Search in sources :

Example 46 with VersionManager

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

the class MergeSubNodeTest method disable_testMergeNodeBestEffortTrueJcr2.

/**
     * VersionManager.merge(): bestEffort is true > (sub)node which could not be merged
     * are not affected.<br>
     */
public void disable_testMergeNodeBestEffortTrueJcr2() throws RepositoryException {
    // create 2 new nodes with two independent versions
    // so merge fails for this node
    Node originalNode = testRootNode.getNode(nodeName1);
    VersionManager originalVersionManager = originalNode.getSession().getWorkspace().getVersionManager();
    String originalPath = originalNode.getPath();
    originalVersionManager.checkout(originalPath);
    Node subNode = originalNode.getNode(nodeName2);
    // will be unchanged after merge
    originalVersionManager.checkout(subNode.getPath());
    subNode.setProperty(propertyName1, CHANGED_STRING);
    // will be updated
    originalNode.setProperty(propertyName1, CHANGED_STRING);
    superuser.save();
    originalVersionManager.checkin(subNode.getPath());
    originalVersionManager.checkin(originalPath);
    VersionManager versionManager = nodeToMerge.getSession().getWorkspace().getVersionManager();
    Node subNodeW2 = nodeToMerge.getNode(nodeName2);
    versionManager.checkout(subNodeW2.getPath());
    subNodeW2.setProperty(propertyName1, CHANGED_STRING);
    superuserW2.save();
    versionManager.checkin(subNodeW2.getPath());
    versionManager.checkout(nodeToMerge.getPath());
    // merge, besteffort set to true
    versionManager.merge(nodeToMerge.getPath(), workspace.getName(), true);
    // sub node should not be touched because merging failed
    assertTrue(subNodeW2.getProperty(propertyName1).getString().equals(""));
    // test root node should be touched because update
    assertFalse(nodeToMerge.getProperty(propertyName1).getString().equals(nodeToMerge.getName()));
}
Also used : Node(javax.jcr.Node) VersionManager(javax.jcr.version.VersionManager)

Example 47 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 48 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 49 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 50 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)

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