use of javax.jcr.retention.RetentionManager in project jackrabbit by apache.
the class HoldTest method testAddHoldOnCheckedInNode.
public void testAddHoldOnCheckedInNode() throws NotExecutableException, RepositoryException {
Node child = getVersionableChildNode();
child.checkout();
child.checkin();
// 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 checked-in node must throw VersionException.");
} catch (VersionException e) {
// success
} finally {
otherS.logout();
// clear holds (in case of test failure)
child.checkout();
Hold[] holds = retentionMgr.getHolds(child.getPath());
for (int i = 0; i < holds.length; i++) {
retentionMgr.removeHold(child.getPath(), holds[i]);
}
superuser.save();
}
}
use of javax.jcr.retention.RetentionManager in project jackrabbit by apache.
the class RetentionPolicyTest method testSetRetentionPolicyOnLockedNode.
public void testSetRetentionPolicyOnLockedNode() throws NotExecutableException, RepositoryException {
String childPath = getLockedChildNode().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 locked node must throw LockException.");
} catch (LockException e) {
// success
} finally {
otherS.logout();
if (retentionMgr.getRetentionPolicy(childPath) != null) {
retentionMgr.removeRetentionPolicy(childPath);
}
superuser.save();
}
}
use of javax.jcr.retention.RetentionManager in project jackrabbit by apache.
the class RetentionPolicyTest method testRemoveRetentionPolicyOnCheckedInNode.
public void testRemoveRetentionPolicyOnCheckedInNode() throws NotExecutableException, RepositoryException {
Node child = getVersionableChildNode();
child.checkout();
retentionMgr.setRetentionPolicy(child.getPath(), getApplicableRetentionPolicy());
superuser.save();
child.checkin();
Session otherS = getHelper().getSuperuserSession();
try {
RetentionManager rmgr = getRetentionManager(otherS);
rmgr.removeRetentionPolicy(child.getPath());
otherS.save();
fail("Removing a retention policy on a checked-in node must throw VersionException.");
} catch (VersionException e) {
// success
} finally {
otherS.logout();
// clear policy added before
child.checkout();
try {
retentionMgr.removeRetentionPolicy(child.getPath());
superuser.save();
} catch (RepositoryException e) {
// should not get here if test is correctly executed.
}
}
}
use of javax.jcr.retention.RetentionManager in project jackrabbit by apache.
the class AbstractJCRTest method cleanUpTestRoot.
/**
* Reverts any pending changes made by <code>s</code> and deletes any nodes
* under {@link #testRoot}. If there is no node at {@link #testRoot} then
* the necessary nodes are created.
*
* @param s the session to clean up.
* @return the {@link javax.jcr.Node} that represents the test root.
* @throws RepositoryException if an error occurs.
*/
protected Node cleanUpTestRoot(Session s) throws RepositoryException {
// do a 'rollback'
s.refresh(false);
Node root = s.getRootNode();
Node testRootNode;
if (root.hasNode(testPath)) {
RetentionManager rm;
try {
rm = s.getRetentionManager();
} catch (UnsupportedRepositoryOperationException e) {
rm = null;
}
// clean test root
testRootNode = root.getNode(testPath);
NodeIterator children = testRootNode.getNodes();
while (children.hasNext()) {
Node child = children.nextNode();
// Remove retention policy if needed
String childPath = child.getPath();
if (rm != null && rm.getRetentionPolicy(childPath) != null) {
rm.removeRetentionPolicy(childPath);
s.save();
}
NodeDefinition nodeDef = child.getDefinition();
if (!nodeDef.isMandatory() && !nodeDef.isProtected()) {
// try to remove child
try {
child.remove();
} catch (ConstraintViolationException e) {
log.println("unable to remove node: " + child.getPath());
}
}
}
} else {
// create nodes to testPath
StringTokenizer names = new StringTokenizer(testPath, "/");
Node currentNode = root;
while (names.hasMoreTokens()) {
String name = names.nextToken();
if (currentNode.hasNode(name)) {
currentNode = currentNode.getNode(name);
} else {
currentNode = currentNode.addNode(name, testNodeTypeTestRoot);
}
}
testRootNode = currentNode;
}
s.save();
return testRootNode;
}
use of javax.jcr.retention.RetentionManager 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();
}
}
Aggregations