use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class QueryResultTest method testSkipOrderByProperty.
public void testSkipOrderByProperty() throws RepositoryException {
QueryManager qm = superuser.getWorkspace().getQueryManager();
for (int i = 0; i < 10; i++) {
String stmt = testPath + "/*[@" + propertyName1 + " < 1000] order by @" + propertyName1;
QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
for (int j = 0; j < INITIAL_NODE_NUM - i; j++) {
// skip to each node in the result
NodeIterator it = result.getNodes();
it.skip(j);
long propValue = it.nextNode().getProperty(propertyName1).getLong();
// expected = number of skipped nodes + number of deleted nodes
long expected = j + i;
assertEquals("Wrong node after skip()", expected, propValue);
}
try {
NodeIterator it = result.getNodes();
it.skip(it.getSize() + 1);
fail("must throw NoSuchElementException");
} catch (NoSuchElementException e) {
// correct
}
// remove node for the next iteration
testRootNode.getNode("node" + i).remove();
testRootNode.save();
}
}
use of javax.jcr.NodeIterator 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.NodeIterator 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.NodeIterator in project jackrabbit by apache.
the class ShareableNodeTest method testPathConstraint.
public void testPathConstraint() throws RepositoryException {
Node n1 = testRootNode.addNode(nodeName1);
Node n2 = testRootNode.addNode(nodeName2);
Node s = n1.addNode(nodeName3);
s.setProperty(propertyName1, "value");
s.addMixin(mixShareable);
Node n4 = s.addNode(nodeName4);
n4.setProperty(propertyName2, "value");
testRootNode.save();
Workspace wsp = superuser.getWorkspace();
wsp.clone(wsp.getName(), s.getPath(), n2.getPath() + "/" + s.getName(), false);
String stmt = testPath + "/" + nodeName1 + "/*[@" + propertyName1 + "='value']";
NodeIterator nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", s.isSame(nodes.nextNode()));
stmt = testPath + "/" + nodeName2 + "/*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", s.isSame(nodes.nextNode()));
stmt = testPath + "//*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", s.isSame(nodes.nextNode()));
stmt = testPath + "//*[@" + propertyName2 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", n4.isSame(nodes.nextNode()));
// remove a node from the shared set
s.removeShare();
testRootNode.save();
s = n2.getNode(nodeName3);
stmt = testPath + "/" + nodeName1 + "/*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 0, nodes.getSize());
stmt = testPath + "/" + nodeName2 + "/*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", s.isSame(nodes.nextNode()));
stmt = testPath + "//*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 1, nodes.getSize());
// spec does not say which path must be returned -> use isSame()
assertTrue("wrong node", s.isSame(nodes.nextNode()));
// remove remaining node from the shared set
s.removeShare();
testRootNode.save();
stmt = testPath + "/" + nodeName1 + "/*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 0, nodes.getSize());
stmt = testPath + "/" + nodeName2 + "/*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 0, nodes.getSize());
stmt = testPath + "//*[@" + propertyName1 + "='value']";
nodes = executeQuery(stmt).getNodes();
assertEquals("wrong result size", 0, nodes.getSize());
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class UserImporterTest method testImportGroupMembersFromNodesBestEffort.
public void testImportGroupMembersFromNodesBestEffort() throws RepositoryException, IOException, SAXException {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><sv:node sv:name=\"s\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:sling=\"http://sling.apache.org/jcr/sling/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property><sv:property sv:name=\"jcr:created\" sv:type=\"Date\"><sv:value>2010-08-17T18:22:20.086+02:00</sv:value></sv:property><sv:property sv:name=\"jcr:createdBy\" sv:type=\"String\"><sv:value>admin</sv:value></sv:property><sv:node sv:name=\"sh\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:AuthorizableFolder</sv:value></sv:property><sv:property sv:name=\"jcr:created\" sv:type=\"Date\"><sv:value>2010-08-17T18:22:20.086+02:00</sv:value></sv:property><sv:property sv:name=\"jcr:createdBy\" sv:type=\"String\"><sv:value>admin</sv:value></sv:property><sv:node sv:name=\"shrimps\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Group</sv:value></sv:property><sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>08429aec-6f09-30db-8c83-1a2a57fc760c</sv:value></sv:property><sv:property sv:name=\"jcr:created\" sv:type=\"Date\">" + "<sv:value>2010-08-17T18:22:20.086+02:00</sv:value></sv:property><sv:property sv:name=\"jcr:createdBy\" sv:type=\"String\"><sv:value>admin</sv:value></sv:property><sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>shrimps</sv:value></sv:property><sv:node sv:name=\"rep:members\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:node sv:name=\"adi\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:node sv:name=\"adi\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:property sv:name=\"adi\" sv:type=\"WeakReference\"><sv:value>c46335eb-267e-3e1c-9e5b-017acb4cd799</sv:value></sv:property><sv:property sv:name=\"admin\" sv:type=\"WeakReference\"><sv:value>21232f29-7a57-35a7-8389-4a0e4a801fc3</sv:value></sv:property></sv:node><sv:node sv:name=\"angi\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:property sv:name=\"angi\" sv:type=\"WeakReference\"><sv:value>a468b64f-b1df-377c-b325-20d97aaa1ad9</sv:value></sv:property><sv:property sv:name=\"anonymous\" sv:type=\"WeakReference\"><sv:value>294de355-7d9d-30b3-92d8-a1e6aab028cf</sv:value></sv:property><sv:property sv:name=\"cati\" sv:type=\"WeakReference\"><sv:value>f08910b6-41c8-3cb9-a648-1dddd14b132d</sv:value></sv:property></sv:node></sv:node><sv:n" + "ode sv:name=\"debbi\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:node sv:name=\"debbi\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:property sv:name=\"debbi\" sv:type=\"WeakReference\"><sv:value>d53bedf9-ebb8-3117-a8b8-162d32b4bee2</sv:value></sv:property><sv:property sv:name=\"eddi\" sv:type=\"WeakReference\"><sv:value>1795fa1a-3d20-3a64-996e-eaaeb520a01e</sv:value></sv:property><sv:property sv:name=\"gabi\" sv:type=\"WeakReference\"><sv:value>a0d499c7-5105-3663-8611-a32779a57104</sv:value></sv:property><sv:property sv:name=\"hansi\" sv:type=\"WeakReference\"><sv:value>9ea4d671-8ed1-399a-8401-59487a14d00a</sv:value></sv:property></sv:node><sv:node sv:name=\"hari\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:property sv:name=\"hari\" sv:type=\"WeakReference\"><sv:value>a9bcf1e4-d7b9-3a22-a297-5c812d938889</sv:value></sv:property><sv:property sv:name=\"lisi\" sv:type=\"WeakReference\"><sv:value>dc3a8f16-70d6-3bea-a9b7-b65048a0ac40</sv:value></sv:property></sv:node><sv:node sv:name=\"luzi\"><sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:Members</sv:value></sv:property><sv:property sv:name=\"luzi\" sv:type=\"WeakReference\"><sv:value>9ec299fd-3461-3f1a-9749-92a76f2516eb</sv:value></sv:property><sv:property sv:name=\"pipi\" sv:type=" + "\"WeakReference\"><sv:value>16d5d24f-5b09-3199-9bd4-e5f57bf11237</sv:value></sv:property><sv:property sv:name=\"susi\" sv:type=\"WeakReference\"><sv:value>536931d8-0dec-318c-b3db-9612bdd004d4</sv:value></sv:property></sv:node></sv:node></sv:node></sv:node></sv:node></sv:node>";
List<String> createdUsers = new LinkedList<String>();
NodeImpl groupsNode = (NodeImpl) sImpl.getNode(umgr.getGroupsPath());
try {
String[] users = { "angi", "adi", "hansi", "lisi", "luzi", "susi", "pipi", "hari", "gabi", "eddi", "debbi", "cati", "admin", "anonymous" };
doImport(groupsNode, xml, UserImporter.ImportBehavior.BESTEFFORT);
if (!umgr.isAutoSave()) {
sImpl.save();
}
for (String user : users) {
if (umgr.getAuthorizable(user) == null) {
umgr.createUser(user, user);
createdUsers.add(user);
}
}
if (!umgr.isAutoSave()) {
sImpl.save();
}
Authorizable aShrimps = umgr.getAuthorizable("shrimps");
assertNotNull(aShrimps);
assertTrue(aShrimps.isGroup());
Group gShrimps = (Group) aShrimps;
for (String user : users) {
assertTrue(user + " should be member of " + gShrimps, gShrimps.isMember(umgr.getAuthorizable(user)));
}
} finally {
sImpl.refresh(false);
for (String user : createdUsers) {
Authorizable a = umgr.getAuthorizable(user);
if (a != null && !a.isGroup()) {
a.remove();
}
}
if (!umgr.isAutoSave()) {
sImpl.save();
}
for (NodeIterator it = groupsNode.getNodes(); it.hasNext(); ) {
it.nextNode().remove();
}
if (!umgr.isAutoSave()) {
sImpl.save();
}
}
}
Aggregations