Search in sources :

Example 6 with VersionManager

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

the class OnParentVersionComputeTest method testRestorePropJcr2.

/**
     * Test the restore of a OnParentVersion-COMPUTE property
     *
     * @throws javax.jcr.RepositoryException
     */
public void testRestorePropJcr2() throws RepositoryException {
    Node propParent = p.getParent();
    VersionManager versionManager = propParent.getSession().getWorkspace().getVersionManager();
    String path = propParent.getPath();
    versionManager.checkout(path);
    Version v = versionManager.checkin(path);
    versionManager.checkout(path);
    p.setValue(newPropValue);
    p.getSession().save();
    versionManager.restore(v, false);
    assertEquals("On restore of a OnParentVersion-COMPUTE property P, the current P in the workspace will be left unchanged.", p.getString(), newPropValue);
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager)

Example 7 with VersionManager

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

the class MergeSubNodeTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    nodeToMerge = testRootNodeW2.getNode(nodeName1);
    // node has to be checked out while merging
    VersionManager versionManager = nodeToMerge.getSession().getWorkspace().getVersionManager();
    versionManager.checkout(nodeToMerge.getPath());
}
Also used : VersionManager(javax.jcr.version.VersionManager)

Example 8 with VersionManager

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

the class VersionLabelTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    jcrVersionLabels = superuser.getNamespacePrefix(NS_JCR_URI) + ":versionLabels";
    vHistory = versionableNode.getSession().getWorkspace().getVersionManager().getVersionHistory(versionableNode.getPath());
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    vMgr.checkpoint(versionableNode.getPath());
    version = vMgr.getBaseVersion(versionableNode.getPath());
    if (vHistory.hasVersionLabel(versionLabel)) {
        fail("Version label '" + versionLabel + "' is already present in this version history. Label test cannot be performed.");
    }
    if (vHistory.hasVersionLabel(versionLabel2)) {
        fail("Version label '" + versionLabel2 + "' is already present in this version history. Label test cannot be performed.");
    }
}
Also used : VersionManager(javax.jcr.version.VersionManager)

Example 9 with VersionManager

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

the class RestoreNodeWithSNSTest method testRestoreWithSNS.

public void testRestoreWithSNS() throws Exception {
    int childCount = 5;
    // create a test node with /childCount/ children with the same name
    Node n = testRootNode.addNode(nodeName1);
    n.addMixin(mixVersionable);
    for (int i = 0; i < childCount; i++) {
        Node child = n.addNode(nodeName2);
        child.setProperty("name", nodeName2 + i);
    }
    testRootNode.getSession().save();
    // check the number of children
    assertEquals(childCount, n.getNodes().getSize());
    VersionManager vm = testRootNode.getSession().getWorkspace().getVersionManager();
    vm.checkin(n.getPath());
    // modify one child
    vm.checkout(n.getPath());
    n.getNode(nodeName2).setProperty("name", "modified");
    testRootNode.getSession().save();
    // check the number of children again
    assertEquals(childCount, n.getNodes().getSize());
    // restore base versiob
    Version baseVersion = vm.getBaseVersion(n.getPath());
    vm.restore(baseVersion, true);
    n.getSession().refresh(false);
    // check the number of children again
    assertEquals(childCount, n.getNodes().getSize());
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager)

Example 10 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)

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