Search in sources :

Example 56 with LockException

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

the class HoldTest method testAddHoldOnLockedNode.

public void testAddHoldOnLockedNode() throws NotExecutableException, RepositoryException {
    Node child = getLockedChildNode();
    // remember current holds for clean up.
    List<Hold> holdsBefore = Arrays.asList(retentionMgr.getHolds(child.getPath()));
    // get another session.
    javax.jcr.Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        rmgr.addHold(child.getPath(), getHoldName(), false);
        otherS.save();
        fail("Adding hold on a locked node must throw LockException.");
    } catch (LockException e) {
    // success
    } finally {
        otherS.logout();
        // clear holds (in case of test failure)
        List<Hold> holds = new ArrayList<Hold>(Arrays.asList(retentionMgr.getHolds(child.getPath())));
        if (holds.removeAll(holdsBefore)) {
            for (Iterator<Hold> it = holds.iterator(); it.hasNext(); ) {
                retentionMgr.removeHold(child.getPath(), (Hold) it.next());
            }
        }
        superuser.save();
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) Hold(javax.jcr.retention.Hold)

Example 57 with LockException

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

the class RetentionPolicyTest method testRemoveRetentionPolicyOnLockedNode.

public void testRemoveRetentionPolicyOnLockedNode() throws NotExecutableException, RepositoryException {
    String childPath = getLockedChildNode().getPath();
    retentionMgr.setRetentionPolicy(childPath, getApplicableRetentionPolicy());
    testRootNode.getSession().save();
    Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        rmgr.removeRetentionPolicy(childPath);
        fail("Removing a retention policy on a locked node must throw LockException.");
    } catch (LockException e) {
    // success
    } finally {
        otherS.logout();
        // clear  retention policy added before
        try {
            retentionMgr.removeRetentionPolicy(childPath);
            superuser.save();
        } catch (RepositoryException e) {
        // should not get here if test is correctly executed.
        }
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) LockException(javax.jcr.lock.LockException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 58 with LockException

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

the class HoldTest method testRemoveHoldOnLockedNode.

public void testRemoveHoldOnLockedNode() throws NotExecutableException, RepositoryException {
    Node child = getLockedChildNode();
    Hold h = retentionMgr.addHold(child.getPath(), getHoldName(), false);
    testRootNode.getSession().save();
    javax.jcr.Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        Hold[] holds = rmgr.getHolds(child.getPath());
        if (holds.length > 0) {
            rmgr.removeHold(child.getPath(), holds[0]);
            otherS.save();
            fail("Removing a hold on a locked node must throw LockException.");
        }
    } catch (LockException e) {
    // success
    } finally {
        otherS.logout();
        // clear hold added before
        try {
            retentionMgr.removeHold(child.getPath(), h);
            superuser.save();
        } catch (RepositoryException e) {
        // should not get here if test is correctly executed.
        }
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Hold(javax.jcr.retention.Hold)

Example 59 with LockException

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

the class MergeNodeTest method disable_testMergeLockedJcr2.

/**
     * Tests if a {@link LockException} is thrown when merge is called on a
     * locked node.
     * @throws NotExecutableException if repository does not support locking.
     */
public void disable_testMergeLockedJcr2() throws NotExecutableException, RepositoryException {
    if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
        throw new NotExecutableException("Locking is not supported.");
    }
    // try to make nodeToMerge lockable if it is not
    ensureMixinType(nodeToMerge, mixLockable);
    nodeToMerge.getParent().getSession().save();
    // lock the node
    // remove first slash of path to get rel path to root
    String pathRelToRoot = nodeToMerge.getPath().substring(1);
    // access node through another session to lock it
    Session session2 = getHelper().getSuperuserSession();
    try {
        Node node2 = session2.getRootNode().getNode(pathRelToRoot);
        node2.getSession().getWorkspace().getLockManager().lock(node2.getPath(), false, false, 60, "");
        try {
            nodeToMerge.getSession().getWorkspace().getVersionManager().merge(nodeToMerge.getPath(), workspace.getName(), false);
            fail("merge must throw a LockException if applied on a " + "locked node");
        } catch (LockException e) {
        // success
        }
        node2.getSession().getWorkspace().getLockManager().unlock(node2.getPath());
    } 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 60 with LockException

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

the class DeepLockTest method testRemoveLockedChild.

public void testRemoveLockedChild() throws RepositoryException {
    Session otherSession = getHelper().getReadWriteSession();
    try {
        Node child = (Node) otherSession.getItem(childNode.getPath());
        child.remove();
        otherSession.save();
        fail("A node below a deeply locked node cannot be removed by another Session.");
    } catch (LockException e) {
    // success
    } finally {
        otherSession.logout();
    }
}
Also used : LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) Session(javax.jcr.Session)

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