Example #1
0
 public void testEqualsWhenAmendmentDateAreNotEquals() throws Exception {
   Amendment a1 =
       Fixtures.createAmendment("Amendment", DateTools.createDate(2007, Calendar.APRIL, 6));
   Amendment a2 =
       Fixtures.createAmendment("Amendment", DateTools.createDate(2008, Calendar.APRIL, 6));
   assertNotEquals("Amendments are not equals", a1, a2);
 }
Example #2
0
  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\"");
  }
Example #3
0
 public void testDeepEqualsWhenDatesAreNotEqual() throws Exception {
   Amendment a1 =
       Fixtures.createAmendment("Amendment", DateTools.createDate(2007, Calendar.APRIL, 6));
   Amendment a2 =
       Fixtures.createAmendment("Amendment", DateTools.createDate(2008, Calendar.APRIL, 6));
   assertDifferences(a1.deepEquals(a2), "amendment date 04/06/2007 does not match 04/06/2008");
 }
Example #4
0
 public void testSetMemOnlyRecursiveToDeltas() throws Exception {
   Amendment amendment =
       Fixtures.createAmendment(null, DateTools.createDate(2008, Calendar.JUNE, 22));
   amendment.addDelta(Delta.createDeltaFor(new Study()));
   amendment.setMemoryOnly(true);
   assertTrue(amendment.getDeltas().get(0).isMemoryOnly());
 }
Example #5
0
  public void testCloneDeepClonesDeltas() throws Exception {
    Amendment src = Fixtures.createAmendment(null, DateTools.createDate(2008, Calendar.JUNE, 22));
    src.addDelta(Delta.createDeltaFor(new Study()));

    Amendment clone = src.clone();
    assertEquals("Wrong number of cloned changes", 1, clone.getDeltas().size());
    assertNotSame("Deltas not deep cloned", src.getDeltas().get(0), clone.getDeltas().get(0));
  }
Example #6
0
 public void testFindMatchingDelta() throws Exception {
   Amendment a1 =
       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");
   a1.addDelta(delta1);
   Delta actualDelta = a1.getMatchingDelta("delta1", "epoch1", delta1.getClass());
   assertNotNull("Delta not found", actualDelta);
 }
Example #7
0
  public void testCloneDeepClonesPreviousAmendments() throws Exception {
    Amendment src = Fixtures.createAmendments("C", "B", "A");
    Amendment clone = src.clone();

    assertNotSame(
        "Previous amendment not cloned", src.getPreviousAmendment(), clone.getPreviousAmendment());
    assertNotSame(
        "Previous previous amendment not cloned",
        src.getPreviousAmendment().getPreviousAmendment(),
        clone.getPreviousAmendment().getPreviousAmendment());
  }
Example #8
0
 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));
 }
Example #9
0
 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));
 }
Example #10
0
  public void testRemoveDetachedNodesWhileIterating() {
    Study s = Fixtures.createReleasedTemplate();
    Delta pc = Delta.createDeltaFor(s.getPlannedCalendar());
    Delta epoch2 = Delta.createDeltaFor(s.getPlannedCalendar().getEpochs().get(0));
    StudySegment segment1 = s.getPlannedCalendar().getEpochs().get(0).getStudySegments().get(1);
    Delta ss1 = Delta.createDeltaFor(segment1);
    Delta ss2 =
        Delta.createDeltaFor(s.getPlannedCalendar().getEpochs().get(0).getStudySegments().get(2));
    List<Delta<?>> deltaList = new ArrayList<Delta<?>>();
    deltaList.add(ss1);
    deltaList.add(epoch2);
    deltaList.add(pc);
    deltaList.add(ss2);

    expect(templateService.findEquivalentChild(s, pc.getNode())).andReturn(pc.getNode());
    expect(templateService.findEquivalentChild(s, epoch2.getNode())).andReturn(epoch2.getNode());
    expect(templateService.findEquivalentChild(s, ss1.getNode())).andReturn(ss1.getNode());
    expect(templateService.findEquivalentChild(s, ss2.getNode())).andReturn(ss2.getNode());

    replayMocks();
    DeltaIterator di = new DeltaIterator(deltaList, s, templateService, false);
    List<Delta> encountered = new LinkedList<Delta>();
    while (di.hasNext()) {
      Delta delta = di.next();
      encountered.add(delta);

      if (delta == epoch2) {
        segment1.setParent(null);
      }
    }

    assertEquals("Wrong number of deltas encountered: " + encountered, 3, encountered.size());
    assertEquals("Wrong delta 0", pc, encountered.get(0));
    assertEquals("Wrong delta 1", epoch2, encountered.get(1));
    assertEquals("Wrong delta 2", ss2, encountered.get(2));
    verifyMocks();
  }
Example #11
0
 public void testDeepEqualsWhenNamesAreNotEqual() throws Exception {
   Amendment a1 = Fixtures.createAmendment("A", DateTools.createDate(2007, Calendar.APRIL, 6));
   Amendment a2 = Fixtures.createAmendment("B", DateTools.createDate(2007, Calendar.APRIL, 6));
   assertDifferences(a1.deepEquals(a2), "amendment name \"A\" does not match \"B\"");
 }
Example #12
0
 public void testSetMemOnlyRecursiveToPreviousAmendments() throws Exception {
   Amendment amendment = Fixtures.createAmendments("C", "B", "A");
   amendment.setMemoryOnly(true);
   assertTrue(amendment.getPreviousAmendment().isMemoryOnly());
 }
Example #13
0
  public void testDetailOrder() {
    Study s = Fixtures.createReleasedTemplate();
    Period period = Fixtures.createPeriod("period1", 1, 10, 2);
    PlannedActivity plannedActivity = Fixtures.createPlannedActivity("activity", 3);
    PlannedActivityLabel plannedActivityLabel = Fixtures.createPlannedActivityLabel("label");
    period.addPlannedActivity(plannedActivity);
    plannedActivity.addPlannedActivityLabel(plannedActivityLabel);
    s.getPlannedCalendar().getEpochs().get(0).getStudySegments().get(0).getPeriods().add(period);

    Delta studyDelta = Delta.createDeltaFor(s.getPlannedCalendar().getStudy());
    Delta epochDelta = Delta.createDeltaFor(s.getPlannedCalendar().getEpochs().get(0));
    Delta studySegmentDelta =
        Delta.createDeltaFor(s.getPlannedCalendar().getEpochs().get(0).getStudySegments().get(1));
    Delta periodDelta =
        Delta.createDeltaFor(
            s.getPlannedCalendar()
                .getEpochs()
                .get(0)
                .getStudySegments()
                .get(0)
                .getPeriods()
                .last());
    Delta plannedActivityDelta =
        Delta.createDeltaFor(
            s.getPlannedCalendar()
                .getEpochs()
                .get(0)
                .getStudySegments()
                .get(0)
                .getPeriods()
                .first()
                .getPlannedActivities()
                .get(0));
    Delta plannedActivityLabelDelta =
        Delta.createDeltaFor(
            s.getPlannedCalendar()
                .getEpochs()
                .get(0)
                .getStudySegments()
                .get(0)
                .getPeriods()
                .first()
                .getPlannedActivities()
                .get(0)
                .getPlannedActivityLabels()
                .first());

    List<Delta<?>> listOfDeltas = new ArrayList<Delta<?>>();
    listOfDeltas.add(plannedActivityDelta);
    listOfDeltas.add(periodDelta);
    listOfDeltas.add(epochDelta);
    listOfDeltas.add(studyDelta);
    listOfDeltas.add(studySegmentDelta);
    listOfDeltas.add(plannedActivityLabelDelta);

    expect(templateService.findEquivalentChild(s, studyDelta.getNode())).andReturn(s);
    expect(templateService.findEquivalentChild(s, periodDelta.getNode())).andReturn(null);
    expect(templateService.findEquivalentChild(s, epochDelta.getNode()))
        .andReturn(epochDelta.getNode());
    expect(templateService.findEquivalentChild(s, studySegmentDelta.getNode()))
        .andReturn(studySegmentDelta.getNode());
    expect(templateService.findEquivalentChild(s, plannedActivityDelta.getNode())).andReturn(null);
    expect(templateService.findEquivalentChild(s, plannedActivityLabelDelta.getNode()))
        .andReturn(plannedActivityLabelDelta.getNode());
    replayMocks();
    DeltaIterator di = new DeltaIterator(listOfDeltas, s, templateService, false);

    assertSame("studyDelta is not the first element", studyDelta, di.next());
    assertSame("epochDelta is not the second element", epochDelta, di.next());
    assertSame("studySegmentDelta is not the third element", studySegmentDelta, di.next());
    assertSame("periodDelta is not the forth element", plannedActivityLabelDelta, di.next());
    assertFalse("deltaIterator has more elements ", di.hasNext());
    verifyMocks();
  }