JcrNode extends AbstractJcrNode { @Override public String getName() throws RepositoryException { return segment().getName().getString(namespaces()); } JcrNode( JcrSession session,
             NodeKey nodeKey ); @Override int getIndex(); @Override String getName(); @Override AbstractJcrNode getParent(); @Override String getPath();  }
@Test public void shouldRetrieveReferenceProperties() throws Exception { Node referenceableNode = session.getRootNode().addNode("referenceable"); referenceableNode.addMixin(JcrMixLexicon.REFERENCEABLE.toString()); Node node1 = session.getRootNode().addNode("node1"); Property prop1 = node1.setProperty("prop1", session.getValueFactory().createValue(referenceableNode, false)); Property prop2 = node1.setProperty("prop2", session.getValueFactory().createValue(referenceableNode, true)); Node node2 = session.getRootNode().addNode("node2"); Property prop3 = node2.setProperty("prop3", session.getValueFactory().createValue(referenceableNode, false)); Property prop4 = node2.setProperty("prop4", session.getValueFactory().createValue(referenceableNode, true)); session.save(); try { PropertyIterator propertyIterator = referenceableNode.getReferences(); assertEquals(2, propertyIterator.getSize()); Set<String> propertyNames = new HashSet<String>(2); while (propertyIterator.hasNext()) { propertyNames.add(propertyIterator.nextProperty().getName()); } assertTrue(propertyNames.contains(prop1.getName()) && propertyNames.contains(prop3.getName())); propertyIterator = referenceableNode.getReferences("prop1"); assertEquals(1, propertyIterator.getSize()); assertEquals(prop1.getName(), propertyIterator.nextProperty().getName()); propertyIterator = referenceableNode.getReferences("unknown"); assertEquals(0, propertyIterator.getSize()); propertyIterator = referenceableNode.getWeakReferences(); assertEquals(2, propertyIterator.getSize()); propertyNames = new HashSet<String>(2); while (propertyIterator.hasNext()) { propertyNames.add(propertyIterator.nextProperty().getName()); } assertTrue(propertyNames.contains(prop2.getName()) && propertyNames.contains(prop4.getName())); propertyIterator = referenceableNode.getWeakReferences("prop4"); assertEquals(1, propertyIterator.getSize()); assertEquals(prop4.getName(), propertyIterator.nextProperty().getName()); propertyIterator = referenceableNode.getWeakReferences("unknown"); assertEquals(0, propertyIterator.getSize()); } finally { node1.remove(); node2.remove(); referenceableNode.remove(); session.save(); } }
@Test @FixFor("MODE-1489") public void shouldAllowMultipleOrderBeforeWithoutSave() throws Exception { int childCount = 2; Node parent = session.getRootNode().addNode("parent", "nt:unstructured"); try { for (int i = 0; i < childCount; i++) { parent.addNode("Child " + i, "nt:unstructured"); } session.save(); long childIdx = 0; NodeIterator nodeIterator = parent.getNodes(); while (nodeIterator.hasNext()) { parent.orderBefore("Child " + childIdx, "Child 0"); childIdx++; nodeIterator.nextNode(); } session.save(); nodeIterator = parent.getNodes(); childIdx = nodeIterator.getSize() - 1; while (nodeIterator.hasNext()) { Node child = nodeIterator.nextNode(); assertEquals("Child " + childIdx, child.getName()); childIdx--; } } finally { parent.remove(); session.save(); } }
@Test @FixFor("MODE-2034") public void shouldReorderChildrenWithChanges() throws Exception { Node parent = session.getRootNode().addNode("parent", "nt:unstructured"); try { Node child1 = parent.addNode("child1"); Node child2 = parent.addNode("child2"); session.save(); parent.orderBefore("child2", "child1"); child1.setProperty("prop", "value"); child2.setProperty("prop", "value"); session.save(); NodeIterator nodeIterator = parent.getNodes(); long childIdx = nodeIterator.getSize(); while (nodeIterator.hasNext()) { Node child = nodeIterator.nextNode(); assertEquals("child" + childIdx, child.getName()); childIdx--; } } finally { parent.remove(); session.save(); } }
@Test @FixFor( "MODE-2386 ") public void shouldIterateUsingGlobsInTransientSession() throws RepositoryException { try { Node jcrRootNode = session.getRootNode(); Node rootNode = jcrRootNode.addNode("testRoot"); String dynOperandName = session.encode("tsql:dynamicCommand"); Node command = rootNode.addNode(dynOperandName); String columnsName = session.encode("tsql:asColumns"); command.addNode(columnsName); command.addNode(session.encode("tsql:intoGroup")); command.addNode(session.encode("tsql:sql")); command = rootNode.getNode(dynOperandName); NodeIterator nodeIterator = command.getNodes(columnsName); assertEquals(1, nodeIterator.getSize()); assertEquals(columnsName, nodeIterator.nextNode().getName()); } finally { session.getNode("/testRoot").remove(); session.save(); } }