Search in sources :

Example 41 with NodeIterator

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

Example 42 with NodeIterator

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

Example 43 with NodeIterator

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
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) NoSuchElementException(java.util.NoSuchElementException)

Example 44 with NodeIterator

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

Example 45 with NodeIterator

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

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