use of javax.jcr.version.Version in project jackrabbit by apache.
the class RestoreTest method testRestoreChild1Jcr2_3.
public void testRestoreChild1Jcr2_3() throws RepositoryException {
versionableNode.addNode("child1");
versionableNode.getSession().save();
Version v1 = versionManager.checkin(versionableNode.getPath());
versionManager.checkout(versionableNode.getPath());
Version v2 = versionManager.checkin(versionableNode.getPath());
versionManager.restore(versionableNode.getPath(), v1.getName(), true);
assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1"));
versionManager.restore(versionableNode.getPath(), version.getName(), true);
assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1"));
try {
versionManager.restore(versionableNode.getPath(), v2.getName(), true);
} catch (RepositoryException e) {
fail("Node.restore('1.3') must fail.");
}
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class RestoreTest method testRestoreInvalidVersionJcr2.
/**
* VersionException expected on Node.restore(Version, boolean) if the
* specified version is not part of this node's version history.
*
* @throws RepositoryException
*/
public void testRestoreInvalidVersionJcr2() throws RepositoryException {
Version vNode2 = versionManager.checkin(versionableNode2.getPath());
try {
versionManager.restore(versionableNode.getPath(), vNode2, true);
fail("VersionException expected on Node.restore(Version, boolean) if the specified version is not part of this node's version history.");
} catch (VersionException e) {
// ok
}
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class VersioningTest method testVersionGraph.
/**
* Tests that the version tree documented in
* AbstractVersionManager.calculateCheckinVersionName() can be
* constructed and has the expected version names.
* <p>
* Note that this test case needs to be modified if the version naming
* algorithm ever gets changed.
*/
public void testVersionGraph() throws Exception {
Version vR = n1.getBaseVersion();
Version v10 = n1.checkin();
n1.checkout();
Version v11 = n1.checkin();
n1.checkout();
Version v12 = n1.checkin();
n1.checkout();
Version v13 = n1.checkin();
n1.checkout();
Version v14 = n1.checkin();
n1.checkout();
Version v15 = n1.checkin();
n1.checkout();
Version v16 = n1.checkin();
n1.restore(v12, true);
n1.checkout();
Version v120 = n1.checkin();
n1.checkout();
Version v121 = n1.checkin();
n1.checkout();
Version v122 = n1.checkin();
n1.restore(v12, true);
n1.checkout();
Version v1200 = n1.checkin();
n1.restore(v121, true);
n1.checkout();
Version v1210 = n1.checkin();
n1.checkout();
Version v1211 = n1.checkin();
// x.0 versions can be created if the newly created versionable
// node is cloned to another workspace before the first checkin
Version v20 = n2.checkin();
// Multiple branches can be merged using multiple workspaces
n2.restore(v122, true);
n1.restore(v16, true);
n1.checkout();
n1.merge(n2.getSession().getWorkspace().getName(), true);
n1.doneMerge(v122);
Version v17 = n1.checkin();
assertEquals("jcr:rootVersion", vR.getName());
assertPredecessors("", vR);
assertSuccessors("1.0 2.0", vR);
assertEquals("1.0", v10.getName());
assertPredecessors("jcr:rootVersion", v10);
assertSuccessors("1.1", v10);
assertEquals("1.1", v11.getName());
assertPredecessors("1.0", v11);
assertSuccessors("1.2", v11);
assertEquals("1.2", v12.getName());
assertPredecessors("1.1", v12);
assertSuccessors("1.3 1.2.0 1.2.0.0", v12);
assertEquals("1.3", v13.getName());
assertPredecessors("1.2", v13);
assertSuccessors("1.4", v13);
assertEquals("1.4", v14.getName());
assertPredecessors("1.3", v14);
assertSuccessors("1.5", v14);
assertEquals("1.5", v15.getName());
assertPredecessors("1.4", v15);
assertSuccessors("1.6", v15);
assertEquals("1.6", v16.getName());
assertPredecessors("1.5", v16);
assertSuccessors("1.7", v16);
assertEquals("1.7", v17.getName());
assertPredecessors("1.6 1.2.2", v17);
assertSuccessors("", v17);
assertEquals("1.2.0", v120.getName());
assertPredecessors("1.2", v120);
assertSuccessors("1.2.1", v120);
assertEquals("1.2.1", v121.getName());
assertPredecessors("1.2.0", v121);
assertSuccessors("1.2.2 1.2.1.0", v121);
assertEquals("1.2.2", v122.getName());
assertPredecessors("1.2.1", v122);
assertSuccessors("1.7", v122);
assertEquals("1.2.0.0", v1200.getName());
assertPredecessors("1.2", v1200);
assertSuccessors("", v1200);
assertEquals("1.2.1.0", v1210.getName());
assertPredecessors("1.2.1", v1210);
assertSuccessors("1.2.1.1", v1210);
assertEquals("1.2.1.1", v1211.getName());
assertPredecessors("1.2.1.0", v1211);
assertSuccessors("", v1211);
assertEquals("2.0", v20.getName());
assertPredecessors("jcr:rootVersion", v20);
assertSuccessors("", v20);
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class VersioningTest method assertSuccessors.
private void assertSuccessors(String expected, Version version) throws Exception {
Set successors = new HashSet();
if (expected.length() > 0) {
successors.addAll(Arrays.asList(expected.split(" ")));
}
Version[] versions = version.getSuccessors();
for (int i = 0; i < versions.length; i++) {
if (!successors.remove(versions[i].getName())) {
fail("Version " + version.getName() + " has an unexpected successor " + versions[i].getName());
}
}
if (!successors.isEmpty()) {
fail("Version " + version.getName() + " does not have all expected successors");
}
}
use of javax.jcr.version.Version in project jackrabbit by apache.
the class CopyFrozenUuidTest method testCopyFrozenUuidProperty.
public void testCopyFrozenUuidProperty() throws Exception {
Node firstNode = testRootNode.addNode(nodeName1);
firstNode.setPrimaryType(JcrConstants.NT_UNSTRUCTURED);
firstNode.addMixin(JcrConstants.MIX_VERSIONABLE);
firstNode.getSession().save();
// create version for the node
Version firstNodeVersion = firstNode.checkin();
firstNode.checkout();
Node secondNode = testRootNode.addNode(nodeName2);
secondNode.setPrimaryType(JcrConstants.NT_UNSTRUCTURED);
secondNode.addMixin(JcrConstants.MIX_VERSIONABLE);
Property firstNodeVersionFrozenUuid = firstNodeVersion.getFrozenNode().getProperty(JcrConstants.JCR_FROZENUUID);
secondNode.setProperty(JcrConstants.JCR_FROZENUUID, firstNodeVersionFrozenUuid.getValue());
secondNode.getSession().save();
// create version of the second node
Version secondNodeVersion = secondNode.checkin();
secondNode.checkout();
// frozenUuid from the second node version node should not be the same as the one from the first node version
Property secondBodeVersionFrozenUuid = secondNodeVersion.getFrozenNode().getProperty(JcrConstants.JCR_FROZENUUID);
assertFalse(JcrConstants.JCR_FROZENUUID + " should not be the same for two different versions of different nodes! ", secondBodeVersionFrozenUuid.getValue().equals(firstNodeVersionFrozenUuid.getValue()));
}
Aggregations