Search in sources :

Example 66 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 67 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)

Example 68 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class NodeOrderableChildNodesTest method prepareTest.

/**
     * Sets up the test content needed for the test cases.
     */
private void prepareTest() throws RepositoryException {
    // get root node
    Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
    // create testNode
    parentNode = defaultRootNode.addNode(nodeName1, getProperty("nodetype2"));
    // add child node
    Node firstNode = parentNode.addNode(nodeName2, getProperty("nodetype3"));
    // add a second child node
    Node secondNode = parentNode.addNode(nodeName3, getProperty("nodetype3"));
    // save the new nodes
    superuser.save();
    // get child node refs
    NodeIterator it = parentNode.getNodes();
    initialFirstNode = it.nextNode();
    initialSecondNode = it.nextNode();
    // first lets test if the nodes have been added in the right order
    assertTrue("Child nodes are not added in proper order ", firstNode.isSame(initialFirstNode));
    assertTrue("Child nodes are not added in proper order ", secondNode.isSame(initialSecondNode));
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node)

Example 69 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class XPathDocOrderTest method docOrderTest.

//-----------------------------< internal >---------------------------------
/**
     * Executes a statement, checks if the Result contains exactly one node with
     * <code>path</code>.
     *
     * @param stmt to be executed
     * @param path the path of the node in the query result.
     */
private void docOrderTest(Statement stmt, String path) throws RepositoryException, NotExecutableException {
    if (!isSupported(Repository.QUERY_XPATH_DOC_ORDER)) {
        throw new NotExecutableException("Repository does not support document order on result set.");
    }
    int count = 0;
    // check precondition: at least 3 nodes
    for (NodeIterator it = testRootNode.getNodes(); it.hasNext(); it.nextNode()) {
        count++;
    }
    if (count < 3) {
        throw new NotExecutableException("Workspace does not contain enough content under: " + testRoot + ". At least 3 nodes are required for this test.");
    }
    QueryResult result = execute(stmt);
    checkResult(result, 1);
    assertEquals("Wrong result node.", path, result.getNodes().nextNode().getPath());
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException)

Example 70 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class XPathDocOrderTest method testDocOrderLastFunction.

/**
     * Tests the <code>last()</code> function.
     * <p>
     * For configuration description see {@link XPathDocOrderTest}.
     */
public void testDocOrderLastFunction() throws Exception {
    String xpath = xpathRoot + "/*[position()=last()]";
    String resultPath = "";
    for (NodeIterator nodes = testRootNode.getNodes(); nodes.hasNext(); ) {
        resultPath = nodes.nextNode().getPath();
    }
    docOrderTest(new Statement(xpath, qsXPATH), resultPath);
}
Also used : NodeIterator(javax.jcr.NodeIterator)

Aggregations

NodeIterator (javax.jcr.NodeIterator)309 Node (javax.jcr.Node)216 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