Search in sources :

Example 1 with MultiStringPropertyState

use of org.apache.jackrabbit.oak.plugins.memory.MultiStringPropertyState in project jackrabbit-oak by apache.

the class NodeStoreTest method manyChildNodes.

@Test
public void manyChildNodes() throws CommitFailedException {
    NodeBuilder root = store.getRoot().builder();
    NodeBuilder parent = root.child("parent");
    for (int i = 0; i <= 100; i++) {
        parent.child("child-" + i);
    }
    store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    NodeState base = store.getRoot();
    root = base.builder();
    parent = root.child("parent");
    parent.child("child-new");
    store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    Diff diff = new Diff();
    store.getRoot().compareAgainstBaseState(base, diff);
    assertEquals(0, diff.removed.size());
    assertEquals(1, diff.added.size());
    assertEquals("child-new", diff.added.get(0));
    base = store.getRoot();
    root = base.builder();
    parent = root.getChildNode("parent");
    parent.getChildNode("child-new").moveTo(parent, "child-moved");
    store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    diff = new Diff();
    store.getRoot().compareAgainstBaseState(base, diff);
    assertEquals(1, diff.removed.size());
    assertEquals("child-new", diff.removed.get(0));
    assertEquals(1, diff.added.size());
    assertEquals("child-moved", diff.added.get(0));
    base = store.getRoot();
    root = base.builder();
    parent = root.child("parent");
    parent.child("child-moved").setProperty("foo", "value");
    parent.child("child-moved").setProperty(new MultiStringPropertyState("bar", Arrays.asList("value")));
    store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    diff = new Diff();
    store.getRoot().compareAgainstBaseState(base, diff);
    assertEquals(0, diff.removed.size());
    assertEquals(0, diff.added.size());
    assertEquals(2, diff.addedProperties.size());
    assertTrue(diff.addedProperties.contains("foo"));
    assertTrue(diff.addedProperties.contains("bar"));
    base = store.getRoot();
    root = base.builder();
    parent = root.child("parent");
    parent.setProperty("foo", "value");
    parent.setProperty(new MultiStringPropertyState("bar", Arrays.asList("value")));
    store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    diff = new Diff();
    store.getRoot().compareAgainstBaseState(base, diff);
    assertEquals(0, diff.removed.size());
    assertEquals(0, diff.added.size());
    assertEquals(2, diff.addedProperties.size());
    assertTrue(diff.addedProperties.contains("foo"));
    assertTrue(diff.addedProperties.contains("bar"));
    base = store.getRoot();
    root = base.builder();
    parent = root.child("parent");
    parent.getChildNode("child-moved").remove();
    store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    diff = new Diff();
    store.getRoot().compareAgainstBaseState(base, diff);
    assertEquals(1, diff.removed.size());
    assertEquals(0, diff.added.size());
    assertEquals("child-moved", diff.removed.get(0));
}
Also used : MultiStringPropertyState(org.apache.jackrabbit.oak.plugins.memory.MultiStringPropertyState) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Aggregations

OakBaseTest (org.apache.jackrabbit.oak.OakBaseTest)1 MultiStringPropertyState (org.apache.jackrabbit.oak.plugins.memory.MultiStringPropertyState)1 Test (org.junit.Test)1