Search in sources :

Example 26 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit by apache.

the class CheckoutTest method testCheckoutNonVersionableNodeJcr2.

/**
     * Test calling VersionManager.checkout(P) with P denoting the absolute
     * path of a non-versionable node.
     */
public void testCheckoutNonVersionableNodeJcr2() throws RepositoryException {
    VersionManager versionManager = nonVersionableNode.getSession().getWorkspace().getVersionManager();
    String path = nonVersionableNode.getPath();
    try {
        versionManager.checkout(path);
        fail("VersionManager.checkout(P) with P denoting the absolute path of a non-versionable node must throw UnsupportedRepositoryOperationException");
    } catch (UnsupportedRepositoryOperationException e) {
    //success
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) VersionManager(javax.jcr.version.VersionManager)

Example 27 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit by apache.

the class WorkspaceRestoreTest method testWorkspaceRestoreOnCheckedOutNodeJcr2.

/**
     * Test if workspace-restoring a node works on checked-out node.
     */
public void testWorkspaceRestoreOnCheckedOutNodeJcr2() throws RepositoryException {
    VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    if (!versionManager.isCheckedOut(path)) {
        versionManager.checkout(path);
    }
    superuser.getWorkspace().getVersionManager().restore(new Version[] { version }, true);
}
Also used : VersionManager(javax.jcr.version.VersionManager)

Example 28 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit by apache.

the class WorkspaceRestoreTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    version = versionManager.checkin(path);
    versionManager.checkout(path);
    version2 = versionManager.checkin(path);
    versionManager.checkout(path);
    rootVersion = versionManager.getVersionHistory(path).getRootVersion();
    // build a second versionable node below the testroot
    try {
        versionableNode2 = createVersionableNode(testRootNode, nodeName2, versionableNodeType);
    } catch (RepositoryException e) {
        fail("Failed to create a second versionable node: " + e.getMessage());
    }
    try {
        wSuperuser = getHelper().getSuperuserSession(workspaceName);
    } catch (RepositoryException e) {
        fail("Failed to retrieve superuser session for second workspace '" + workspaceName + "': " + e.getMessage());
    }
    // test if the required nodes exist in the second workspace if not try to clone them
    try {
        testRootNode.getCorrespondingNodePath(workspaceName);
    } catch (ItemNotFoundException e) {
        // clone testRoot
        wSuperuser.getWorkspace().clone(superuser.getWorkspace().getName(), testRoot, testRoot, true);
    }
    try {
        versionableNode.getCorrespondingNodePath(workspaceName);
    } catch (ItemNotFoundException e) {
        // clone versionable node
        wSuperuser.getWorkspace().clone(superuser.getWorkspace().getName(), versionableNode.getPath(), versionableNode.getPath(), true);
    }
    try {
        versionableNode2.getCorrespondingNodePath(workspaceName);
    } catch (ItemNotFoundException e) {
        // clone second versionable node
        wSuperuser.getWorkspace().clone(superuser.getWorkspace().getName(), versionableNode2.getPath(), versionableNode2.getPath(), true);
    }
    try {
        // set node-fields (wTestRoot, wVersionableNode, wVersionableNode2)
        // and check versionable nodes out.
        wTestRoot = (Node) wSuperuser.getItem(testRootNode.getPath());
        wVersionableNode = wSuperuser.getNodeByIdentifier(versionableNode.getIdentifier());
        wVersionableNode.getSession().getWorkspace().getVersionManager().checkout(wVersionableNode.getPath());
        wVersionableNode2 = wSuperuser.getNodeByIdentifier(versionableNode2.getIdentifier());
        wVersionableNode2.getSession().getWorkspace().getVersionManager().checkout(wVersionableNode2.getPath());
    } catch (RepositoryException e) {
        fail("Failed to setup test environment in workspace: " + e.toString());
    }
    // that is not present in the default workspace.
    try {
        wVersionableChildNode = createVersionableNode(wVersionableNode, nodeName4, versionableNodeType);
    } catch (RepositoryException e) {
        fail("Failed to create versionable child node in second workspace: " + e.getMessage());
    }
    // create a version of the versionable child node
    VersionManager wVersionManager = wVersionableChildNode.getSession().getWorkspace().getVersionManager();
    String wPath = wVersionableChildNode.getPath();
    wVersionManager.checkout(wPath);
    wChildVersion = wVersionManager.checkin(wPath);
    wVersionManager.checkout(wPath);
}
Also used : RepositoryException(javax.jcr.RepositoryException) VersionManager(javax.jcr.version.VersionManager) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 29 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit by apache.

the class CheckinTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    try {
        VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
        String path = versionableNode.getPath();
        versionManager.checkout(path);
    } catch (RepositoryException e) {
        cleanUp();
        throw e;
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) VersionManager(javax.jcr.version.VersionManager)

Example 30 with VersionManager

use of javax.jcr.version.VersionManager in project jackrabbit by apache.

the class CheckinTest method testIsNotCheckedOutJcr2.

/**
     * Test if VersionManager.isCheckedOut(P) returns false after calling VersionManager.checkin(P).
     *
     * @throws RepositoryException
     */
public void testIsNotCheckedOutJcr2() throws RepositoryException {
    VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
    String path = versionableNode.getPath();
    versionManager.checkin(path);
    boolean isCheckedOut = versionManager.isCheckedOut(path);
    assertFalse("VersionManager.isCheckedOut(P) must return false after VersionManager.checkin(P).", isCheckedOut);
}
Also used : VersionManager(javax.jcr.version.VersionManager)

Aggregations

VersionManager (javax.jcr.version.VersionManager)154 Node (javax.jcr.Node)97 Version (javax.jcr.version.Version)65 VersionHistory (javax.jcr.version.VersionHistory)17 RepositoryException (javax.jcr.RepositoryException)11 Value (javax.jcr.Value)10 Test (org.junit.Test)9 Property (javax.jcr.Property)8 Session (javax.jcr.Session)8 NodeIterator (javax.jcr.NodeIterator)7 VersionException (javax.jcr.version.VersionException)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)4 MergeException (javax.jcr.MergeException)4 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)4 VersionIterator (javax.jcr.version.VersionIterator)4 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)3 InvalidItemStateException (javax.jcr.InvalidItemStateException)2