use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class QueryResultTest method testGetSize.
public void testGetSize() throws RepositoryException {
QueryManager qm = superuser.getWorkspace().getQueryManager();
for (int i = 0; i < 10; i++) {
String stmt = testPath + "/*[@" + propertyName1 + " < 1000]";
QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
assertEquals("Wrong size of NodeIterator in result", INITIAL_NODE_NUM - i, result.getNodes().getSize());
// remove node for the next iteration
testRootNode.getNode("node" + i).remove();
testRootNode.save();
}
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class QueryResultTest method testGetSizeOrderByScore.
public void testGetSizeOrderByScore() throws RepositoryException {
QueryManager qm = superuser.getWorkspace().getQueryManager();
for (int i = 0; i < 10; i++) {
String stmt = testPath + "/*[@" + propertyName1 + " < 1000] order by jcr:score()";
QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
assertEquals("Wrong size of NodeIterator in result", INITIAL_NODE_NUM - i, result.getNodes().getSize());
// remove node for the next iteration
testRootNode.getNode("node" + i).remove();
testRootNode.save();
}
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class QueryResultTest method testGetPosition.
public void testGetPosition() throws RepositoryException {
QueryManager qm = superuser.getWorkspace().getQueryManager();
for (int i = 0; i < 10; i++) {
String stmt = testPath + "/*[@" + propertyName1 + " < 1000]";
QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
NodeIterator it = result.getNodes();
assertEquals("Wrong position", 0, it.getPosition());
int count = 0;
while (it.hasNext()) {
long position = it.getPosition();
it.nextNode();
assertEquals("Wrong position", count++, position);
}
try {
it.next();
fail("must throw NoSuchElementException");
} catch (Exception e) {
// correct
}
// remove node for the next iteration
testRootNode.getNode("node" + i).remove();
testRootNode.save();
}
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class QueryResultTest method testIteratorNextOrderByScore.
public void testIteratorNextOrderByScore() throws RepositoryException {
QueryManager qm = superuser.getWorkspace().getQueryManager();
for (int i = 0; i < 10; i++) {
String stmt = testPath + "/*[@" + propertyName1 + " < 1000] order by jcr:score()";
QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
int size = 0;
for (NodeIterator it = result.getNodes(); it.hasNext(); ) {
it.nextNode();
size++;
}
assertEquals("Wrong size of NodeIterator in result", INITIAL_NODE_NUM - i, size);
// remove node for the next iteration
testRootNode.getNode("node" + i).remove();
testRootNode.save();
}
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class DerefTest method testDerefToVersionNode.
/**
* Checks if jcr:deref works when dereferencing into the version storage.
*/
public void testDerefToVersionNode() throws RepositoryException {
Node referenced = testRootNode.addNode(nodeName1);
referenced.addMixin(mixVersionable);
testRootNode.save();
Version version = referenced.checkin();
Node referencedVersionNode = version.getNode(jcrFrozenNode);
Node referencer = testRootNode.addNode(nodeName2);
referencer.setProperty(propertyName1, referencedVersionNode);
testRootNode.save();
String query = "/" + testRoot + "/*[@" + propertyName1 + "]/jcr:deref(@" + propertyName1 + ",'*')";
QueryManager qm = superuser.getWorkspace().getQueryManager();
Query q = qm.createQuery(query, Query.XPATH);
QueryResult qr = q.execute();
NodeIterator ni = qr.getNodes();
assertEquals("Must find one result in query", 1, ni.getSize());
while (ni.hasNext()) {
Node node = (Node) ni.next();
assertTrue(node.getProperty("jcr:frozenUuid").getString().equals(referenced.getUUID()));
}
}
Aggregations