Search in sources :

Example 61 with RepositoryException

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)));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) RepositoryException(javax.jcr.RepositoryException)

Example 62 with RepositoryException

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));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 63 with RepositoryException

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;
    }
}
Also used : LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 64 with RepositoryException

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));
    }
}
Also used : Item(javax.jcr.Item) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) RepositoryException(javax.jcr.RepositoryException) EventIterator(javax.jcr.observation.EventIterator) Session(javax.jcr.Session)

Example 65 with RepositoryException

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 });
    }
}
Also used : NamespaceRegistry(javax.jcr.NamespaceRegistry) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Aggregations

RepositoryException (javax.jcr.RepositoryException)1236 Node (javax.jcr.Node)289 Session (javax.jcr.Session)182 IOException (java.io.IOException)156 ArrayList (java.util.ArrayList)106 Name (org.apache.jackrabbit.spi.Name)94 DavException (org.apache.jackrabbit.webdav.DavException)90 Test (org.junit.Test)87 Value (javax.jcr.Value)80 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)76 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)72 Path (org.apache.jackrabbit.spi.Path)67 ItemNotFoundException (javax.jcr.ItemNotFoundException)65 PathNotFoundException (javax.jcr.PathNotFoundException)65 NodeId (org.apache.jackrabbit.core.id.NodeId)64 Property (javax.jcr.Property)61 HashMap (java.util.HashMap)53 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)53 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)52 InvalidItemStateException (javax.jcr.InvalidItemStateException)50