use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class NodeReadMethodsTest method locateNodeWithSameNameSiblings.
/**
* Returns the first descendant of <code>node</code> which has same name
* siblings.
*
* @param node <code>Node</code> to start traversal.
* @return first node with same name siblings
*/
private Node locateNodeWithSameNameSiblings(Node node) throws RepositoryException {
NodeIterator nodes = node.getNodes();
while (nodes.hasNext()) {
Node n = nodes.nextNode();
NodeIterator nodes2 = node.getNodes(n.getName());
int i = 0;
while (nodes2.hasNext()) {
nodes2.next();
i++;
}
if (i > 1) {
// node has same name siblings
return n;
} else {
Node returnedNode = locateNodeWithSameNameSiblings(n);
if (returnedNode != null) {
return returnedNode;
}
}
}
return null;
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class NodeIteratorTest method testGetSize.
/**
* Tests if {@link javax.jcr.NodeIterator#getSize()} returns the correct
* size.
* @throws NotExecutableException if getSize() returns -1 (unavailable).
*/
public void testGetSize() throws RepositoryException, NotExecutableException {
NodeIterator iter = testRootNode.getNodes();
long size = testRootNode.getNodes().getSize();
if (size != -1) {
long count = 0;
while (iter.hasNext()) {
iter.nextNode();
count++;
}
assertEquals("NodeIterator.getSize does not return correct number.", size, count);
} else {
throw new NotExecutableException("NodeIterator.getSize() does not return size information.");
}
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class NodeIteratorTest method testNoSuchElementException.
/**
* Tests if a {@link java.util.NoSuchElementException} is thrown when {@link
* javax.jcr.NodeIterator#nextNode()} is called and there are no more nodes
* available.
*/
public void testNoSuchElementException() throws RepositoryException {
NodeIterator iter = testRootNode.getNodes();
while (iter.hasNext()) {
iter.nextNode();
}
try {
iter.nextNode();
fail("nextNode() must throw a NoSuchElementException when no nodes are available");
} catch (NoSuchElementException e) {
// success
}
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class NodeIteratorTest method testGetPos.
/**
* Tests if {@link javax.jcr.NodeIterator#getPosition()} return correct values.
*/
public void testGetPos() throws RepositoryException {
NodeIterator iter = testRootNode.getNodes();
assertEquals("Initial call to getPos() must return zero", 0, iter.getPosition());
int index = 0;
while (iter.hasNext()) {
iter.nextNode();
assertEquals("Wrong position returned by getPos()", ++index, iter.getPosition());
}
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class NodeOrderableChildNodesTest method testOrderBeforePlaceAtEndParentSave.
/**
* Creates two child nodes, reorders first node to end, uses parentNode's
* {@link Node#save()}.
*/
public void testOrderBeforePlaceAtEndParentSave() throws RepositoryException, NotExecutableException {
checkOrderableNodeType(getProperty("nodetype2"));
prepareTest();
// ok lets reorder and save
parentNode.orderBefore(initialFirstNode.getName(), null);
parentNode.save();
// get child node refs
NodeIterator it = parentNode.getNodes();
Node firstNode = it.nextNode();
Node secondNode = it.nextNode();
// lets see if reordering worked
assertTrue("Child nodes are not added in proper order after Node.orderBefore()!", firstNode.isSame(initialSecondNode));
assertTrue("Child nodes are not added in proper order after Node.orderBefore()!", secondNode.isSame(initialFirstNode));
}
Aggregations