示例#1
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\"");
  }
示例#2
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");
 }
示例#3
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());
 }
示例#4
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);
 }
示例#5
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    a3 = createAmendments("A0", "A1", "A2", "A3");
    a2 = a3.getPreviousAmendment();
    a1 = a2.getPreviousAmendment();
    a0 = a1.getPreviousAmendment();

    b2 = createAmendments("B0", "B1", "B2");
    FormatTools.setLocal(new FormatTools("MM/dd/yyyy"));
  }
示例#6
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());
  }
示例#7
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));
  }
示例#8
0
 public void testGetNextDate() throws Exception {
   Amendment.Key actual = Amendment.decomposeNaturalKey("2003-08-11~fred");
   assertDayOfDate(2003, Calendar.AUGUST, 11, actual.getDate());
   Date nextDay = actual.getDateNext();
   Calendar c1 = Calendar.getInstance();
   c1.setTime(nextDay);
   int day = c1.get(Calendar.DATE);
   System.out.println("day " + day);
   assertEquals("Day is not incremented", 12, day);
   assertEquals("Wrong name", "fred", actual.getName());
 }
示例#9
0
  public void testIsPreviousAmendment() throws Exception {
    assertFalse(a3.hasPreviousAmendment(a3));
    assertTrue(a3.hasPreviousAmendment(a2));
    assertTrue(a3.hasPreviousAmendment(a1));
    assertTrue(a3.hasPreviousAmendment(a0));

    assertFalse(a2.hasPreviousAmendment(a3));
    assertFalse(a2.hasPreviousAmendment(a2));
    assertTrue(a2.hasPreviousAmendment(a1));
    assertTrue(a2.hasPreviousAmendment(a0));

    assertFalse(a1.hasPreviousAmendment(a3));
    assertFalse(a1.hasPreviousAmendment(a2));
    assertFalse(a1.hasPreviousAmendment(a1));
    assertTrue(a1.hasPreviousAmendment(a0));

    assertFalse(a2.hasPreviousAmendment(b2));
  }
示例#10
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());
  }
示例#11
0
  public void testGetNextDateAtTheEndOfMonth() throws Exception {
    Calendar c = Calendar.getInstance();
    Amendment.Key actual = Amendment.decomposeNaturalKey("2003-08-31~fred");
    assertDayOfDate(2003, Calendar.AUGUST, 31, actual.getDate());
    c.setTime(actual.getDate());

    Date nextDay = actual.getDateNext();
    Calendar c1 = Calendar.getInstance();
    c1.setTime(nextDay);
    assertEquals("Day is not incremented", 1, c1.get(Calendar.DATE));
    assertEquals("Month is not incremented", c.get(Calendar.MONTH) + 1, c1.get(Calendar.MONTH));
    assertEquals("Wrong name", "fred", actual.getName());
  }
示例#12
0
 public void testIsInitialTemplate() throws Exception {
   a0.setName(null);
   assertFalse(a0.isInitialTemplate());
   a0.setName("3");
   assertFalse(a0.isInitialTemplate());
   a0.setName(Amendment.INITIAL_TEMPLATE_AMENDMENT_NAME);
   assertTrue(a0.isInitialTemplate());
 }
示例#13
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");
  }
示例#14
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));
 }
示例#15
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));
 }
示例#16
0
 public void testDisplayNameWithDateAndName() throws Exception {
   a3.setDate(DateTools.createDate(2005, Calendar.MARCH, 6));
   assertEquals("03/06/2005 (A3)", a3.getDisplayName());
 }
示例#17
0
 public void testCount() throws Exception {
   assertEquals(3, a3.getPreviousAmendmentsCount());
   assertEquals(2, a2.getPreviousAmendmentsCount());
   assertEquals(1, a1.getPreviousAmendmentsCount());
   assertEquals(0, a0.getPreviousAmendmentsCount());
 }
示例#18
0
 public void testNaturalKeyWithBlankName() throws Exception {
   a0.setDate(DateTools.createDate(2022, Calendar.MARCH, 6));
   a0.setName(" ");
   assertEquals("2022-03-06", a0.getNaturalKey());
 }
示例#19
0
 public void testDecomposeNaturalKeyWithName() throws Exception {
   Amendment.Key actual = Amendment.decomposeNaturalKey("2003-08-11~fred");
   assertDayOfDate(2003, Calendar.AUGUST, 11, actual.getDate());
   assertEquals("Wrong name", "fred", actual.getName());
 }
示例#20
0
  public void testLastModifiedDatePrefersReleasedDateIfNoDeltas() throws Exception {
    a3.setReleasedDate(DateTools.createDate(2007, Calendar.OCTOBER, 20));
    a3.getDeltas().clear();

    assertDayOfDate(2007, Calendar.OCTOBER, 20, a3.getLastModifiedDate());
  }
示例#21
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\"");
 }
示例#22
0
 public void testDecomposeNaturalKeyWithoutName() throws Exception {
   Amendment.Key actual = Amendment.decomposeNaturalKey("2001-01-12");
   assertDayOfDate(2001, Calendar.JANUARY, 12, actual.getDate());
   assertNull("Wrong name", actual.getName());
 }
示例#23
0
 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);
 }
示例#24
0
  public void testLastModifiedDateIsNullIfAllDatesAreNull() throws Exception {
    a3.setReleasedDate(null);
    ensureUpdatedDate(a3, null);

    assertNull(a3.getLastModifiedDate());
  }
示例#25
0
 public void testSetMemOnlyRecursiveToPreviousAmendments() throws Exception {
   Amendment amendment = Fixtures.createAmendments("C", "B", "A");
   amendment.setMemoryOnly(true);
   assertTrue(amendment.getPreviousAmendment().isMemoryOnly());
 }
示例#26
0
 public void testNaturalKeyWithoutName() throws Exception {
   a0.setDate(DateTools.createDate(2009, Calendar.NOVEMBER, 6));
   a0.setName(null);
   assertEquals("2009-11-06", a0.getNaturalKey());
 }
示例#27
0
  public void testLastModifiedDatePrefersUpdatedDateIfReleasedDateNull() throws Exception {
    a3.setReleasedDate(null);
    ensureUpdatedDate(a3, DateTools.createDate(2007, Calendar.OCTOBER, 20));

    assertDayOfDate(2007, Calendar.OCTOBER, 20, a3.getLastModifiedDate());
  }
示例#28
0
 public void testDisplayNameForOriginalAmendment() throws Exception {
   a0.setName(Amendment.INITIAL_TEMPLATE_AMENDMENT_NAME);
   assertEquals("Initial template", a0.getDisplayName());
 }
示例#29
0
 public void testNaturalKeyWithName() throws Exception {
   a0.setDate(DateTools.createDate(2005, Calendar.MAY, 4));
   a0.setName("4");
   assertEquals("2005-05-04~4", a0.getNaturalKey());
 }
示例#30
0
  public void testLastModifiedDatePrefersReleasedDateIfNoChanges() throws Exception {
    a3.setReleasedDate(DateTools.createDate(2007, Calendar.OCTOBER, 20));
    a3.addDelta(new EpochDelta());

    assertDayOfDate(2007, Calendar.OCTOBER, 20, a3.getLastModifiedDate());
  }