use of javax.jcr.version.Version 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.version.Version 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.version.Version 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
}
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class RemoveVersionLabelTest method testRemoveVersionLabel.
public void testRemoveVersionLabel() throws RepositoryException {
Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixVersionable);
testRootNode.save();
Version v10 = n.checkin();
n.checkout();
n.checkin();
VersionHistory vh = n.getVersionHistory();
vh.addVersionLabel(v10.getName(), "test", true);
// the next call must not fail
vh.removeVersion(v10.getName());
// now the label must be gone
String[] labels = vh.getVersionLabels();
assertEquals("Label of a removed version must be removed as well", 0, labels.length);
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class RestoreNodeWithSNSTest method testRestoreWithSNS.
public void testRestoreWithSNS() throws Exception {
int childCount = 5;
// create a test node with /childCount/ children with the same name
Node n = testRootNode.addNode(nodeName1);
n.addMixin(mixVersionable);
for (int i = 0; i < childCount; i++) {
Node child = n.addNode(nodeName2);
child.setProperty("name", nodeName2 + i);
}
testRootNode.getSession().save();
// check the number of children
assertEquals(childCount, n.getNodes().getSize());
VersionManager vm = testRootNode.getSession().getWorkspace().getVersionManager();
vm.checkin(n.getPath());
// modify one child
vm.checkout(n.getPath());
n.getNode(nodeName2).setProperty("name", "modified");
testRootNode.getSession().save();
// check the number of children again
assertEquals(childCount, n.getNodes().getSize());
// restore base versiob
Version baseVersion = vm.getBaseVersion(n.getPath());
vm.restore(baseVersion, true);
n.getSession().refresh(false);
// check the number of children again
assertEquals(childCount, n.getNodes().getSize());
}
Aggregations