Search in sources :

Example 51 with RepositoryException

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

the class HoldEffectTest method assertEffect.

private void assertEffect(Node targetNode, String childName, String propName, String childName2, String propName2) throws RepositoryException {
    Session s = targetNode.getSession();
    try {
        Node child = targetNode.getNode(childName);
        child.remove();
        s.save();
        fail("Hold present must prevent a child node from being removed.");
    } catch (RepositoryException e) {
        // success
        s.refresh(false);
    }
    try {
        Property p = targetNode.getProperty(propName);
        p.remove();
        s.save();
        fail("Hold present must prevent a child property from being removed.");
    } catch (RepositoryException e) {
        // success
        s.refresh(false);
    }
    try {
        Property p = targetNode.getProperty(propName);
        p.setValue("test2");
        s.save();
        fail("Hold present must prevent the child property from being modified.");
    } catch (RepositoryException e) {
        // success
        s.refresh(false);
    }
    try {
        targetNode.addNode(childName2);
        s.save();
        fail("Hold present must prevent the target node from having new nodes added.");
    } catch (RepositoryException e) {
        // success
        s.refresh(false);
    }
    try {
        Value v = getJcrValue(s, RepositoryStub.PROP_PROP_VALUE2, RepositoryStub.PROP_PROP_TYPE2, "test");
        targetNode.setProperty(propName2, v);
        s.save();
        fail("Hold present must prevent the target node from having new properties set.");
    } catch (RepositoryException e) {
        // success
        s.refresh(false);
    }
    NodeType[] mixins = targetNode.getMixinNodeTypes();
    if (mixins.length > 0) {
        try {
            targetNode.removeMixin(mixins[0].getName());
            s.save();
            fail("Hold present must prevent the target node from having it's mixin types changed.");
        } catch (RepositoryException e) {
            // success
            s.refresh(false);
        }
    }
    try {
        targetNode.remove();
        s.save();
        fail("Hold present must prevent the target node from being removed.");
    } catch (RepositoryException e) {
        // success
        s.refresh(false);
    }
}
Also used : Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property) Session(javax.jcr.Session)

Example 52 with RepositoryException

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

the class HoldTest method testInvalidPath.

public void testInvalidPath() throws RepositoryException, NotExecutableException {
    // not an absolute path.
    String invalidPath = testPath;
    try {
        retentionMgr.getHolds(invalidPath);
        fail("Accessing holds an invalid path must throw RepositoryException.");
    } catch (RepositoryException e) {
    // success
    }
    try {
        retentionMgr.addHold(invalidPath, getHoldName(), true);
        fail("Adding a hold at an invalid path must throw RepositoryException.");
    } catch (RepositoryException e) {
    // success
    }
    try {
        Hold h = retentionMgr.addHold(testNodePath, getHoldName(), true);
        retentionMgr.removeHold(invalidPath, h);
        fail("Removing a hold at an invalid path must throw RepositoryException.");
    } catch (RepositoryException e) {
    // success
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) Hold(javax.jcr.retention.Hold)

Example 53 with RepositoryException

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

the class HoldTest method testRemoveHoldFromChild.

public void testRemoveHoldFromChild() throws RepositoryException, NotExecutableException {
    String childPath = testRootNode.addNode(nodeName2, testNodeType).getPath();
    Hold hold = retentionMgr.addHold(testNodePath, getHoldName(), false);
    try {
        retentionMgr.removeHold(childPath, hold);
        fail("Removing hold from another node must fail");
    } catch (RepositoryException e) {
        // success
        assertTrue(containsHold(retentionMgr.getHolds(testNodePath), hold));
    }
    // check again with persisted hold
    superuser.save();
    try {
        retentionMgr.removeHold(childPath, hold);
        fail("Removing hold from another node must fail");
    } catch (RepositoryException e) {
        // success
        assertTrue(containsHold(retentionMgr.getHolds(testNodePath), hold));
    } finally {
        // clear the hold that was permanently added before.
        retentionMgr.removeHold(testNodePath, hold);
        superuser.save();
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) Hold(javax.jcr.retention.Hold)

Example 54 with RepositoryException

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

the class SelectorTest method testSelector.

public void testSelector() throws RepositoryException {
    // make sure there's at least one node with this node type
    testRootNode.addNode(nodeName1, testNodeType);
    superuser.save();
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), null, null, null);
    forQOMandSQL2(qom, new Callable() {

        public Object call(Query query) throws RepositoryException {
            QueryResult result = query.execute();
            String[] names = result.getSelectorNames();
            assertNotNull(names);
            assertEquals(1, names.length);
            assertEquals("s", names[0]);
            NodeIterator it = result.getNodes();
            while (it.hasNext()) {
                assertTrue("Wrong node type", it.nextNode().isNodeType(testNodeType));
            }
            return null;
        }
    });
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) RepositoryException(javax.jcr.RepositoryException)

Example 55 with RepositoryException

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

the class RestoreTest method testRestoreChild1Jcr2.

public void testRestoreChild1Jcr2() throws RepositoryException {
    versionableNode.addNode("child1");
    versionableNode.getSession().save();
    Version v1 = versionManager.checkin(versionableNode.getPath());
    versionManager.checkout(versionableNode.getPath());
    Version v2 = versionManager.checkin(versionableNode.getPath());
    versionManager.restore(v1, true);
    assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1"));
    versionManager.restore(version, true);
    assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1"));
    try {
        versionManager.restore(v2, true);
    } catch (RepositoryException e) {
        fail("Node.restore('1.3') must fail.");
    }
}
Also used : Version(javax.jcr.version.Version) 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