use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class SQLPathTest method setUp.
protected void setUp() throws Exception {
isReadOnly = true;
super.setUp();
session = getHelper().getReadOnlySession();
// check precondition for this test
if (testRootNode.hasNodes()) {
for (NodeIterator it = testRootNode.getNodes(); it.hasNext(); ) {
if (it.nextNode().hasNodes()) {
return;
}
}
}
fail("Default workspace at " + testRoot + " does not contain sufficient content.");
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class SQLPathTest method testDescendantSelfTestRoot.
/**
* Tests if <somepath>/%/<nodename> OR <somepath>/<nodename>
* returns nodes with name <nodename> which are descendants of
* node at <code>testroot</code>.
* @throws NotExecutableException
*/
public void testDescendantSelfTestRoot() throws RepositoryException, NotExecutableException {
// get first node which is two levels deeper than node at testroot
Node n = null;
for (NodeIterator it = testRootNode.getNodes(); it.hasNext(); ) {
Node child = it.nextNode();
if (child.hasNodes()) {
n = child.getNodes().nextNode();
break;
}
}
final String name = n.getName();
String sql = getStatement(testRoot + "/%/" + name);
sql += " OR " + jcrPath + " = '" + testRoot + "/" + name + "'";
// gather the nodes with visitor
final List<Node> nodes = new ArrayList<Node>();
testRootNode.accept(new TraversingItemVisitor.Default() {
protected void entering(Node node, int level) throws RepositoryException {
if (node.getName().equals(name) && !testRootNode.isSame(node)) {
nodes.add(node);
}
}
});
executeSqlQuery(session, sql, nodes.toArray(new Node[nodes.size()]));
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class QueryResultNodeIteratorTest method testGetPositionEmptyIterator.
/**
* Tests the method <code>NodeIterator.getPosition()</code> on an empty
* <code>NodeIterator</code>.
* @throws NotExecutableException
*/
public void testGetPositionEmptyIterator() throws RepositoryException, NotExecutableException {
QueryResult rs = execute(xpathRoot + "/" + nodeName4, qsXPATH);
NodeIterator it = rs.getNodes();
assertFalse("NodeIterator must be empty.", it.hasNext());
assertEquals("Empty NodeIterator must return 0 on getPosition()", 0, it.getPosition());
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class QueryResultNodeIteratorTest method testGetPosition.
/**
* Tests the method <code>NodeIterator.getPosition()</code>.
*/
public void testGetPosition() throws RepositoryException, NotExecutableException {
QueryResult rs = execute(xpathRoot + "//*", qsXPATH);
// getPosition initially returns 0
NodeIterator it = rs.getNodes();
assertEquals("Initial call to getPosition() must return 0.", 0, it.getPosition());
// check getPosition while iterating
int index = 0;
while (it.hasNext()) {
it.nextNode();
assertEquals("Wrong position returned by getPosition()", ++index, it.getPosition());
}
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class QueryResultNodeIteratorTest method testGetSize.
/**
* Tests if {@link javax.jcr.NodeIterator#getSize()} returns the correct
* size.
*
* @throws org.apache.jackrabbit.test.NotExecutableException
* if getSize() returns -1 (unavailable).
*/
public void testGetSize() throws RepositoryException, NotExecutableException {
NodeIterator it = execute(xpathRoot + "//*", qsXPATH).getNodes();
long size = testRootNode.getNodes().getSize();
if (size != -1) {
long count = 0;
while (it.hasNext()) {
it.nextNode();
count++;
}
assertEquals("NodeIterator.getSize does not return correct number.", size, count);
} else {
throw new NotExecutableException("NodeIterator.getSize() does not return size information.");
}
}
Aggregations