use of javax.jcr.version.VersionManager in project jackrabbit-oak by apache.
the class RepositorySidegradeTest method verifyVersionHistory.
@Test
public void verifyVersionHistory() throws RepositoryException {
Session session = createAdminSession();
try {
assertTrue(session.nodeExists("/versionable"));
Node versionable = session.getNode("/versionable");
assertTrue(versionable.hasNode("child"));
Node child = versionable.getNode("child");
assertTrue(child.hasNode("child2"));
Node child2 = child.getNode("child2");
assertFalse(versionable.isCheckedOut());
assertTrue(versionable.hasProperty(JCR_UUID));
assertFalse(child.isCheckedOut());
assertTrue(child.hasProperty(JCR_UUID));
assertFalse(child2.isCheckedOut());
assertFalse(child2.hasProperty(JCR_UUID));
VersionManager manager = session.getWorkspace().getVersionManager();
Version version = manager.getBaseVersion("/versionable");
Node frozen = version.getFrozenNode();
assertEquals(versionable.getPrimaryNodeType().getName(), frozen.getProperty(JCR_FROZENPRIMARYTYPE).getString());
assertEquals(versionable.getMixinNodeTypes()[0].getName(), frozen.getProperty(JCR_FROZENMIXINTYPES).getValues()[0].getString());
assertEquals(versionable.getIdentifier(), frozen.getProperty(JCR_FROZENUUID).getString());
Node frozenChild = frozen.getNode("child");
assertEquals(child.getPrimaryNodeType().getName(), frozenChild.getProperty(JCR_FROZENPRIMARYTYPE).getString());
assertFalse(frozenChild.hasProperty(JCR_FROZENMIXINTYPES));
assertEquals("OAK-1789", child.getIdentifier(), frozenChild.getProperty(JCR_FROZENUUID).getString());
Node frozenChild2 = frozenChild.getNode("child2");
assertEquals(child2.getPrimaryNodeType().getName(), frozenChild2.getProperty(JCR_FROZENPRIMARYTYPE).getString());
assertFalse(frozenChild2.hasProperty(JCR_FROZENMIXINTYPES));
assertEquals("OAK-1789", child2.getIdentifier(), frozenChild2.getProperty(JCR_FROZENUUID).getString());
VersionHistory history = manager.getVersionHistory("/versionable");
assertTrue(history.isNodeType("rep:VersionablePaths"));
Property versionablePath = history.getProperty("default");
assertEquals("/versionable", versionablePath.getString());
} finally {
session.logout();
}
}
use of javax.jcr.version.VersionManager in project jackrabbit-oak by apache.
the class RepositoryUpgradeTest method verifyVersionHistory.
@Test
public void verifyVersionHistory() throws RepositoryException {
Session session = createAdminSession();
try {
assertTrue(session.nodeExists("/versionable"));
Node versionable = session.getNode("/versionable");
assertTrue(versionable.hasNode("child"));
Node child = versionable.getNode("child");
assertTrue(child.hasNode("child2"));
Node child2 = child.getNode("child2");
assertFalse(versionable.isCheckedOut());
assertTrue(versionable.hasProperty(JCR_UUID));
assertFalse(child.isCheckedOut());
assertTrue(child.hasProperty(JCR_UUID));
assertFalse(child2.isCheckedOut());
assertFalse(child2.hasProperty(JCR_UUID));
VersionManager manager = session.getWorkspace().getVersionManager();
Version version = manager.getBaseVersion("/versionable");
Node frozen = version.getFrozenNode();
assertEquals(versionable.getPrimaryNodeType().getName(), frozen.getProperty(JCR_FROZENPRIMARYTYPE).getString());
assertEquals(versionable.getMixinNodeTypes()[0].getName(), frozen.getProperty(JCR_FROZENMIXINTYPES).getValues()[0].getString());
assertEquals(versionable.getIdentifier(), frozen.getProperty(JCR_FROZENUUID).getString());
Node frozenChild = frozen.getNode("child");
assertEquals(child.getPrimaryNodeType().getName(), frozenChild.getProperty(JCR_FROZENPRIMARYTYPE).getString());
assertFalse(frozenChild.hasProperty(JCR_FROZENMIXINTYPES));
assertEquals("OAK-1789", child.getIdentifier(), frozenChild.getProperty(JCR_FROZENUUID).getString());
Node frozenChild2 = frozenChild.getNode("child2");
assertEquals(child2.getPrimaryNodeType().getName(), frozenChild2.getProperty(JCR_FROZENPRIMARYTYPE).getString());
assertFalse(frozenChild2.hasProperty(JCR_FROZENMIXINTYPES));
assertEquals("OAK-1789", child2.getIdentifier(), frozenChild2.getProperty(JCR_FROZENUUID).getString());
VersionHistory history = manager.getVersionHistory("/versionable");
assertTrue(history.isNodeType("rep:VersionablePaths"));
Property versionablePath = history.getProperty("default");
assertEquals("/versionable", versionablePath.getString());
} finally {
session.logout();
}
}
use of javax.jcr.version.VersionManager in project jackrabbit-oak by apache.
the class BrokenVersionableTest method verifyNoVersionable.
@Test
public void verifyNoVersionable() throws RepositoryException {
Session session = createAdminSession();
VersionManager vMgr = session.getWorkspace().getVersionManager();
try {
assertFalse(session.getNode("/versionable1").isNodeType(MIX_VERSIONABLE));
Node versionable2 = session.getNode("/versionable2");
assertTrue(versionable2.isNodeType(MIX_VERSIONABLE));
VersionHistory history = vMgr.getVersionHistory(versionable2.getPath());
VersionIterator versions = history.getAllVersions();
assertEquals("jcr:rootVersion", versions.nextVersion().getName());
assertFalse(versions.hasNext());
} finally {
session.logout();
}
}
use of javax.jcr.version.VersionManager in project jackrabbit-oak by apache.
the class CopyVersionHistoryTest method assertVersionsCanBeRestored.
private static void assertVersionsCanBeRestored(final Session session, final String... names) throws RepositoryException {
VersionManager vMgr = session.getWorkspace().getVersionManager();
for (final String mixin : MIXINS) {
final String pathPrefix = VERSIONABLES_PATH_PREFIX + mixin + "/";
for (final String name : names) {
final String path = pathPrefix + name;
VersionHistory history = vMgr.getVersionHistory(path);
assertEquals("1.2", session.getNode(path).getProperty("version").getString());
vMgr.restore(history.getVersion("1.0"), false);
Node versionable = session.getNode(path);
assertEquals("1.0", versionable.getProperty("version").getString());
// restored node should have correct properties
String versionHistoryUuid = versionable.getProperty(JCR_VERSIONHISTORY).getString();
assertEquals(history.getIdentifier(), versionHistoryUuid);
final Version baseVersion = vMgr.getBaseVersion(path);
assertEquals("1.0", baseVersion.getName());
final Value[] predecessors = versionable.getProperty(JCR_PREDECESSORS).getValues();
assertEquals(0, predecessors.length);
assertFalse(vMgr.isCheckedOut(path));
}
}
// after restoring, the paths should be still versionable
assertVersionablePaths(session, names);
}
use of javax.jcr.version.VersionManager in project jackrabbit-oak by apache.
the class VersionCopyTestUtils method createLabeledVersions.
public static String createLabeledVersions(Node node) throws RepositoryException, InterruptedException {
final Session session = node.getSession();
final VersionManager versionManager = session.getWorkspace().getVersionManager();
node.setProperty("version", "root");
session.save();
final String path = node.getPath();
final List<String> versionNames = new ArrayList<String>();
for (final String label : LABELS) {
node.setProperty("version", label);
session.save();
final Version v = versionManager.checkpoint(path);
versionNames.add(v.getName());
}
final VersionHistory history = versionManager.getVersionHistory(path);
for (final String versionName : versionNames) {
history.addVersionLabel(versionName, String.format("version %s", versionName), false);
}
return history.getPath();
}
Aggregations