Beispiel #1
0
  @Test
  public void changeTracking() {
    Anchor a = new Anchor();
    a.setId("123");
    a.setOffset(456.789);
    a.put("foo", "bar");
    assertEquals(new Double(456.789), a.getOffset());
    assertEquals("Offset and original are the same", a.getOriginalOffset(), a.getOffset());
    assertEquals(Change.Operation.NoChange, a.getChange());

    a.put("foo", "foo");
    assertEquals("Only offset affects change:", Change.Operation.NoChange, a.getChange());

    a.setOffset(123.456);
    assertEquals(new Double(123.456), a.getOffset());
    assertEquals(
        "Original offset remembers first offset:", new Double(456.789), a.get("originalOffset"));
    assertEquals(
        "Original offset remembers first offset:", new Double(456.789), a.getOriginalOffset());
    assertEquals(Change.Operation.Update, a.getChange());

    a.setOffset(456.123);
    assertEquals(new Double(456.123), a.getOffset());
    assertEquals("Original offset only set once:", new Double(456.789), a.getOriginalOffset());
    assertEquals(Change.Operation.Update, a.getChange());

    a.rollback();
    assertEquals(new Double(456.789), a.getOffset());
    assertEquals("Offset and original are the same", a.getOriginalOffset(), a.getOffset());
    assertEquals(Change.Operation.NoChange, a.getChange());

    a.destroy();
    assertEquals(Change.Operation.Destroy, a.getChange());
    a.rollback();
    assertEquals(Change.Operation.NoChange, a.getChange());

    a.create();
    assertEquals(Change.Operation.Create, a.getChange());
    a.rollback();
    assertEquals("Create cannot be rolled back:", Change.Operation.Create, a.getChange());
  }
Beispiel #2
0
  @Test
  public void copyConstructor() {
    Anchor a = new Anchor("123", 456.789);
    // change offset to generate tracked original
    a.setOffset(123.456);
    // set copiable attribute
    a.put("copy", Boolean.TRUE);
    // set transient attribute
    a.put("@dontCopy", Boolean.TRUE);

    Anchor newA = new Anchor(a);
    assertNull("id not copied", newA.getId());
    assertEquals("offset copied", new Double(123.456), newA.getOffset());
    assertNull("originalOffset not copied", newA.get("originalOffset"));
    assertEquals("originalOffset not copied", new Double(123.456), newA.getOriginalOffset());
    assertEquals("other attribute copied", Boolean.TRUE, newA.get("copy"));
    assertNull("transient attribute not copied", newA.get("@dontCopy"));
  }