assertEquals(test, store.getRoot().getChildNode("test"));
}
@Test
public void manyChildNodes() throws CommitFailedException {
NodeStoreBranch branch = store.branch();
NodeBuilder root = branch.getHead().builder();
NodeBuilder parent = root.child("parent");
for (int i = 0; i <= KernelNodeState.MAX_CHILD_NODE_NAMES; i++) {
parent.child("child-" + i);
}
branch.setRoot(root.getNodeState());
branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
NodeState base = store.getRoot();
branch = store.branch();
root = branch.getHead().builder();
parent = root.child("parent");
parent.child("child-new");
branch.setRoot(root.getNodeState());
branch.merge(EmptyHook.INSTANCE, PostCommitHook.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();
branch = store.branch();
branch.move("/parent/child-new", "/parent/child-moved");
branch.merge(EmptyHook.INSTANCE, PostCommitHook.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();
branch = store.branch();
root = branch.getHead().builder();
parent = root.child("parent");
parent.child("child-moved").setProperty("foo", "value");
parent.child("child-moved").setProperty(
new MultiStringPropertyState("bar", Arrays.asList("value")));
branch.setRoot(root.getNodeState());
branch.merge(EmptyHook.INSTANCE, PostCommitHook.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();
branch = store.branch();
root = branch.getHead().builder();
parent = root.child("parent");
parent.setProperty("foo", "value");
parent.setProperty(new MultiStringPropertyState(
"bar", Arrays.asList("value")));
branch.setRoot(root.getNodeState());
branch.merge(EmptyHook.INSTANCE, PostCommitHook.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();
branch = store.branch();
root = branch.getHead().builder();
parent = root.child("parent");
parent.getChildNode("child-moved").remove();
branch.setRoot(root.getNodeState());
branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
diff = new Diff();
store.getRoot().compareAgainstBaseState(base, diff);
assertEquals(1, diff.removed.size());