use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class ElementTest method testElementTestNameTestSomeNTWithSNS.
/**
* Tests the element test with a name test argument and a type argument that
* matches only certain child nodes. Additonally this test requires that
* testroot allows same name sibling child nodes.
*/
public void testElementTestNameTestSomeNTWithSNS() throws RepositoryException, NotExecutableException {
Node n1 = testRootNode.addNode(nodeName1, testNodeType);
if (!n1.getDefinition().allowsSameNameSiblings()) {
throw new NotExecutableException("Node at " + testRoot + " does not allow same name siblings with name " + nodeName1);
}
testRootNode.addNode(nodeName1, simpleNodeType);
Node n2 = testRootNode.addNode(nodeName1, testNodeType);
testRootNode.addNode(nodeName2, simpleNodeType);
testRootNode.addNode(nodeName3, testNodeType);
testRootNode.getSession().save();
String query = "/" + jcrRoot + testRoot + "/element(" + nodeName1 + ", " + testNodeType + ")";
executeXPathQuery(superuser, query, new Node[] { n1, n2 });
}
use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class SaveTest method testVersionException.
/**
* Tests if a {@link javax.jcr.version.VersionException} is thrown when a
* query is stored under a checked in node.
* <p>
* The tests creates a node under <code>testRoot</code> with name
* <code>nodeName1</code> and adds a mix:versionable mixin if the node is
* not already versionable.
* Then the test tries to store a query as <code>nodeName2</code> under node
* <code>nodeName1</code>.
* @throws NotExecutableException if nt:query is not supported.
*/
public void testVersionException() throws RepositoryException, NotExecutableException {
checkNtQuery();
// check if repository supports versioning
if (!isSupported(Repository.OPTION_VERSIONING_SUPPORTED)) {
throw new NotExecutableException();
}
Query query = superuser.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
// create a node that is versionable
Node versionable = testRootNode.addNode(nodeName1, testNodeType);
// or try to make it versionable if it is not
ensureMixinType(versionable, mixVersionable);
testRootNode.getSession().save();
versionable.checkin();
try {
query.storeAsNode(testRoot + "/" + nodeName1 + "/" + nodeName2);
fail("Query.storeAsNode() must throw VersionException, parent node is checked in.");
} catch (VersionException e) {
// expected behaviour
}
}
use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class SaveTest method testLockException.
/**
* Tests if a {@link javax.jcr.lock.LockException} is thrown if a query is
* stored under a node locked by another <code>Session</code>.
* <p>
* The test creates a node <code>nodeName1</code> of type <code>testNodeType</code>
* under <code>testRoot</code> and locks the node with the superuser session.
* Then the test tries to store a query as <code>nodeName2</code> under
* <code>nodeName1</code> with the readWrite <code>Session</code>.
* @throws NotExecutableException if nt:query is not supported.
*/
public void testLockException() throws RepositoryException, NotExecutableException {
checkNtQuery();
// check if repository supports locking
if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
throw new NotExecutableException();
}
// create a node that is lockable
Node lockable = testRootNode.addNode(nodeName1, testNodeType);
// or try to make it lockable if it is not
ensureMixinType(lockable, mixLockable);
testRootNode.getSession().save();
lockable.lock(false, true);
Session readWrite = getHelper().getReadWriteSession();
try {
Query query = readWrite.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
query.storeAsNode(testRoot + "/" + nodeName1 + "/" + nodeName2);
fail("Query.storeAsNode() must throw LockException, parent node is locked.");
} catch (LockException e) {
// expected behaviour
} finally {
readWrite.logout();
lockable.unlock();
}
}
use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class SQLJoinTest method testJoinSNS.
/**
* Test a SQL query with a primary and mixin nodetype join on child nodes
* with same name siblings.
* <ul>
* <li>{@code testroot} path to node that allows child nodes with same name.
* <li>{@code nodename1} node name of the same name siblings.
* </ul>
* @throws NotExecutableException if <code>testroot</code> does not allow
* same name siblings.
*/
public void testJoinSNS() throws RepositoryException, NotExecutableException {
Node n1 = testRootNode.addNode(nodeName1, testNodeType);
ensureMixinType(n1, mixReferenceable);
if (!n1.getDefinition().allowsSameNameSiblings()) {
throw new NotExecutableException("Node at " + testRoot + " does not allow same name siblings with name " + nodeName1);
}
testRootNode.addNode(nodeName1, testNodeType);
Node n2 = testRootNode.addNode(nodeName2, testNodeType);
ensureMixinType(n2, mixReferenceable);
testRootNode.getSession().save();
StringBuffer query = new StringBuffer("SELECT * FROM ");
query.append(testNodeType).append(", ").append(mixReferenceable);
query.append(" WHERE ");
query.append(testNodeType).append(".").append(jcrPath);
query.append(" = ");
query.append(mixReferenceable).append(".").append(jcrPath);
query.append(" AND ").append(jcrPath).append(" LIKE ");
query.append("'").append(testRoot).append("/%'");
executeSqlQuery(superuser, query.toString(), new Node[] { n1, n2 });
}
use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.
the class NotUserAdministratorTest method testAddToGroup.
public void testAddToGroup() throws NotExecutableException, RepositoryException {
Authorizable auth = uMgr.getAuthorizable(SecurityConstants.ADMINISTRATORS_NAME);
if (auth == null || !auth.isGroup()) {
throw new NotExecutableException("Couldn't find 'administrators' group");
}
Group gr = (Group) auth;
try {
auth = uMgr.getAuthorizable(uID);
gr.addMember(auth);
save(uSession);
fail("a common user should not be allowed to modify any groups.");
} catch (AccessDeniedException e) {
// success
} finally {
if (gr.removeMember(auth)) {
save(uSession);
}
}
}
Aggregations