use of javax.jcr.retention.Hold in project jackrabbit by apache.
the class RetentionRegistryImplTest method testAddMultipleHold.
public void testAddMultipleHold() throws RepositoryException, NotExecutableException {
SessionImpl s = (SessionImpl) getHelper().getSuperuserSession();
RetentionRegistry re = s.getRetentionRegistry();
try {
retentionMgr.addHold(childN2.getPath(), getHoldName(), false);
superuser.save();
// hold is not deep -> only applies to childN2
assertTrue(re.hasEffectiveHold(s.getQPath(childN2.getPath()), false));
assertFalse(re.hasEffectiveHold(s.getQPath(childN2.getPath() + "/child"), false));
retentionMgr.addHold(childN2.getPath(), getHoldName(), true);
superuser.save();
// now deep hold must be taken into account
assertTrue(re.hasEffectiveHold(s.getQPath(childN2.getPath()), false));
assertTrue(re.hasEffectiveHold(s.getQPath(childN2.getPath() + "/child"), false));
} finally {
s.logout();
Hold[] hdls = retentionMgr.getHolds(childN2.getPath());
for (int i = 0; i < hdls.length; i++) {
retentionMgr.removeHold(childN2.getPath(), hdls[i]);
}
superuser.save();
}
}
use of javax.jcr.retention.Hold in project jackrabbit by apache.
the class RetentionRegistryImplTest method testAddHold.
public void testAddHold() throws RepositoryException, NotExecutableException {
SessionImpl s = (SessionImpl) getHelper().getSuperuserSession();
RetentionRegistry re = s.getRetentionRegistry();
Hold h = null;
try {
h = retentionMgr.addHold(childN2.getPath(), getHoldName(), false);
// hold must not be effective yet
assertFalse(re.hasEffectiveHold(s.getQPath(childN2.getPath()), false));
superuser.save();
assertTrue(re.hasEffectiveHold(s.getQPath(childN2.getPath()), false));
} finally {
s.logout();
if (h != null) {
retentionMgr.removeHold(childN2.getPath(), h);
superuser.save();
}
}
}
use of javax.jcr.retention.Hold in project jackrabbit by apache.
the class HoldTest method testAddHoldOnLockedNode.
public void testAddHoldOnLockedNode() throws NotExecutableException, RepositoryException {
Node child = getLockedChildNode();
// remember current holds for clean up.
List<Hold> holdsBefore = Arrays.asList(retentionMgr.getHolds(child.getPath()));
// get another session.
javax.jcr.Session otherS = getHelper().getSuperuserSession();
try {
RetentionManager rmgr = getRetentionManager(otherS);
rmgr.addHold(child.getPath(), getHoldName(), false);
otherS.save();
fail("Adding hold on a locked node must throw LockException.");
} catch (LockException e) {
// success
} finally {
otherS.logout();
// clear holds (in case of test failure)
List<Hold> holds = new ArrayList<Hold>(Arrays.asList(retentionMgr.getHolds(child.getPath())));
if (holds.removeAll(holdsBefore)) {
for (Iterator<Hold> it = holds.iterator(); it.hasNext(); ) {
retentionMgr.removeHold(child.getPath(), (Hold) it.next());
}
}
superuser.save();
}
}
use of javax.jcr.retention.Hold in project jackrabbit by apache.
the class HoldTest method testRemoveHold.
public void testRemoveHold() throws RepositoryException, NotExecutableException {
Hold hold = retentionMgr.addHold(testNodePath, getHoldName(), false);
Hold[] holds = retentionMgr.getHolds(testNodePath);
retentionMgr.removeHold(testNodePath, hold);
Hold[] holds2 = retentionMgr.getHolds(testNodePath);
assertEquals("RetentionManager.removeHold should removed the hold added before.", holds.length - 1, holds2.length);
assertFalse("RetentionManager.removeHold should removed the hold added before.", containsHold(holds2, hold));
}
use of javax.jcr.retention.Hold 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.
}
}
}
Aggregations