use of javax.jcr.version.Version in project jackrabbit by apache.
the class WorkspaceRestoreTest method testWorkspaceRestoreWithRemoveExistingJcr2.
/**
* Test if the removeExisting-flag removes an existing node in case of uuid conflict.
*/
public void testWorkspaceRestoreWithRemoveExistingJcr2() throws NotExecutableException, RepositoryException {
// create version for parentNode of childNode
superuser.getWorkspace().clone(workspaceName, wVersionableChildNode.getPath(), wVersionableChildNode.getPath(), false);
Version parentV = versionableNode.getSession().getWorkspace().getVersionManager().checkin(versionableNode.getPath());
// move child node in order to produce the uuid conflict
String newChildPath = wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName();
wSuperuser.move(wVersionableChildNode.getPath(), newChildPath);
wSuperuser.save();
// restore the parent with removeExisting == true >> moved child node
// must be removed.
wSuperuser.getWorkspace().getVersionManager().restore(new Version[] { parentV }, true);
if (wSuperuser.itemExists(newChildPath)) {
fail("Workspace.restore(Version[], boolean) with the boolean flag set to true, must remove the existing node in case of Uuid conflict.");
}
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class WorkspaceRestoreTest method testWorkspaceRestoreWithUUIDConflict.
/**
* Tests if restoring the <code>Version</code> of an existing node throws an
* <code>ItemExistsException</code> if removeExisting is set to FALSE.
*/
@SuppressWarnings("deprecation")
public void testWorkspaceRestoreWithUUIDConflict() throws RepositoryException, NotExecutableException {
try {
// Verify that nodes used for the test are indeed versionable
NodeDefinition nd = wVersionableNode.getDefinition();
if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
throw new NotExecutableException("Nodes must be versionable in order to run this test.");
}
Version v = wVersionableNode.checkin();
wVersionableNode.checkout();
wSuperuser.move(wVersionableChildNode.getPath(), wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName());
wSuperuser.save();
wSuperuser.getWorkspace().restore(new Version[] { v }, false);
fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false.");
} catch (ItemExistsException e) {
// success
}
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class WorkspaceRestoreTest method testWorkspaceRestoreWithPendingChanges.
/**
* Test if InvalidItemStateException is thrown if the session affected by
* Workspace.restore(Version[], boolean) has pending changes.
*/
@SuppressWarnings("deprecation")
public void testWorkspaceRestoreWithPendingChanges() throws RepositoryException {
versionableNode.checkout();
try {
// modify node without calling save()
versionableNode.setProperty(propertyName1, propertyValue);
// create version in second workspace
Version v = wVersionableNode.checkin();
// try to restore that version
superuser.getWorkspace().restore(new Version[] { v }, false);
fail("InvalidItemStateException must be thrown on attempt to call Workspace.restore(Version[], boolean) in a session having any unsaved changes pending.");
} catch (InvalidItemStateException e) {
// success
}
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class RestoreTest method testRestoreOrderJcr2_4.
/**
* Test the child ordering of restored nodes.
* @throws RepositoryException
*/
public void testRestoreOrderJcr2_4() throws RepositoryException, NotExecutableException {
// create a test-root that has orderable child nodes
Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured");
ensureMixinType(testRoot, mixVersionable);
versionableNode.getSession().save();
// create children of vNode and checkin
Node child1 = testRoot.addNode(nodeName1);
ensureMixinType(child1, mixVersionable);
Node child2 = testRoot.addNode(nodeName2);
ensureMixinType(child2, mixVersionable);
testRoot.getSession().save();
versionManager.checkin(child1.getPath());
versionManager.checkin(child2.getPath());
Version v1 = versionManager.checkin(testRoot.getPath());
// remove node 1
versionManager.checkout(testRoot.getPath());
child1.remove();
testRoot.getSession().save();
versionManager.checkout(testRoot.getPath());
// restore version 1.0
versionManager.restore(new Version[] { v1 }, true);
// check order
NodeIterator iter = testRoot.getNodes();
assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
Node n1 = iter.nextNode();
assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
Node n2 = iter.nextNode();
String orderOk = nodeName1 + ", " + nodeName2;
String order = n1.getName() + ", " + n2.getName();
assertEquals("Invalid child node ordering", orderOk, order);
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class RestoreTest method testRestoreOrderJcr2_2.
/**
* Test the child ordering of restored nodes.
* @throws RepositoryException
*/
public void testRestoreOrderJcr2_2() throws RepositoryException, NotExecutableException {
// create a test-root that has orderable child nodes
Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured");
ensureMixinType(testRoot, mixVersionable);
versionableNode.getSession().save();
// create children of vNode and checkin
Node child1 = testRoot.addNode(nodeName1);
ensureMixinType(child1, mixVersionable);
Node child2 = testRoot.addNode(nodeName2);
ensureMixinType(child2, mixVersionable);
testRoot.getSession().save();
versionManager.checkin(child1.getPath());
versionManager.checkin(child2.getPath());
Version v1 = versionManager.checkin(testRoot.getPath());
// remove node 1
versionManager.checkout(testRoot.getPath());
child1.remove();
testRoot.getSession().save();
versionManager.checkout(testRoot.getPath());
// restore version 1.0
versionManager.restore(v1, true);
// check order
NodeIterator iter = testRoot.getNodes();
assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
Node n1 = iter.nextNode();
assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
Node n2 = iter.nextNode();
String orderOk = nodeName1 + ", " + nodeName2;
String order = n1.getName() + ", " + n2.getName();
assertEquals("Invalid child node ordering", orderOk, order);
}
Aggregations