Search in sources :

Example 66 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class RemoveMixinTest method testRemoveMixinTakingAffectUponSave.

/**
     * Implementation specific test for 'removeMixin' only taking effect upon
     * save.
     *
     * @throws NotExecutableException
     * @throws RepositoryException
     */
public void testRemoveMixinTakingAffectUponSave() throws NotExecutableException, RepositoryException {
    Node node;
    try {
        node = testRootNode.addNode(nodeName1, testNodeType);
        node.addMixin(mixReferenceable);
        testRootNode.save();
    } catch (RepositoryException e) {
        throw new NotExecutableException();
    }
    node.removeMixin(mixReferenceable);
    assertTrue("Removing Mixin must not take effect but after Node has been saved.", node.isNodeType(mixReferenceable));
    List<NodeType> mixins = Arrays.asList(node.getMixinNodeTypes());
    assertTrue("Removing Mixin must not take effect but after Node has been saved.", mixins.contains(ntMgr.getNodeType(mixReferenceable)));
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) RepositoryException(javax.jcr.RepositoryException)

Example 67 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class MandatoryItemTest method testCreation.

public void testCreation() throws NotExecutableException, RepositoryException {
    Node n;
    try {
        n = testRootNode.addNode(nodeName1, testNodeType);
    } catch (RepositoryException e) {
        throw new NotExecutableException();
    }
    try {
        testRootNode.save();
        fail("Saving without having added the mandatory child items must fail.");
    } catch (ConstraintViolationException e) {
    // success
    }
    if (childNodeDef != null) {
        n.addNode(childNodeDef.getName(), childNodeDef.getDefaultPrimaryType().getName());
    }
    if (childPropDef != null) {
        // TODO: check if definition defines default values
        n.setProperty(childPropDef.getName(), "any value");
    }
    // now save must succeed.
    testRootNode.save();
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException)

Example 68 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class MandatoryItemTest method testRemoval.

public void testRemoval() throws NotExecutableException, RepositoryException {
    Node n;
    Node childN = null;
    Property childP = null;
    try {
        n = testRootNode.addNode(nodeName1, testNodeType);
        if (childNodeDef != null) {
            childN = n.addNode(childNodeDef.getName(), childNodeDef.getDefaultPrimaryType().getName());
        }
        if (childPropDef != null) {
            // TODO: check if definition defines default values
            childP = n.setProperty(childPropDef.getName(), "any value");
        }
        testRootNode.save();
    } catch (RepositoryException e) {
        throw new NotExecutableException();
    }
    // remove the mandatory items ((must succeed))
    if (childN != null) {
        childN.remove();
    }
    if (childP != null) {
        childP.remove();
    }
    // ... however, saving must not be allowed.
    try {
        testRootNode.save();
        fail("removing mandatory child items without re-adding them must fail.");
    } catch (ConstraintViolationException e) {
    // success.
    }
    // re-add the mandatory items
    if (childNodeDef != null) {
        childN = n.addNode(childNodeDef.getName(), childNodeDef.getDefaultPrimaryType().getName());
    }
    if (childPropDef != null) {
        // TODO: check if definition defines default values
        childP = n.setProperty(childPropDef.getName(), "any value");
    }
    // save must succeed now.
    testRootNode.save();
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property)

Example 69 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class DeepLockTest method testDeepLockAboveLockedChild.

public void testDeepLockAboveLockedChild() throws RepositoryException, NotExecutableException {
    try {
        Node parent = lockedNode.getParent();
        if (!parent.isNodeType(mixLockable)) {
            try {
                parent.addMixin(mixLockable);
                parent.save();
            } catch (RepositoryException e) {
                throw new NotExecutableException();
            }
        }
        parent.lock(true, isSessionScoped);
        fail("Creating a deep lock on a parent of a locked node must fail.");
    } catch (LockException e) {
    // expected
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 70 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit-oak by apache.

the class RemoveMembersTest method runTest.

@Override
public void runTest() throws Exception {
    Session s = null;
    try {
        // use system session login to avoid measuring the login-performance here
        s = systemLogin();
        UserManager userManager = ((JackrabbitSession) s).getUserManager();
        String groupPath = groupPaths.get(random.nextInt(GROUP_CNT));
        Group g = (Group) userManager.getAuthorizableByPath(groupPath);
        removeMembers(userManager, g, s);
    } catch (RepositoryException e) {
        if (s.hasPendingChanges()) {
            s.refresh(false);
        }
    } finally {
        if (s != null) {
            s.logout();
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) UserManager(org.apache.jackrabbit.api.security.user.UserManager) RepositoryException(javax.jcr.RepositoryException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

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