Search in sources :

Example 51 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.

the class ReadVersionContentTest method testGetVersion.

/**
     * @since oak
     */
@Test
public void testGetVersion() 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);
    VersionHistory vh = testNode.getVersionHistory();
    Version version = vh.getVersion(v.getName());
    assertTrue(v.isSame(version));
    assertTrue(vh.isSame(version.getContainingHistory()));
    version = vh.getVersion(v2.getName());
    assertTrue(v2.isSame(version));
    assertTrue(vh.isSame(version.getContainingHistory()));
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Test(org.junit.Test)

Example 52 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.

the class ReadVersionContentTest method testGetAllVersions.

/**
     * @since oak
     */
@Test
public void testGetAllVersions() 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);
    VersionHistory vh = testNode.getVersionHistory();
    VersionIterator versionIterator = vh.getAllVersions();
}
Also used : Node(javax.jcr.Node) VersionIterator(javax.jcr.version.VersionIterator) VersionHistory(javax.jcr.version.VersionHistory) Test(org.junit.Test)

Example 53 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.

the class VersionManagementTest method testAddVersionLabel.

/**
     * @since oak
     */
@Test
public void testAddVersionLabel() throws Exception {
    Node n = createVersionableNode(superuser.getNode(path));
    allow(n.getPath(), versionPrivileges);
    Node testNode = testSession.getNode(n.getPath());
    Version v = testNode.checkin();
    testNode.checkout();
    Version v2 = testNode.checkin();
    testNode.checkout();
    // -> VersionHistory.addVersionLabel must be allowed
    VersionHistory history = testNode.getVersionHistory();
    history.addVersionLabel(v.getName(), "testLabel", false);
    history.addVersionLabel(v2.getName(), "testLabel", true);
    VersionManager vMgr = testSession.getWorkspace().getVersionManager();
    history = vMgr.getVersionHistory(testNode.getPath());
    history.addVersionLabel(v.getName(), "testLabel", true);
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) VersionManager(javax.jcr.version.VersionManager) Test(org.junit.Test)

Example 54 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.

the class VersionManagementTest method testVersionableChildNode2.

/**
     * @since oak
     */
@Test
public void testVersionableChildNode2() throws Exception {
    Node testNode = superuser.getNode(path).addNode("n1").addNode("n2").addNode("n3").addNode("jcr:content");
    testNode.addMixin("mix:versionable");
    superuser.save();
    testNode.remove();
    testNode = superuser.getNode(path).getNode("n1").getNode("n2").getNode("n3").addNode("jcr:content");
    testNode.addMixin("mix:versionable");
    superuser.save();
    assertTrue(testNode.isNodeType("mix:versionable"));
    VersionHistory vh = testNode.getVersionHistory();
    Property versionablePath = vh.getProperty(superuser.getWorkspace().getName());
    assertEquals(testNode.getPath(), versionablePath.getString());
}
Also used : Node(javax.jcr.Node) VersionHistory(javax.jcr.version.VersionHistory) Property(javax.jcr.Property) Test(org.junit.Test)

Example 55 with VersionHistory

use of javax.jcr.version.VersionHistory in project jackrabbit-oak by apache.

the class VersionManagementTest method testAccessVersionHistoryVersionableNodeNotAccessible.

/**
     * @since oak (DIFF: jr required jcr:versionManagement privilege on the version store)
     */
@Test
public void testAccessVersionHistoryVersionableNodeNotAccessible() throws Exception {
    Node n = createVersionableNode(superuser.getNode(path));
    allow(n.getPath(), versionPrivileges);
    Node testNode = testSession.getNode(n.getPath());
    testNode.checkin();
    testNode.checkout();
    VersionHistory vh = testNode.getVersionHistory();
    String vhPath = vh.getPath();
    String vhUUID = vh.getIdentifier();
    // revert read permission on the versionable node
    modify(n.getPath(), Privilege.JCR_READ, false);
    // versionable node is not readable any more for test session.
    assertFalse(testSession.nodeExists(n.getPath()));
    // access version history directly => should fail
    try {
        VersionHistory history = (VersionHistory) testSession.getNode(vhPath);
        fail("Access to version history should be denied if versionable node is not accessible");
    } catch (PathNotFoundException e) {
    // success
    }
    try {
        VersionHistory history = (VersionHistory) testSession.getNodeByIdentifier(vhUUID);
        fail("Access to version history should be denied if versionable node is not accessible");
    } catch (ItemNotFoundException e) {
    // success
    }
    try {
        VersionHistory history = (VersionHistory) testSession.getNodeByUUID(vhUUID);
        fail("Access to version history should be denied if versionable node is not accessible");
    } catch (ItemNotFoundException e) {
    // success
    }
}
Also used : Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) VersionHistory(javax.jcr.version.VersionHistory) ItemNotFoundException(javax.jcr.ItemNotFoundException) Test(org.junit.Test)

Aggregations

VersionHistory (javax.jcr.version.VersionHistory)73 Node (javax.jcr.Node)45 Version (javax.jcr.version.Version)29 Test (org.junit.Test)25 RepositoryException (javax.jcr.RepositoryException)17 VersionManager (javax.jcr.version.VersionManager)17 Session (javax.jcr.Session)12 VersionIterator (javax.jcr.version.VersionIterator)12 Property (javax.jcr.Property)7 DavException (org.apache.jackrabbit.webdav.DavException)7 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)7 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)7 ArrayList (java.util.ArrayList)6 DavResource (org.apache.jackrabbit.webdav.DavResource)6 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 VersionHistoryResource (org.apache.jackrabbit.webdav.version.VersionHistoryResource)4 Workspace (javax.jcr.Workspace)3 VersionException (javax.jcr.version.VersionException)3 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)3 PathNotFoundException (javax.jcr.PathNotFoundException)2