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\""); }
public void testMergeWithEquivalentAddPresent() throws Exception { delta.addChange(Add.create(ssc, 2)); remove.setChild(ssc); remove.mergeInto(delta, NOW); assertEquals("Remove should have canceled add", 0, delta.getChanges().size()); }
public void testMergeWithAddFollowedByReorderCancelsBoth() throws Exception { delta.addChange(Add.create(ssc, 2)); Reorder.create(ssc, 2, 1).mergeInto(delta, NOW); remove.setChild(ssc); remove.mergeInto(delta, NOW); assertEquals("Remove should have canceled add and reorder", 0, delta.getChanges().size()); }
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)); }
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()); }
public void testMergeTwoIntoDeltaWithIndexesThenRemoveOne() throws Exception { StudySegment retained0 = setId(17, new StudySegment()); StudySegment retained1 = setId(18, new StudySegment()); StudySegment retained2 = setId(19, new StudySegment()); delta.addChange(Add.create(retained0, 2)); delta.addChange(Add.create(ssc, 3)); delta.addChange(Add.create(retained1, 4)); delta.addChange(Add.create(retained2, 5)); remove.setChild(ssc); remove.mergeInto(delta, NOW); assertEquals("Wrong number of changes in delta", 3, delta.getChanges().size()); Add add0 = (Add) delta.getChanges().get(0); Add add1 = (Add) delta.getChanges().get(1); Add add2 = (Add) delta.getChanges().get(2); assertAdd("Index for earlier retained add updated", retained0, 2, add0); assertChangeTime("Unchanged add time incorrectly updated", null, add0); assertAdd("Index for later retained add not updated", retained1, 3, add1); assertChangeTime("Updated add time not updated", NOW, add1); assertAdd("Index for later retained add not updated", retained2, 4, add2); assertChangeTime("Updated add time not updated", NOW, add2); }
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)); }
public void testDeepEqualsWithMismatchedChanges() throws Exception { Amendment a = new Amendment(); a.getDeltas() .add( setGridId( "D1", Delta.createDeltaFor( setGridId("PC1", new PlannedCalendar()), Add.create(setGridId("E1", new Epoch()))))); Amendment b = new Amendment(); b.getDeltas() .add( setGridId( "D1", Delta.createDeltaFor( setGridId("PC1", new PlannedCalendar()), Remove.create(setGridId("E1", new Epoch()))))); assertChildDifferences( a.deepEquals(b), new String[] {"delta for planned calendar PC1"}, "add of epoch:E1 replaced by remove of epoch:E1"); }