예제 #1
0
  @Test
  public void revision_property_should_be_changed() {
    RevisionImpl revision = new RevisionImpl(2);
    Map<String, String> properties = new LinkedHashMap<>();
    properties.put("prop1", "val1");
    properties.put("prop2", "val2");
    properties.put("prop3", "val3");
    revision.setProperties(properties);

    PropertyChange propertyChange = new PropertyChange("prop2"::equals, t -> "d");

    propertyChange.consume(revision);

    Map<String, String> newProperties = revision.getProperties();
    assertThat(newProperties.size(), is(3));
    Iterator<Map.Entry<String, String>> propIter = newProperties.entrySet().iterator();

    Map.Entry<String, String> currentEntry = propIter.next();
    assertThat(currentEntry.getKey(), is(equalTo("prop1")));
    assertThat(currentEntry.getValue(), is(equalTo("val1")));

    currentEntry = propIter.next();
    assertThat(currentEntry.getKey(), is(equalTo("prop2")));
    assertThat(currentEntry.getValue(), is(equalTo("d")));

    currentEntry = propIter.next();
    assertThat(currentEntry.getKey(), is(equalTo("prop3")));
    assertThat(currentEntry.getValue(), is(equalTo("val3")));

    assertFalse(propIter.hasNext());
  }
예제 #2
0
  @Test
  public void node_property_should_be_deleted() {
    NodeImpl node = new NodeImpl();
    Map<String, String> properties = new LinkedHashMap<>();
    properties.put("prop1", "val1");
    properties.put("prop2", "val2");
    properties.put("prop3", "val3");
    node.setProperties(properties);

    PropertyChange propertyChange = new PropertyChange("prop2"::equals, t -> null);

    propertyChange.consume(node);

    Map<String, String> newProperties = node.getProperties();
    assertThat(newProperties.size(), is(2));
    Iterator<Map.Entry<String, String>> propIter = newProperties.entrySet().iterator();

    Map.Entry<String, String> currentEntry = propIter.next();
    assertThat(currentEntry.getKey(), is(equalTo("prop1")));
    assertThat(currentEntry.getValue(), is(equalTo("val1")));

    currentEntry = propIter.next();
    assertThat(currentEntry.getKey(), is(equalTo("prop3")));
    assertThat(currentEntry.getValue(), is(equalTo("val3")));

    assertFalse(propIter.hasNext());
  }
예제 #3
0
파일: AmendmentTest.java 프로젝트: NCIP/psc
  public void testDeepEqualsWhenDeltaAreNotEquals() throws Exception {
    Amendment a1 =
        Fixtures.createAmendment("Amendment", DateTools.createDate(2007, Calendar.APRIL, 6));
    Amendment a2 =
        Fixtures.createAmendment("Amendment", DateTools.createDate(2007, Calendar.APRIL, 6));
    Epoch epoch1 = new Epoch();
    epoch1.setName("Epoch");
    epoch1.setGridId("GridId1");
    Delta<Epoch> delta1 = Delta.createDeltaFor(epoch1);
    delta1.setGridId("delta1");
    delta1.addChanges(PropertyChange.create("name", "A", "C"), Add.create(new StudySegment()));
    a1.addDelta(delta1);
    Epoch epoch2 = new Epoch();
    epoch2.setName("Epoch");
    epoch2.setGridId("GridId1");
    Delta<Epoch> delta2 = Delta.createDeltaFor(epoch2);
    delta2.setGridId("delta1");
    delta2.addChanges(PropertyChange.create("name", "A", "B"), Add.create(new StudySegment()));
    a2.addDelta(delta2);
    Differences differences = a1.deepEquals(a2);
    assertFalse(differences.getChildDifferences().isEmpty());

    assertChildDifferences(
        differences,
        new String[] {"delta for epoch GridId1", "property change for name"},
        "new value \"C\" does not match \"B\"");
  }
예제 #4
0
 /**
  * Update values.
  *
  * @param props the properties
  * @param vals the values
  * @param propchg the property change
  */
 private static void updateValues(String[] props, Object[] vals, PropertyChange propchg) {
   for (int findi = 0; findi < props.length; findi++) {
     if (propchg.getName().lastIndexOf(props[findi]) >= 0) {
       if (propchg.getOp() == PropertyChangeOp.REMOVE) {
         vals[findi] = "";
       } else {
         vals[findi] = propchg.getVal();
       }
     }
   }
 }
예제 #5
0
파일: AmendmentTest.java 프로젝트: NCIP/psc
 public void testDeepEqualsWhenNoOfDeltaAreDifferent() throws Exception {
   Amendment a1 =
       Fixtures.createAmendment("Amendment", DateTools.createDate(2007, Calendar.APRIL, 6));
   Amendment a2 =
       Fixtures.createAmendment("Amendment", DateTools.createDate(2007, Calendar.APRIL, 6));
   a1.addDelta(
       Delta.createDeltaFor(
           new Epoch(), PropertyChange.create("name", "A", "B"), Add.create(new StudySegment())));
   a2.addDelta(
       Delta.createDeltaFor(
           new Epoch(), PropertyChange.create("name", "A", "B"), Add.create(new StudySegment())));
   a2.addDelta(
       Delta.createDeltaFor(
           new Epoch(), PropertyChange.create("name", "A", "B"), Add.create(new StudySegment())));
   Differences differences = a1.deepEquals(a2);
   assertFalse(differences.getMessages().isEmpty());
   assertEquals(
       "Amendment are Equals",
       "number of deltas does not match: 1 != 2",
       differences.getMessages().get(0));
 }
예제 #6
0
파일: AmendmentTest.java 프로젝트: NCIP/psc
  public void testUpdatedDateWhenOneChangeHasAnUpdatedDate() throws Exception {
    a3.addDelta(
        Delta.createDeltaFor(
            new Epoch(), PropertyChange.create("name", "A", "B"), Add.create(new StudySegment())));
    a3.getDeltas()
        .get(0)
        .getChanges()
        .get(0)
        .setUpdatedDate(DateTools.createDate(2005, Calendar.MAY, 3));

    assertDayOfDate(2005, Calendar.MAY, 3, a3.getUpdatedDate());
  }
예제 #7
0
파일: AmendmentTest.java 프로젝트: NCIP/psc
 public void testDeepEqualsWhenNoDeltaFoundInAmendment() throws Exception {
   Amendment a1 =
       Fixtures.createAmendment("Amendment", DateTools.createDate(2007, Calendar.APRIL, 6));
   Amendment a2 =
       Fixtures.createAmendment("Amendment", DateTools.createDate(2007, Calendar.APRIL, 6));
   Epoch epoch1 = new Epoch();
   epoch1.setGridId("epoch1");
   Delta<Epoch> delta1 = Delta.createDeltaFor(epoch1);
   delta1.setGridId("delta1");
   delta1.addChanges(PropertyChange.create("name", "A", "B"), Add.create(new StudySegment()));
   a1.addDelta(delta1);
   StudySegment segment1 = new StudySegment();
   segment1.setGridId("segment1");
   Delta<StudySegment> delta2 = Delta.createDeltaFor(segment1);
   delta2.setGridId("delta1");
   delta2.addChanges(PropertyChange.create("name", "A", "B"), Add.create(new StudySegment()));
   a2.addDelta(delta2);
   Differences differences = a1.deepEquals(a2);
   assertFalse(differences.getMessages().isEmpty());
   assertEquals(
       "Amendments are equals",
       "no delta for epoch epoch1 found",
       differences.getMessages().get(0));
 }
예제 #8
0
파일: AmendmentTest.java 프로젝트: NCIP/psc
 private void ensureUpdatedDate(Amendment expectedAmendment, Date expectedDate) {
   expectedAmendment.getDeltas().clear();
   Delta<?> delta = Delta.createDeltaFor(new Epoch(), PropertyChange.create("name", "A", "B"));
   delta.getChanges().get(0).setUpdatedDate(expectedDate);
   expectedAmendment.addDelta(delta);
 }