Search in sources :

Example 6 with RetentionManager

use of javax.jcr.retention.RetentionManager in project jackrabbit by apache.

the class HoldTest method testRemoveHoldOnCheckedInNode.

public void testRemoveHoldOnCheckedInNode() throws NotExecutableException, RepositoryException {
    Node vn = getVersionableChildNode();
    vn.checkout();
    Node n = vn.addNode(nodeName2);
    Hold h = retentionMgr.addHold(n.getPath(), getHoldName(), false);
    superuser.save();
    // checkin on the parent node make the hold-containing node checked-in.
    vn.checkin();
    javax.jcr.Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        Hold[] holds = rmgr.getHolds(n.getPath());
        if (holds.length > 0) {
            rmgr.removeHold(n.getPath(), holds[0]);
            otherS.save();
            fail("Removing a hold on a checked-in node must throw VersionException.");
        }
    } catch (VersionException e) {
    // success
    } finally {
        otherS.logout();
        // clear hold added before
        vn.checkout();
        try {
            retentionMgr.removeHold(n.getPath(), h);
            superuser.save();
        } catch (RepositoryException e) {
        // should not get here if test is correctly executed.
        }
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Hold(javax.jcr.retention.Hold) VersionException(javax.jcr.version.VersionException)

Example 7 with RetentionManager

use of javax.jcr.retention.RetentionManager in project jackrabbit by apache.

the class RetentionPolicyTest method testRemoveRetentionPolicyOnLockedNode.

public void testRemoveRetentionPolicyOnLockedNode() throws NotExecutableException, RepositoryException {
    String childPath = getLockedChildNode().getPath();
    retentionMgr.setRetentionPolicy(childPath, getApplicableRetentionPolicy());
    testRootNode.getSession().save();
    Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        rmgr.removeRetentionPolicy(childPath);
        fail("Removing a retention policy on a locked node must throw LockException.");
    } catch (LockException e) {
    // success
    } finally {
        otherS.logout();
        // clear  retention policy added before
        try {
            retentionMgr.removeRetentionPolicy(childPath);
            superuser.save();
        } catch (RepositoryException e) {
        // should not get here if test is correctly executed.
        }
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) LockException(javax.jcr.lock.LockException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 8 with RetentionManager

use of javax.jcr.retention.RetentionManager in project jackrabbit by apache.

the class RetentionPolicyTest method testSetRetentionPolicyOnCheckedInNode.

public void testSetRetentionPolicyOnCheckedInNode() throws NotExecutableException, RepositoryException {
    Node child = getVersionableChildNode();
    child.checkout();
    child.checkin();
    String childPath = child.getPath();
    // get another session.
    Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        rmgr.setRetentionPolicy(childPath, getApplicableRetentionPolicy());
        otherS.save();
        fail("Setting a retention policy on a checked-in node must throw VersionException.");
    } catch (VersionException e) {
    // success
    } finally {
        otherS.logout();
        // clear policies (in case of test failure)
        try {
            retentionMgr.removeRetentionPolicy(childPath);
            superuser.save();
        } catch (RepositoryException e) {
        // ignore.
        }
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) VersionException(javax.jcr.version.VersionException)

Example 9 with RetentionManager

use of javax.jcr.retention.RetentionManager in project jackrabbit by apache.

the class RetentionPolicyTest method testReadOnlySession.

public void testReadOnlySession() throws NotExecutableException, RepositoryException {
    Session s = getHelper().getReadOnlySession();
    try {
        RetentionManager rmgr = getRetentionManager(s);
        try {
            rmgr.getRetentionPolicy(testNodePath);
            fail("Read-only session doesn't have sufficient privileges to retrieve retention policy.");
        } catch (AccessDeniedException e) {
        // success
        }
        try {
            rmgr.setRetentionPolicy(testNodePath, getApplicableRetentionPolicy());
            fail("Read-only session doesn't have sufficient privileges to retrieve retention policy.");
        } catch (AccessDeniedException e) {
        // success
        }
    } finally {
        s.logout();
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) AccessDeniedException(javax.jcr.AccessDeniedException) Session(javax.jcr.Session)

Example 10 with RetentionManager

use of javax.jcr.retention.RetentionManager in project jackrabbit by apache.

the class HoldTest method testRemoveHoldOnLockedNode.

public void testRemoveHoldOnLockedNode() throws NotExecutableException, RepositoryException {
    Node child = getLockedChildNode();
    Hold h = retentionMgr.addHold(child.getPath(), getHoldName(), false);
    testRootNode.getSession().save();
    javax.jcr.Session otherS = getHelper().getSuperuserSession();
    try {
        RetentionManager rmgr = getRetentionManager(otherS);
        Hold[] holds = rmgr.getHolds(child.getPath());
        if (holds.length > 0) {
            rmgr.removeHold(child.getPath(), holds[0]);
            otherS.save();
            fail("Removing a hold on a locked node must throw LockException.");
        }
    } catch (LockException e) {
    // success
    } finally {
        otherS.logout();
        // clear hold added before
        try {
            retentionMgr.removeHold(child.getPath(), h);
            superuser.save();
        } catch (RepositoryException e) {
        // should not get here if test is correctly executed.
        }
    }
}
Also used : RetentionManager(javax.jcr.retention.RetentionManager) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Hold(javax.jcr.retention.Hold)

Aggregations

RetentionManager (javax.jcr.retention.RetentionManager)11 Node (javax.jcr.Node)7 RepositoryException (javax.jcr.RepositoryException)5 Session (javax.jcr.Session)5 LockException (javax.jcr.lock.LockException)4 Hold (javax.jcr.retention.Hold)4 VersionException (javax.jcr.version.VersionException)4 AccessDeniedException (javax.jcr.AccessDeniedException)2 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 NodeIterator (javax.jcr.NodeIterator)1 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 NodeDefinition (javax.jcr.nodetype.NodeDefinition)1