Example #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());
  }
Example #2
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());
  }
Example #3
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());
  }
Example #4
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());
  }
Example #5
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));
  }
Example #6
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);
  }
Example #7
0
  public void contentRemoved(int offset, int length, String text, boolean clearDirty) {
    Edit last = getLastEdit();
    Edit toMerge = getMergeEdit();

    if (!clearDirty && toMerge instanceof Remove && redosFirst == null) {
      Remove rem = (Remove) toMerge;
      if (rem.offset == offset) {
        rem.content.str = rem.content.str.concat(text);
        rem.content.hashcode = rem.content.str.hashCode();
        rem.length += length;
        KillRing.getInstance().changed(rem.content);
        return;
      } else if (offset + length == rem.offset) {
        rem.content.str = text.concat(rem.content.str);
        rem.content.hashcode = rem.content.str.hashCode();
        rem.length += length;
        rem.offset = offset;
        KillRing.getInstance().changed(rem.content);
        return;
      }
    }

    Remove rem = new Remove(this, offset, length, text);
    if (clearDirty) {
      redoClearDirty = last;
      undoClearDirty = rem;
    }

    if (compoundEdit != null) compoundEdit.add(rem);
    else {
      reviseUndoId();
      addEdit(rem);
    }

    KillRing.getInstance().add(rem.content);
  }
Example #8
0
  // {{{ contentRemoved() method
  public void contentRemoved(int offset, int length, String text, boolean clearDirty) {
    Edit toMerge = getMergeEdit();

    if (!clearDirty && toMerge instanceof Remove && redosFirst == null) {
      Remove rem = (Remove) toMerge;
      if (rem.offset == offset) {
        String newStr = rem.str.concat(text);
        KillRing.getInstance().changed(rem.str, newStr);
        rem.str = newStr;
        return;
      } else if (offset + length == rem.offset) {
        String newStr = text.concat(rem.str);
        KillRing.getInstance().changed(rem.str, newStr);
        rem.offset = offset;
        rem.str = newStr;
        return;
      }
    }

    // use String.intern() here as new Strings are created in
    // JEditBuffer.remove() via undoMgr.contentRemoved(... getText() ...);
    Remove rem = new Remove(offset, text.intern());

    if (clearDirty) {
      redoClearDirty = getLastEdit();
      undoClearDirty = rem;
    }

    if (compoundEdit != null) compoundEdit.add(this, rem);
    else {
      reviseUndoId();
      addEdit(rem);
    }

    KillRing.getInstance().add(rem.str);
  } // }}}
Example #9
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");
  }
Example #10
0
 public void testSetChildIdKeepsChildIfIdsMatch() throws Exception {
   StudySegment expectedChild = setId(15, new StudySegment());
   remove.setChild(expectedChild);
   remove.setChildId(expectedChild.getId());
   assertSame("New child incorrectly cleared", expectedChild, remove.getChild());
 }
Example #11
0
 public void testSetChildIdClearsChildIfIdsDoNotMatch() throws Exception {
   remove.setChild(setId(3, new StudySegment()));
   remove.setChildId(15);
   assertNull("New child not cleared", remove.getChild());
 }
Example #12
0
 public void testGetChildUsesDirectAttributeIfNoDomainObject() throws Exception {
   remove.setChild(null);
   remove.setChildId(5);
   assertEquals(5, (int) remove.getChildId());
 }
Example #13
0
 public void testGetChildIdPassesThroughFromDomainObject() throws Exception {
   Epoch child = setId(4, new Epoch());
   remove.setChildId(17);
   remove.setChild(child);
   assertEquals(4, (int) remove.getChildId());
 }
Example #14
0
 public void testEqualsWhenRemoveHasDifferentChild() throws Exception {
   Remove remove1 = Remove.create(createNamedInstance("Epoch1", Epoch.class));
   Remove remove2 = Remove.create(createNamedInstance("Segment2", StudySegment.class));
   assertNotEquals("Removes are equals", remove1, remove2);
 }
Example #15
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);
 }
Example #16
0
  public void testMergeWithChildNotInNode() throws Exception {
    remove.setChild(ssc);
    remove.mergeInto(delta, NOW);

    assertEquals("Remove should not have been added", 0, delta.getChanges().size());
  }
Example #17
0
  public void testDeepEqualsWhenRemoveHasDifferentChild() throws Exception {
    Remove remove1 = Remove.create(setGridId("e1", Epoch.create("E1")));
    Remove remove2 = Remove.create(setGridId("e2", Epoch.create("E2")));

    assertDifferences(remove1.deepEquals(remove2), "for different child");
  }