use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class NodeReadMethodsTest method testHasNodes.
/**
* Test if hasNodes() returns true if any sub node exists or false if not.
* Tested node: root
*/
public void testHasNodes() throws RepositoryException {
Node node = testRootNode;
NodeIterator nodes = node.getNodes();
int i = 0;
while (nodes.hasNext()) {
nodes.nextNode();
i++;
}
if (i == 0) {
assertFalse("node.hasNodes() returns true although " + "no sub nodes existing", node.hasNodes());
} else {
assertTrue("node.hasNodes() returns false althuogh " + "sub nodes are existing", node.hasNodes());
}
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class NodeReadMethodsTest method testHasNode.
/**
* Test if hasNode(String relPath) returns true if the required node exists
* and false if it doesn't. Tested node: root
*/
public void testHasNode() throws NotExecutableException, RepositoryException {
Node node = testRootNode;
NodeIterator nodes = node.getNodes();
StringBuffer notExistingNodeName = new StringBuffer();
while (nodes.hasNext()) {
Node n = nodes.nextNode();
assertTrue("hasNode(String relPath) returns false although " + "node at relPath is existing", node.hasNode(n.getName()));
notExistingNodeName.append(n.getName() + "X");
}
if (notExistingNodeName.toString().equals("")) {
throw new NotExecutableException("Workspace does not have sufficient content for this test. " + "Root node must have at least one child node.");
}
assertFalse("hasNode(String relPath) returns true although " + "node at relPath is not existing", node.hasNode(notExistingNodeName.toString().replaceAll(":", "")));
}
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
}
}
Aggregations