use of javax.jcr.version.VersionHistory in project jackrabbit by apache.
the class BackwardsCompatibilityIT method assertVersionable.
@SuppressWarnings("deprecation")
private Node assertVersionable(Node test) throws RepositoryException {
assertTrue(test.hasNode("versionable"));
Node versionable = test.getNode("versionable");
assertTrue(versionable.isNodeType("nt:myversionable"));
assertTrue(versionable.isNodeType("nt:unstructured"));
assertTrue(versionable.isNodeType("mix:versionable"));
assertFalse(versionable.isCheckedOut());
VersionHistory history = versionable.getVersionHistory();
Version versionB = versionable.getBaseVersion();
String[] labels = history.getVersionLabels(versionB);
assertEquals(1, labels.length);
assertEquals("labelB", labels[0]);
Version versionA = history.getVersionByLabel("labelA");
versionable.restore(versionA, true);
assertEquals("A", versionable.getProperty("foo").getString());
versionable.restore(versionB, true);
assertEquals("B", versionable.getProperty("foo").getString());
return versionable;
}
use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.
the class ReferencesTest method testVersionReferencesVH.
public void testVersionReferencesVH() throws RepositoryException {
Node n = testRootNode.addNode(nodeName1, testNodeType);
n.addMixin(mixVersionable);
superuser.save();
String p = n.getPath();
VersionManager vMgr = superuser.getWorkspace().getVersionManager();
VersionHistory vh = vMgr.getVersionHistory(p);
// check if versionable node has references to root version
assertEquals("Version History", vh.getIdentifier(), n.getProperty(Property.JCR_VERSION_HISTORY).getString());
checkReferences("Version History", vh.getReferences(), p + "/jcr:versionHistory");
}
use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.
the class CopyVersionHistoryTest method assertExistingHistories.
private static void assertExistingHistories(final Session session, final String... names) throws RepositoryException {
for (final String mixin : MIXINS) {
final String pathPrefix = VERSIONABLES_PATH_PREFIX + mixin + "/";
for (final String name : names) {
final String path = pathPrefix + name;
final VersionHistory history = getVersionHistoryForPath(session, path);
assertNotNull("No history found for " + path, history);
VersionCopyTestUtils.assertLabeledVersions(history);
}
}
}
use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.
the class CopyTest method testCopyVersionableNodeCreatesJcrCopiedFrom.
@Test
public void testCopyVersionableNodeCreatesJcrCopiedFrom() throws Exception {
Session session = getAdminSession();
Node toCopy = session.getNode(TEST_PATH + "/source/node");
toCopy.addMixin(JcrConstants.MIX_VERSIONABLE);
session.save();
Version baseV = toCopy.getBaseVersion();
session.getWorkspace().copy(TEST_PATH + "/source/node", TEST_PATH + "/target/copied");
Node copy = testNode.getNode("target/copied");
VersionHistory copiedVh = copy.getVersionHistory();
assertTrue(copiedVh.hasProperty(VersionConstants.JCR_COPIED_FROM));
Property prop = copiedVh.getProperty(VersionConstants.JCR_COPIED_FROM);
assertEquals(PropertyType.WEAKREFERENCE, prop.getType());
Node copiedFrom = prop.getNode();
assertTrue(baseV.isSame(copiedFrom));
}
use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.
the class CopyTest method testCopyVersionableNodeClearsVersions.
@Test
public void testCopyVersionableNodeClearsVersions() throws Exception {
Session session = getAdminSession();
Node toCopy = session.getNode(TEST_PATH + "/source/node");
toCopy.addMixin(JcrConstants.MIX_VERSIONABLE);
session.save();
Version v1 = toCopy.checkin();
toCopy.checkout();
Version v2 = toCopy.checkin();
toCopy.checkout();
session.getWorkspace().copy(TEST_PATH + "/source/node", TEST_PATH + "/target/copied");
Node copy = testNode.getNode("target/copied");
VersionHistory vh = copy.getVersionHistory();
Version rootV = vh.getRootVersion();
assertEquals(0, rootV.getSuccessors().length);
VersionIterator vItr = vh.getAllVersions();
while (vItr.hasNext()) {
if (!rootV.isSame(vItr.nextVersion())) {
fail("Unexpected version in version history of copied node.");
}
}
try {
vh.getVersion(v1.getName());
fail("Unexpected version in version history of copied node.");
} catch (VersionException e) {
// success
}
try {
vh.getVersion(v2.getName());
fail("Unexpected version in version history of copied node.");
} catch (VersionException e) {
// success
}
}
Aggregations