Search in sources :

Example 26 with NotExecutableException

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 });
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node)

Example 27 with NotExecutableException

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
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Query(javax.jcr.query.Query) Node(javax.jcr.Node) VersionException(javax.jcr.version.VersionException)

Example 28 with NotExecutableException

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();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Query(javax.jcr.query.Query) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 29 with NotExecutableException

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 });
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node)

Example 30 with NotExecutableException

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);
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) AccessDeniedException(javax.jcr.AccessDeniedException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable)

Aggregations

NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)381 Node (javax.jcr.Node)149 NodeType (javax.jcr.nodetype.NodeType)84 Value (javax.jcr.Value)81 RepositoryException (javax.jcr.RepositoryException)64 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)61 Session (javax.jcr.Session)59 Property (javax.jcr.Property)47 NodeDefinition (javax.jcr.nodetype.NodeDefinition)29 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)28 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)25 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)23 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)22 Test (org.junit.Test)22 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)21 User (org.apache.jackrabbit.api.security.user.User)19 Principal (java.security.Principal)18 NodeIterator (javax.jcr.NodeIterator)18 UserManager (org.apache.jackrabbit.api.security.user.UserManager)17 ItemExistsException (javax.jcr.ItemExistsException)16