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());
}
}
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));
}
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));
}
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());
}
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);
}
Aggregations