/** * Tests if <code>VersionHistory.getIdentifier()</code> returns the right UUID */ public void testGetIdentifier() throws Exception { assertEquals("VersionHistory.getIdentifier() did not return the right Id", versionableNode.getProperty(jcrVersionHistory).getString(), vHistory.getIdentifier()); }
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"); }
public void testGetNodeByIdentifier() throws RepositoryException { Node n = testRootNode.addNode(nodeName1, testNodeType); n.addMixin(mixVersionable); superuser.save(); VersionManager vMgr = superuser.getWorkspace().getVersionManager(); String id = vMgr.getVersionHistory(n.getPath()).getIdentifier(); assertTrue("Session.getNodeByIdentifier() did not return VersionHistory object for a nt:versionHistory node.", superuser.getNodeByIdentifier(id) instanceof VersionHistory); }
/** * @since oak */ @Test public void testVersionHistoryGetIdentifier() throws Exception { VersionHistory testVh = testSession.getNode(versionablePath).getVersionHistory(); testVh.getIdentifier(); }
if (keyStr.equals(version.getContainingHistory().getIdentifier())) { JcrVersionNode versionNode = (JcrVersionNode)version; nonExistingVersions.remove(version); if (keyStr.equals(version.getContainingHistory().getIdentifier())) { JcrVersionNode versionNode = (JcrVersionNode)version; existingVersions.remove(version);
if (keyStr.equals(version.getContainingHistory().getIdentifier())) { JcrVersionNode versionNode = (JcrVersionNode)version; nonExistingVersions.remove(version); if (keyStr.equals(version.getContainingHistory().getIdentifier())) { JcrVersionNode versionNode = (JcrVersionNode)version; existingVersions.remove(version);
private static void assertVersionableProperties(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; Node versionable = session.getNode(path); String versionHistoryUuid = versionable.getProperty(JCR_VERSIONHISTORY).getString(); assertEquals(getVersionHistoryForPath(session, path).getIdentifier(), versionHistoryUuid); final Version baseVersion = vMgr.getBaseVersion(path); assertEquals("1.2", baseVersion.getName()); final Value[] predecessors = versionable.getProperty(JCR_PREDECESSORS).getValues(); assertEquals(1, predecessors.length); assertEquals(baseVersion.getIdentifier(), predecessors[0].getString()); } } }
@SuppressWarnings( "deprecation" ) public void testShouldCreateProperVersionHistoryWhenSavingVersionedNode() throws Exception { session = getHelper().getReadWriteSession(); Node node = session.getRootNode().addNode("test", "nt:unstructured"); node.addMixin("mix:versionable"); session.save(); assertThat(node.hasProperty("jcr:isCheckedOut"), is(true)); assertThat(node.getProperty("jcr:isCheckedOut").getBoolean(), is(true)); assertThat(node.hasProperty("jcr:versionHistory"), is(true)); Node history = node.getProperty("jcr:versionHistory").getNode(); assertThat(history, is(notNullValue())); assertThat(node.hasProperty("jcr:baseVersion"), is(true)); Node version = node.getProperty("jcr:baseVersion").getNode(); assertThat(version, is(notNullValue())); assertThat(version.getParent(), is(history)); assertThat(node.hasProperty("jcr:uuid"), is(true)); assertThat(node.getProperty("jcr:uuid").getString(), is(history.getProperty("jcr:versionableUuid").getString())); assertThat(versionHistory(node).getUUID(), is(history.getUUID())); assertThat(versionHistory(node).getIdentifier(), is(history.getIdentifier())); assertThat(versionHistory(node).getPath(), is(history.getPath())); assertThat(baseVersion(node).getUUID(), is(version.getUUID())); assertThat(baseVersion(node).getIdentifier(), is(version.getIdentifier())); assertThat(baseVersion(node).getPath(), is(version.getPath())); }
@FixFor( "MODE-786" ) @Test public void shouldReceiveEventsForChangesToVersionsInSystemContent() throws Exception { int numEvents = 22; SimpleListener listener = addListener(session, numEvents, ALL_EVENTS, "/jcr:system", true, null, null, false); Node node = session.getRootNode().addNode("/test", "nt:unstructured"); node.addMixin("mix:versionable"); session.save(); // SHOULD GENERATE AN EVENT TO CREATE VERSION HISTORY FOR THE NODE // Wait for the events on the session's listeners (that should get the events) ... listener.waitForEvents(); removeListener(listener); Node history = node.getProperty("jcr:versionHistory").getNode(); assertThat(history, is(notNullValue())); assertThat(node.hasProperty("jcr:baseVersion"), is(true)); Node version = node.getProperty("jcr:baseVersion").getNode(); assertThat(version, is(notNullValue())); assertThat(version.getParent(), is(history)); assertThat(node.hasProperty("jcr:uuid"), is(true)); assertThat(node.getProperty("jcr:uuid").getString(), is(history.getProperty("jcr:versionableUuid").getString())); assertThat(versionHistory(node).getIdentifier(), is(history.getIdentifier())); assertThat(versionHistory(node).getPath(), is(history.getPath())); assertThat(baseVersion(node).getIdentifier(), is(version.getIdentifier())); assertThat(baseVersion(node).getPath(), is(version.getPath())); // Verify the expected events were received ... checkResults(listener); }
/** * @since oak */ @Test public void testGetVersionHistoryNode() throws Exception { // accessing the version history must be allowed if the versionable node // is readable to the editing test session. Node testNode = testSession.getNode(versionablePath); String vhPath = vh.getPath(); String vhUUID = vh.getIdentifier(); assertTrue(vh.isSame(testNode.getSession().getNode(vhPath))); assertTrue(vh.isSame(testNode.getSession().getNodeByIdentifier(vhUUID))); assertTrue(vh.isSame(testNode.getSession().getNodeByUUID(vhUUID))); }
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); } }
String id = vh.getIdentifier();
/** * @since oak (DIFF: jr required jcr:versionManagement privilege on the version store) */ @Test public void testAccessVersionHistory() throws Exception { Node n = createVersionableNode(superuser.getNode(path)); allow(n.getPath(), versionPrivileges); Node testNode = testSession.getNode(n.getPath()); testNode.checkin(); testNode.checkout(); // accessing the version history must be allowed if the versionable node // is readable to the editing test session. VersionHistory vh = testNode.getVersionHistory(); String vhPath = vh.getPath(); String vhUUID = vh.getIdentifier(); assertTrue(vh.isSame(testNode.getSession().getNode(vhPath))); assertTrue(vh.isSame(testNode.getSession().getNodeByIdentifier(vhUUID))); assertTrue(vh.isSame(testNode.getSession().getNodeByUUID(vhUUID))); }
String vhUUID = vh.getIdentifier();
/** * @since oak */ @Test public void testAccessVersionHistoryVersionableNodeRemoved() throws Exception { Node n = createVersionableNode(superuser.getNode(path)); allow(n.getPath(), versionPrivileges); n.checkin(); n.checkout(); String versionablePath = n.getPath(); VersionHistory vh = n.getVersionHistory(); String vhPath = vh.getPath(); String vhUUID = vh.getIdentifier(); // remove the versionable node n.remove(); superuser.save(); testSession.refresh(false); assertTrue(testSession.nodeExists(path)); assertFalse(testSession.nodeExists(versionablePath)); // accessing the version history directly should still succeed as // read permission is still granted on the tree defined by the parent. VersionHistory history = (VersionHistory) testSession.getNode(vhPath); history = (VersionHistory) testSession.getNodeByIdentifier(vhUUID); history = (VersionHistory) testSession.getNodeByUUID(vhUUID); // revoking read permission on the parent node -> version history // must no longer be accessible modify(path, Privilege.JCR_READ, false); assertFalse(testSession.nodeExists(vhPath)); }
/** * @since oak */ @Test public void testAccessVersionHistoryVersionableNodeRemoved() throws Exception { superuser.getNode(versionablePath).remove(); superuser.save(); testSession.refresh(false); assertTrue(testSession.nodeExists(path)); assertFalse(testSession.nodeExists(versionablePath)); // accessing the version history directly should still succeed as // read permission is still granted on the tree defined by the parent. VersionHistory history = (VersionHistory) testSession.getNode(vh.getPath()); history = (VersionHistory) testSession.getNodeByIdentifier(vh.getIdentifier()); history = (VersionHistory) testSession.getNodeByUUID(vh.getUUID()); // revoking read permission on the parent node -> version history // must no longer be accessible modify(path, Privilege.JCR_READ, false); assertFalse(testSession.nodeExists(vh.getPath())); } }
/** * @since oak */ @Test public void testAccessVersionHistoryVersionableNodeNotAccessible() throws Exception { // revert read permission on the versionable node modify(versionablePath, Privilege.JCR_READ, false); // versionable node is not readable any more for test session. assertFalse(testSession.nodeExists(versionablePath)); // access version history directly => should fail try { VersionHistory history = (VersionHistory) testSession.getNode(vh.getPath()); fail("Access to version history should be denied if versionable node is not accessible"); } catch (PathNotFoundException e) { // success } try { VersionHistory history = (VersionHistory) testSession.getNodeByIdentifier(vh.getIdentifier()); fail("Access to version history should be denied if versionable node is not accessible"); } catch (ItemNotFoundException e) { // success } try { VersionHistory history = (VersionHistory) testSession.getNodeByUUID(vh.getUUID()); fail("Access to version history should be denied if versionable node is not accessible"); } catch (ItemNotFoundException e) { // success } }