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