use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class AddMixinTest method testAddMultipleSeparately.
/**
* Implementation specific test adding a new Node with a nodeType, that has
* a mixin-supertype. The mixin must only take effect upon save.
*
* @throws NotExecutableException
* @throws RepositoryException
*/
public void testAddMultipleSeparately() throws NotExecutableException, RepositoryException {
Node node;
try {
node = testRootNode.addNode(nodeName1, testNodeType);
node.addMixin(mixReferenceable);
testRootNode.save();
node.addMixin(mixLockable);
testRootNode.save();
} catch (RepositoryException e) {
throw new NotExecutableException();
}
assertTrue("Adding 2 mixins at once -> both must be present.", node.isNodeType(mixReferenceable) && node.isNodeType(mixLockable));
List<NodeType> mixins = Arrays.asList(node.getMixinNodeTypes());
assertTrue("Adding 2 mixins at once -> both must be present.", mixins.contains(ntMgr.getNodeType(mixReferenceable)) && mixins.contains(ntMgr.getNodeType(mixLockable)));
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class AddMixinTest method testAddMultipleAtOnce.
/**
* Implementation specific test adding a new Node with a nodeType, that has
* a mixin-supertype. The mixin must only take effect upon save.
*
* @throws NotExecutableException
* @throws RepositoryException
*/
public void testAddMultipleAtOnce() throws NotExecutableException, RepositoryException {
Node node;
try {
node = testRootNode.addNode(nodeName1, testNodeType);
node.addMixin(mixReferenceable);
node.addMixin(mixLockable);
testRootNode.save();
} catch (RepositoryException e) {
throw new NotExecutableException();
}
assertTrue("Adding 2 mixins at once -> both must be present.", node.isNodeType(mixReferenceable) && node.isNodeType(mixLockable));
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class OpenScopedLockTest method testUnlockAfterTokenTransfer3.
/**
* Test if a Lock created by one session gets properly invalidated
* if the lock token has been transfered to another session, which
* unlocks the Node.
*/
public void testUnlockAfterTokenTransfer3() throws Exception {
String lockToken = lock.getLockToken();
try {
superuser.removeLockToken(lockToken);
otherSession.addLockToken(lockToken);
// otherSession is now lockHolder -> unlock must succeed.
Node n2 = (Node) otherSession.getItem(lockedNode.getPath());
n2.unlock();
assertFalse("Lock has been release by another session.", lockedNode.holdsLock());
assertFalse("Lock has been release by another session.", lock.isLive());
assertFalse("Lock has been release by another session.", lock.getNode().isLocked());
try {
lockedNode.getLock();
fail("Lock has been release by another session.");
} catch (LockException e) {
// ok
}
} catch (RepositoryException e) {
// only in case of failure:
// move lock token back in order to have lock removed properly
// if test succeeds, moving back tokens is not necessary.
otherSession.removeLockToken(lockToken);
superuser.addLockToken(lockToken);
// and rethrow
throw e;
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class ObservationTest method testJCR_2293.
/**
* Check whether an item with the path of an add node event exists.
* Regression test for JCR-2293.
* @throws RepositoryException
* @throws InterruptedException
*/
public void testJCR_2293() throws RepositoryException, InterruptedException {
final String parentPath = testNode.getPath();
final String folderName = "folder_" + System.currentTimeMillis();
final Session session = getHelper().getReadWriteSession();
final Session session2 = getHelper().getReadOnlySession();
// Don't remove. See JCR-2293.
session2.getItem(parentPath);
WaitableEventListener eventListener = new WaitableEventListener() {
private RepositoryException failure;
private boolean done;
public synchronized void onEvent(final EventIterator events) {
try {
while (events.hasNext()) {
Event event = events.nextEvent();
Item item2 = session2.getItem(event.getPath());
assertEquals(parentPath + "/" + folderName, item2.getPath());
}
} catch (RepositoryException e) {
failure = e;
} finally {
done = true;
notifyAll();
}
}
public synchronized void waitForEvent(int timeout) throws InterruptedException, RepositoryException {
if (!done) {
wait(timeout);
}
if (!done) {
fail("Event listener not called");
}
if (failure != null) {
throw failure;
}
}
};
session2.getWorkspace().getObservationManager().addEventListener(eventListener, Event.NODE_ADDED, parentPath, true, null, null, false);
Node parent = (Node) session.getItem(parentPath);
Node toDelete = parent.addNode(folderName, "nt:folder");
parent.save();
try {
eventListener.waitForEvent(60000);
} finally {
toDelete.remove();
parent.save();
assertFalse(parent.hasNode(folderName));
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class QueryTest method testRemappedNamespace.
public void testRemappedNamespace() throws RepositoryException, NotExecutableException {
String namespaceURI = "http://jackrabbit.apache.org/spi/test";
String defaultPrefix = "spiTest";
NamespaceRegistry nsReg = superuser.getWorkspace().getNamespaceRegistry();
try {
nsReg.getPrefix(namespaceURI);
} catch (RepositoryException e) {
nsReg.registerNamespace(defaultPrefix, namespaceURI);
}
Node n = testRootNode.addNode("spiTest:node");
superuser.save();
for (int i = 0; i < 10; i++) {
String prefix = defaultPrefix + i;
superuser.setNamespacePrefix(prefix, namespaceURI);
executeXPathQuery(superuser, testPath + "/" + prefix + ":node", new Node[] { n });
}
}
Aggregations