use of javax.jcr.Session in project jackrabbit by apache.
the class AccessManagerTest method testCanAccessNotExistingWorkspace.
public void testCanAccessNotExistingWorkspace() throws RepositoryException, NotExecutableException {
Session s = getHelper().getReadOnlySession();
try {
List<String> all = Arrays.asList(s.getWorkspace().getAccessibleWorkspaceNames());
String testName = "anyWorkspace";
int i = 0;
while (all.contains(testName)) {
testName = "anyWorkspace" + i;
i++;
}
assertFalse(getAccessManager(s).canAccess(testName));
} catch (NoSuchWorkspaceException e) {
// fine as well.
} finally {
s.logout();
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class AccessManagerTest method testIsGrantedReadOnlySession.
public void testIsGrantedReadOnlySession() throws NotExecutableException, RepositoryException {
Session s = getHelper().getReadOnlySession();
try {
AccessManager acMgr = getAccessManager(s);
Path p = PathFactoryImpl.getInstance().getRootPath();
// existing node-path
assertTrue(acMgr.isGranted(p, Permission.READ));
// not existing property:
assertTrue(acMgr.isGranted(p, NameConstants.JCR_CREATED, Permission.READ));
// existing node-path
assertFalse(acMgr.isGranted(p, Permission.ALL));
// not existing property:
assertFalse(acMgr.isGranted(p, NameConstants.JCR_CREATED, Permission.ALL));
} finally {
s.logout();
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class RemoveOrphanVersionHistoryTest method testRemoveOrphanVersionHistory.
/**
* Test orphan version history cleaning in a single workspace.
* @throws RepositoryException if an error occurs.
*/
public void testRemoveOrphanVersionHistory() throws RepositoryException {
Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixVersionable);
testRootNode.save();
Session session = n.getSession();
VersionHistory vh = n.getVersionHistory();
String vhUuid = vh.getUUID();
assertExists(session, vhUuid);
// First version
Version v10 = n.checkin();
n.checkout();
// Second version
Version v11 = n.checkin();
n.checkout();
// Remove node
n.remove();
testRootNode.save();
assertExists(session, vhUuid);
// Remove the first version
vh.removeVersion(v10.getName());
assertExists(session, vhUuid);
// Remove the second and last version
vh.removeVersion(v11.getName());
try {
session.getNodeByUUID(vhUuid);
fail("Orphan version history must have been removed");
} catch (ItemNotFoundException e) {
// Expected
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class RemoveOrphanVersionHistoryTest method testEmptyNonOrphanVersionHistory.
/**
* Test that an emptied version history that is still being referenced
* from another workspace does not get removed.
*
* @throws RepositoryException if an error occurs.
*/
public void testEmptyNonOrphanVersionHistory() throws RepositoryException {
Session session = testRootNode.getSession();
// Create versionable test node
Node node = testRootNode.addNode(nodeName1);
node.addMixin(mixVersionable);
session.save();
VersionHistory history = node.getVersionHistory();
String uuid = history.getUUID();
// Create version 1.0
Version v10 = node.checkin();
// Remove the test node
node.checkout();
node.remove();
session.save();
Session otherSession = getHelper().getReadWriteSession(workspaceName);
try {
// create a reference to the version history in another workspace
Node otherRoot = otherSession.getRootNode();
Property reference = otherRoot.setProperty("RemoveOrphanVersionTest", uuid, PropertyType.REFERENCE);
otherSession.save();
// Now remove the contents of the version history
history.removeVersion(v10.getName());
// Check that the version history still exists!
try {
session.getNodeByUUID(uuid);
} catch (ItemNotFoundException e) {
fail("Referenced empty version history must note be removed");
}
// Cleanup
reference.remove();
otherSession.save();
} finally {
otherSession.logout();
}
}
use of javax.jcr.Session in project jackrabbit by apache.
the class RemoveOrphanVersionHistoryTest method testWorkspaceRemoveOrphanVersionHistory.
/**
* Test orphan version history cleaning in multiple workspace.
* @throws RepositoryException if an error occurs.
*/
public void testWorkspaceRemoveOrphanVersionHistory() throws RepositoryException {
Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixVersionable);
testRootNode.save();
Session session = n.getSession();
VersionHistory vh = n.getVersionHistory();
String vhUuid = vh.getUUID();
assertExists(session, vhUuid);
// First version
Version v10 = n.checkin();
n.checkout();
Workspace defaultWorkspace = n.getSession().getWorkspace();
Session otherWsSession = n.getSession().getRepository().login(new SimpleCredentials("superuser", "".toCharArray()), workspaceName);
// Clone the node in another workspace
otherWsSession.getWorkspace().clone(defaultWorkspace.getName(), n.getPath(), n.getPath(), false);
Node otherWsRootNode = otherWsSession.getRootNode();
Node clonedNode = otherWsRootNode.getNode(n.getPath().substring(1));
// Ensure that version histories are the same
assertEquals(vhUuid, clonedNode.getVersionHistory().getUUID());
Version v11 = clonedNode.checkin();
clonedNode.checkout();
// Remove node
n.remove();
testRootNode.save();
assertExists(session, vhUuid);
assertExists(otherWsSession, vhUuid);
// Remove the first version
vh.removeVersion(v10.getName());
assertExists(session, vhUuid);
assertExists(otherWsSession, vhUuid);
// Remove cloned node
clonedNode.remove();
otherWsRootNode.save();
assertExists(session, vhUuid);
assertExists(otherWsSession, vhUuid);
// Remove the last version
vh.removeVersion(v11.getName());
try {
session.getNodeByUUID(vhUuid);
fail("Orphan version history must have been removed from the default workspace");
} catch (ItemNotFoundException e) {
// Expected
}
try {
otherWsSession.getNodeByUUID(vhUuid);
fail("Orphan version history must have been removed from the other workspace");
} catch (ItemNotFoundException e) {
// Expected
}
}
Aggregations