Search in sources :

Example 46 with LockException

use of javax.jcr.lock.LockException in project jackrabbit by apache.

the class JcrDavExceptionTest method testDerivedException.

public void testDerivedException() {
    RepositoryException re = new DerievedRepositoryException();
    // creating JcrDavException from the derived exception must not throw
    // NPE (see issue https://issues.apache.org/jira/browse/JCR-1678)
    JcrDavException jde = new JcrDavException(re);
    // error code must be the same as for LockException
    assertEquals(new JcrDavException(new LockException()).getErrorCode(), jde.getErrorCode());
}
Also used : LockException(javax.jcr.lock.LockException) RepositoryException(javax.jcr.RepositoryException)

Example 47 with LockException

use of javax.jcr.lock.LockException in project jackrabbit by apache.

the class NodeRemoveMixinTest method testLocked.

/**
     * Tests if <code>Node.removeMixin(String mixinName)</code> throws a
     * <code>LockException</code> if <code>Node</code> is locked.
     * <p>
     * The test creates a node <code>nodeName1</code> of type
     * <code>testNodeType</code> under <code>testRoot</code>, adds a mixin and
     * then locks the node with the superuser session. Then the test tries to
     * remove the before added mixin readWrite <code>Session</code>.
     */
public void testLocked() throws ConstraintViolationException, NotExecutableException, RepositoryException {
    Session session = testRootNode.getSession();
    if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
        throw new NotExecutableException("Locking is not supported.");
    }
    // create a node that is lockable
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    // or try to make it lockable if it is not
    ensureMixinType(node, mixLockable);
    testRootNode.getSession().save();
    String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
    if (mixinName == null) {
        throw new NotExecutableException("No testable mixin node type found");
    }
    node.addMixin(mixinName);
    testRootNode.getSession().save();
    // remove first slash of path to get rel path to root
    String pathRelToRoot = node.getPath().substring(1);
    // access node through another session to lock it
    Session session2 = getHelper().getSuperuserSession();
    try {
        Node node2 = session2.getRootNode().getNode(pathRelToRoot);
        node2.lock(true, true);
        try {
            // remove mixin on locked node must throw either directly upon
            // removeMixin or upon save.
            node.removeMixin(mixinName);
            node.save();
            fail("Node.removeMixin(String mixinName) must throw a " + "LockException if the node is locked.");
        } catch (LockException e) {
        // success
        }
        // unlock to remove node at tearDown()
        node2.unlock();
    } finally {
        session2.logout();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 48 with LockException

use of javax.jcr.lock.LockException in project jackrabbit by apache.

the class WorkspaceMoveTest method testMoveNodesLocked.

/**
     * A LockException is thrown if a lock prevents the copy.
     */
public void testMoveNodesLocked() throws RepositoryException, NotExecutableException {
    // we assume repository supports locking
    String dstAbsPath = node2.getPath() + "/" + node1.getName();
    // get other session
    Session otherSession = getHelper().getReadWriteSession();
    try {
        // get lock target node in destination wsp through other session
        Node lockTarget = (Node) otherSession.getItem(node2.getPath());
        // add mixin "lockable" to be able to lock the node
        ensureMixinType(lockTarget, mixLockable);
        lockTarget.getParent().save();
        // lock dst parent node using other session
        lockTarget.lock(true, true);
        try {
            workspace.move(node1.getPath(), dstAbsPath);
            fail("LockException was expected.");
        } catch (LockException e) {
        // successful
        } finally {
            lockTarget.unlock();
        }
    } finally {
        otherSession.logout();
    }
}
Also used : LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 49 with LockException

use of javax.jcr.lock.LockException in project jackrabbit by apache.

the class WorkspaceCloneTest method testCloneNodesLocked.

/**
     * A LockException is thrown if a lock prevents the copy.
     */
public void testCloneNodesLocked() throws RepositoryException, NotExecutableException {
    // we assume repository supports locking
    String dstAbsPath = node2W2.getPath() + "/" + node1.getName();
    // get lock target node in destination wsp through other session
    Node lockTarget = (Node) rwSessionW2.getItem(node2W2.getPath());
    // add mixin "lockable" to be able to lock the node
    ensureMixinType(lockTarget, mixLockable);
    lockTarget.getParent().save();
    // lock dst parent node using other session
    lockTarget.lock(true, true);
    try {
        workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true);
        fail("LockException was expected.");
    } catch (LockException e) {
    // successful
    } finally {
        lockTarget.unlock();
    }
}
Also used : LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node)

Example 50 with LockException

use of javax.jcr.lock.LockException in project jackrabbit by apache.

the class WorkspaceCopyBetweenWorkspacesTest method testCopyNodesLocked.

/**
     * A LockException is thrown if a lock prevents the copy.
     */
public void testCopyNodesLocked() throws RepositoryException, NotExecutableException {
    if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
        throw new NotExecutableException("Repository does not support locking.");
    }
    // we assume repository supports locking
    String dstAbsPath = node2W2.getPath() + "/" + node1.getName();
    // get lock target node in destination wsp through other session
    Node lockTarget = (Node) rwSessionW2.getItem(node2W2.getPath());
    // add mixin "lockable" to be able to lock the node
    ensureMixinType(lockTarget, mixLockable);
    lockTarget.getParent().save();
    // lock dst parent node using other session
    lockTarget.lock(true, true);
    try {
        workspaceW2.copy(workspace.getName(), node1.getPath(), dstAbsPath);
        fail("LockException was expected.");
    } catch (LockException e) {
    // successful
    } finally {
        lockTarget.unlock();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node)

Aggregations

LockException (javax.jcr.lock.LockException)61 Node (javax.jcr.Node)33 Session (javax.jcr.Session)24 Lock (javax.jcr.lock.Lock)13 RepositoryException (javax.jcr.RepositoryException)11 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 NodeImpl (org.apache.jackrabbit.core.NodeImpl)7 LockManager (javax.jcr.lock.LockManager)6 NodeId (org.apache.jackrabbit.core.id.NodeId)6 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 PathMap (org.apache.jackrabbit.spi.commons.name.PathMap)5 RetentionManager (javax.jcr.retention.RetentionManager)4 SessionImpl (org.apache.jackrabbit.core.SessionImpl)4 Value (javax.jcr.Value)3 Path (org.apache.jackrabbit.spi.Path)3 IOException (java.io.IOException)2 InvalidItemStateException (javax.jcr.InvalidItemStateException)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 Property (javax.jcr.Property)2 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)2