use of javax.jcr.version.Version in project jackrabbit by apache.
the class RestoreTest method testRestoreNameJcr2.
/**
* Test the restore of the OPV=Version child nodes.
* @throws RepositoryException
*/
public void testRestoreNameJcr2() throws RepositoryException, NotExecutableException {
// V1.0 of versionableNode has no child
Node child1 = versionableNode.addNode(nodeName4);
ensureMixinType(child1, mixVersionable);
versionableNode.getSession().save();
// create v1.0 of child
Version v1Child = child1.checkin();
// V1 of versionable node has child1
String v1 = versionManager.checkin(versionableNode.getPath()).getName();
// create V1.1 of child
versionManager.checkout(child1.getPath());
Version v11Child = versionManager.checkin(child1.getPath());
// V2 of versionable node has child1
versionManager.checkout(versionableNode.getPath());
String v2 = versionManager.checkin(versionableNode.getPath()).getName();
// restore 1.0 of versionable node --> no child
versionManager.restore(version, true);
assertFalse("restore must remove child node.", versionableNode.hasNode(nodeName4));
// restore V1 via name. since child was checkin first, 1.0 should be restored
versionManager.restore(versionableNode.getPath(), v1, true);
assertTrue("restore must restore child node.", versionableNode.hasNode(nodeName4));
child1 = versionableNode.getNode(nodeName4);
assertEquals("restore must restore child node version 1.0.", v1Child.getName(), versionManager.getBaseVersion(child1.getPath()).getName());
// restore V2 via name. child should be 1.1
versionManager.restore(versionableNode.getPath(), v2, true);
child1 = versionableNode.getNode(nodeName4);
assertEquals("Node.restore('foo') must restore child node version 1.1.", v11Child.getName(), versionManager.getBaseVersion(child1.getPath()).getName());
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class RestoreTest method testRestoreOrder2Jcr2_3.
/**
* Test the child ordering of restored nodes.
* @throws RepositoryException
*/
public void testRestoreOrder2Jcr2_3() 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());
// reoder nodes
versionManager.checkout(testRoot.getPath());
testRoot.orderBefore(nodeName2, nodeName1);
testRoot.getSession().save();
versionManager.checkin(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);
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class CheckinTest method testMultipleCheckinHasNoEffectJcr2.
/**
* Test if VersionManager.checkin(P) has no effect if the path P resolves
* to a checked-in node.
*
* @throws RepositoryException
*/
public void testMultipleCheckinHasNoEffectJcr2() throws RepositoryException {
VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
String path = versionableNode.getPath();
Version v = versionManager.checkin(path);
try {
Version v2 = versionManager.checkin(path);
assertTrue("Calling VersionManager.checkin(P) must not have an if the path P resolves to a node that is already checked-in.", v.isSame(v2));
} catch (RepositoryException e) {
fail("Calling VersionManager.checkin(P) must not throw an exception if the path P resolves to a node that is already checked-in.");
}
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class RestoreTest method testRestoreWithUUIDConflictJcr2_3.
/**
* Tests if restoring the <code>Version</code> of an existing node throws an
* <code>ItemExistsException</code> if removeExisting is set to FALSE.
*/
public void testRestoreWithUUIDConflictJcr2_3() throws RepositoryException, NotExecutableException {
try {
Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType);
// Verify that nodes used for the test have proper opv behaviour
NodeDefinition nd = naa.getDefinition();
if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict.");
}
Version v = versionManager.checkin(versionableNode.getPath());
versionManager.checkout(versionableNode.getPath());
superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName());
superuser.save();
versionManager.restore(versionableNode.getPath(), v.getName(), 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 RestoreTest method testRestoreOrder.
/**
* Test the child ordering of restored nodes.
* @throws RepositoryException
*/
@SuppressWarnings("deprecation")
public void testRestoreOrder() 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();
child1.checkin();
child2.checkin();
Version v1 = testRoot.checkin();
// remove node 1
testRoot.checkout();
child1.remove();
testRoot.getSession().save();
testRoot.checkin();
// restore version 1.0
testRoot.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