I just started to look into Jackrabbit Oak 1.7.5 and I can't get my changes saved - this test fails on the last assertion:
public class JCRTest {
@Test
public void testCommit() throws CommitFailedException {
final NodeStore ns = new MemoryNodeStore();
final String imagesFolder = "images";
NodeState rootState = ns.getRoot();
//newly created store does not have nodes
assertThat(rootState.getChildNode(imagesFolder).exists(), is(equalTo(false)));
NodeBuilder rootBuilder = rootState.builder();
//adding a node called 'images'
rootBuilder.child(imagesFolder);
//it is still not going to be shown since we are working in our own 'state'
assertThat(rootState.getChildNode(imagesFolder).exists(), is(equalTo(false)));
//merging the changes into root
ns.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
//expecting to see the 'images' folder
assertThat(rootState.getChildNode(imagesFolder).exists(), is(equalTo(true)));
}
}
A NodeState
(rootState in your test) is a snapshot of the repository. After you merge your changes, you need to get head of the repository again (i.e. do rootState = ns.getRoot()
again before asserting).