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();
}
}
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.
}
}
}
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.
}
}
}
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();
}
}
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();
}
}
Aggregations