Search in sources :

Example 91 with NodeIterator

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.");
}
Also used : NodeIterator(javax.jcr.NodeIterator)

Example 92 with NodeIterator

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()]));
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor)

Example 93 with NodeIterator

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());
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult)

Example 94 with NodeIterator

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());
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult)

Example 95 with NodeIterator

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.");
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException)

Aggregations

NodeIterator (javax.jcr.NodeIterator)307 Node (javax.jcr.Node)214 Session (javax.jcr.Session)55 QueryResult (javax.jcr.query.QueryResult)52 RepositoryException (javax.jcr.RepositoryException)40 Query (javax.jcr.query.Query)40 Test (org.junit.Test)36 QueryManager (javax.jcr.query.QueryManager)34 PropertyIterator (javax.jcr.PropertyIterator)30 ArrayList (java.util.ArrayList)26 Property (javax.jcr.Property)24 Version (javax.jcr.version.Version)23 NoSuchElementException (java.util.NoSuchElementException)19 Value (javax.jcr.Value)19 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)19 HashSet (java.util.HashSet)13 PathNotFoundException (javax.jcr.PathNotFoundException)12 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)11 NodeImpl (org.apache.jackrabbit.core.NodeImpl)11 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)11