Exemple #1
0
  public void testMergeWithNoOtherChanges() throws Exception {
    remove.setChild(ssa);
    remove.mergeInto(delta, NOW);

    assertEquals("Remove should have been added", 1, delta.getChanges().size());
    assertSame(remove, delta.getChanges().get(0));
    assertEquals("Updated date not set", NOW, remove.getUpdatedDate());
  }
Exemple #2
0
 public void testAddPeriod() {
   Period period = new Period();
   studySegment.addPeriod(period);
   assertEquals("wrong number of periods", 1, studySegment.getPeriods().size());
   assertSame("wrong period present", period, studySegment.getPeriods().iterator().next());
   assertEquals(
       "bidirectional relationship not maintained", studySegment, period.getStudySegment());
 }
Exemple #3
0
  public void testMergeWithEquivalentRemovePresent() throws Exception {
    Remove expectedRemove = Remove.create(ssb);
    delta.addChange(expectedRemove);

    remove.setChild(ssb);
    remove.mergeInto(delta, NOW);

    assertEquals("Duplicate remove should not have been added", 1, delta.getChanges().size());
    assertEquals(expectedRemove, delta.getChanges().get(0));
  }
Exemple #4
0
  public void testLengthNegativeAndPositiveWithGap() throws Exception {
    studySegment.addPeriod(createPeriod("dc", -28, 14, 1));
    studySegment.addPeriod(createPeriod("dc", 10, 8, 2));

    assertDayRange(-28, 25, studySegment.getDayRange());
    assertEquals(54, studySegment.getLengthInDays());
  }
Exemple #5
0
  public void testLengthNegative() throws Exception {
    Period single = createPeriod("", -28, 15, 1);
    studySegment.addPeriod(single);

    assertDayRange(-28, -14, studySegment.getDayRange());
    assertEquals(15, studySegment.getLengthInDays());
  }
Exemple #6
0
  public void testLengthSimple() throws Exception {
    Period single = createPeriod("", 3, Duration.Unit.day, 15, 3);
    studySegment.addPeriod(single);

    assertDayRange(3, 47, studySegment.getDayRange());
    assertEquals(45, studySegment.getLengthInDays());
  }
Exemple #7
0
  public void testMergeWithReorderAloneDoesNotCancelReorder() throws Exception {
    delta.addChange(Reorder.create(ssa, 0, 1));

    remove.setChild(ssa);
    remove.mergeInto(delta, NOW);

    assertEquals("Remove should not have canceled anything", 2, delta.getChanges().size());
  }
Exemple #8
0
  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());
  }
Exemple #9
0
  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());
  }
Exemple #10
0
  public void testLengthWhenOverlapping() throws Exception {
    Period zero = createPeriod("", 1, Duration.Unit.day, 30, 1);
    Period one = createPeriod("", 17, Duration.Unit.day, 15, 1);
    studySegment.addPeriod(zero);
    studySegment.addPeriod(one);

    assertDayRange(1, 31, studySegment.getDayRange());
    assertEquals(31, studySegment.getLengthInDays());
  }
Exemple #11
0
  public void testAddMultiplePeriod() {
    studySegment = new StudySegment();
    Period period = createPeriod("name", 3, Duration.Unit.day, 15, 3);
    Period anotherPeriod = createPeriod("name", 3, Duration.Unit.day, 15, 3);
    studySegment.addPeriod(period);
    studySegment.addPeriod(anotherPeriod);

    assertEquals(
        "wrong number of periods because both periods are same",
        1,
        studySegment.getPeriods().size());

    studySegment = new StudySegment();

    period.setId(1);
    studySegment.addPeriod(period);
    studySegment.addPeriod(anotherPeriod);

    assertEquals("wrong number of periods", 2, studySegment.getPeriods().size());
  }
Exemple #12
0
  public void testEqualsWhenSameNameAndProxied() throws Exception {
    StudySegment s1 = createNamedInstance("Segment", StudySegment.class);

    ProxyFactory factory = new ProxyFactory();
    factory.setSuperclass(StudySegment.class);
    factory.setHandler(
        new MethodHandler() {
          public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args)
              throws Throwable {
            StudySegment target = createNamedInstance("Segment", StudySegment.class);
            return thisMethod.invoke(target, args);
          }
        });
    StudySegment proxy = (StudySegment) factory.createClass().newInstance();

    assertEquals("StudySegments are not equals", s1, proxy);
  }
Exemple #13
0
  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);
  }
Exemple #14
0
 public void testEqualsWhenRemoveHasSameChild() throws Exception {
   Remove remove1 = Remove.create(createNamedInstance("Segment1", StudySegment.class));
   Remove remove2 = Remove.create(createNamedInstance("Segment1", StudySegment.class));
   assertEquals("Removes are not equals", remove1, remove2);
 }
Exemple #15
0
 public void testDefaultName() throws Exception {
   assertEquals("[Unnamed study segment]", new StudySegment().getName());
 }
Exemple #16
0
 public void testGetChildIdPassesThroughFromDomainObject() throws Exception {
   Epoch child = setId(4, new Epoch());
   remove.setChildId(17);
   remove.setChild(child);
   assertEquals(4, (int) remove.getChildId());
 }
Exemple #17
0
 public void testGetChildUsesDirectAttributeIfNoDomainObject() throws Exception {
   remove.setChild(null);
   remove.setChildId(5);
   assertEquals(5, (int) remove.getChildId());
 }
Exemple #18
0
 public void testQualifiedNameZeroStudySegmentEpoch() throws Exception {
   assertEquals("Epoch", Epoch.create("Epoch").getStudySegments().get(0).getQualifiedName());
 }
Exemple #19
0
 public void testQualifiedName() throws Exception {
   Epoch epoch = Epoch.create("Epoch", "A", "B");
   assertEquals("Epoch: A", epoch.getStudySegments().get(0).getQualifiedName());
   assertEquals("Epoch: B", epoch.getStudySegments().get(1).getQualifiedName());
 }
Exemple #20
0
 public void testDayRangeWithNoPeriods() throws Exception {
   assertEquals(0, new StudySegment().getDayRange().getDayCount());
 }
Exemple #21
0
  public void testMergeWithChildNotInNode() throws Exception {
    remove.setChild(ssc);
    remove.mergeInto(delta, NOW);

    assertEquals("Remove should not have been added", 0, delta.getChanges().size());
  }
Exemple #22
0
 public void testEqualsWhenSameName() throws Exception {
   StudySegment s1 = createNamedInstance("Segment", StudySegment.class);
   StudySegment s2 = createNamedInstance("Segment", StudySegment.class);
   assertEquals("StudySegments are not equals", s1, s2);
 }