use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class AbstractLockTest method testUnlockByOtherSession.
/**
* Test {@link LockManager#unlock(String)} for a session that is not
* lock owner.
*
* @throws RepositoryException
* @throws NotExecutableException
*/
public void testUnlockByOtherSession() throws RepositoryException, NotExecutableException {
Session otherSession = getHelper().getReadWriteSession();
try {
getLockManager(otherSession).unlock(lockedNode.getPath());
fail("Another session must not be allowed to unlock.");
} catch (LockException e) {
// success
// make sure the node is still locked and the lock properties are
// still present.
assertTrue(lockMgr.isLocked(lockedNode.getPath()));
assertTrue(lockedNode.hasProperty(jcrlockIsDeep));
assertTrue(lockedNode.hasProperty(jcrLockOwner));
} finally {
otherSession.logout();
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class LockManagerTest method testRemoveLockToken3.
public void testRemoveLockToken3() throws Exception {
assertLockable(testNode);
boolean sessionScoped = false;
Lock l = lockMgr.lock(testPath, true, sessionScoped, Long.MAX_VALUE, null);
String ltoken = l.getLockToken();
try {
lockMgr.removeLockToken(ltoken);
// the locked node.
try {
testNode.addNode(nodeName2, testNodeType);
fail("Session must not be allowed to modify node");
} catch (LockException e) {
// expected
}
} finally {
// make sure lock token is added even if test fail
lockMgr.addLockToken(ltoken);
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class LockTest method testParentChildDeepLock.
/**
* Test parent/child lock
*/
public void testParentChildDeepLock() throws Exception {
// create new nodes
Node n1 = testRootNode.addNode(nodeName1, testNodeType);
ensureMixinType(n1, mixLockable);
Node n2 = n1.addNode(nodeName2, testNodeType);
ensureMixinType(n2, mixLockable);
testRootNode.getSession().save();
// lock child node
n2.lock(false, true);
// assert: unable to deep lock parent node
try {
n1.lock(true, true);
fail("unable to deep lock parent node");
} catch (LockException e) {
// expected
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class MergeNodeTest method disable_testMergeLocked.
/**
* Tests if a {@link LockException} is thrown when merge is called on a
* locked node.
* @throws NotExecutableException if repository does not support locking.
*/
@SuppressWarnings("deprecation")
public void disable_testMergeLocked() 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().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.lock(false, false);
try {
nodeToMerge.merge(workspace.getName(), false);
fail("merge must throw a LockException if applied on a " + "locked node");
} catch (LockException e) {
// success
}
node2.unlock();
} finally {
session2.logout();
}
}
use of javax.jcr.lock.LockException in project jackrabbit-oak by apache.
the class NodeDelegate method unlock.
public void unlock() throws RepositoryException {
String path = getPath();
Root root = sessionDelegate.getContentSession().getLatestRoot();
Tree tree = root.getTree(path);
if (!tree.exists()) {
throw new ItemNotFoundException("Node " + path + " does not exist");
} else if (!isNodeType(tree, MIX_LOCKABLE, root)) {
throw new LockException("Node " + path + " is not lockable");
} else if (!tree.hasProperty(JCR_LOCKISDEEP)) {
throw new LockException("Node " + path + " is not locked");
}
try {
tree.removeProperty(JCR_LOCKISDEEP);
tree.removeProperty(JCR_LOCKOWNER);
sessionDelegate.commit(root);
} catch (CommitFailedException e) {
if (e.isAccessViolation()) {
throw new AccessControlException("Access denied to unlock node " + path, e);
} else {
throw new RepositoryException("Unable to unlock node " + path, e);
}
}
}
Aggregations