JcrNode extends AbstractJcrNode { @Override public String getPath() throws RepositoryException { return path().getString(namespaces()); } JcrNode( JcrSession session,
             NodeKey nodeKey ); @Override int getIndex(); @Override String getName(); @Override AbstractJcrNode getParent(); @Override String getPath();  }
@Test public void shouldHavePath() throws Exception { assertThat(altima.getPath(), is("/Cars/Hybrid/Nissan Altima")); javax.jcr.Node altima2 = hybrid.addNode("Nissan Altima"); try { assertThat(altima2, is(notNullValue())); assertThat(altima2.getPath(), is("/Cars/Hybrid/Nissan Altima[2]")); } finally { altima2.remove(); } }
@Test @FixFor("MODE-2096") public void shouldReorderTransientChildren() throws Exception { Node parent = session.getRootNode().addNode("parent", "nt:unstructured"); try { parent.addNode("child1"); parent.addNode("child2"); parent.addNode("child3"); parent.addNode("child4"); parent.orderBefore("child4", "child3"); parent.orderBefore("child3", "child2"); parent.orderBefore("child2", "child1"); session.save(); List<String> paths = new ArrayList<String>(); NodeIterator nodeIterator = parent.getNodes(); while (nodeIterator.hasNext()) { paths.add(nodeIterator.nextNode().getPath()); } assertEquals(Arrays.asList("/parent/child4", "/parent/child3", "/parent/child2", "/parent/child1"), paths); } finally { parent.remove(); session.save(); } }
@Test @FixFor("MODE-2096") public void shouldReorderTransientChildrenAtEnd() throws Exception { Node parent = session.getRootNode().addNode("parent", "nt:unstructured"); try { parent.addNode("child1"); parent.addNode("child2"); parent.addNode("child3"); parent.addNode("child4"); parent.addNode("child5"); parent.addNode("child6"); parent.orderBefore("child5", "child4"); parent.orderBefore("child6", "child4"); parent.orderBefore("child3", "child2"); parent.orderBefore("child1", null); parent.orderBefore("child2", null); session.save(); List<String> paths = new ArrayList<String>(); NodeIterator nodeIterator = parent.getNodes(); while (nodeIterator.hasNext()) { paths.add(nodeIterator.nextNode().getPath()); } assertEquals(6, paths.size()); int child5Idx = paths.indexOf("/parent/child5"); int child6Idx = paths.indexOf("/parent/child6"); int child4Idx = paths.indexOf("/parent/child4"); int child3Idx = paths.indexOf("/parent/child3"); int child2Idx = paths.indexOf("/parent/child2"); assertTrue("/parent/child5 not moved before /parent/child4", child5Idx < child4Idx); assertTrue("/parent/child6 not moved before /parent/child4", child6Idx < child4Idx); assertTrue("/parent/child3 not moved before /parent/child2", child3Idx < child2Idx); assertEquals(Arrays.asList("/parent/child1", "/parent/child2"), paths.subList(4, 6)); } finally { parent.remove(); session.save(); } }
@Test @FixFor( "MODE-2463" ) public void transientRemovalAndAdditionOfTheSameNodeShouldNotCorruptPaths() throws Exception { session.logout(); String name = "testNode"; JcrSession session1 = repository().login(); Node rootNode = session1.getRootNode(); Node testNode = rootNode.addNode(name); assertNotNull(testNode); String testNodePath = testNode.getPath(); session1.save(); session1.logout(); JcrSession session2 = repository().login(); rootNode = session2.getRootNode(); assertNotNull(rootNode); testNode = session2.getNode(testNodePath); testNode.remove(); assertFalse(rootNode.hasNode(name)); try { session2.getNode(testNodePath); fail("This should throw a PathNotFoundException since testNode has been removed"); } catch (PathNotFoundException ex) { } Node newTestNode = rootNode.addNode(name); assertEquals(testNodePath, newTestNode.getPath()); Node node = session2.getNode(testNodePath); assertEquals("Node path should equal " + testNodePath, testNodePath, node.getPath()); try { session2.getNode(testNodePath + "[2]"); fail("There shouldn't be any SNS node"); } catch (PathNotFoundException ex) { } session2.save(); session2.logout(); JcrSession session3 = repository().login(); node = session3.getNode("/" + testNodePath); assertNotNull(node); try { session3.getNode(testNodePath + "[2]"); fail("There shouldn't be any SNS node"); } catch (PathNotFoundException ex) { } }