jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r777548 [1/2] - /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/
Date Fri, 22 May 2009 14:38:52 GMT
Author: reschke
Date: Fri May 22 14:38:51 2009
New Revision: 777548

URL: http://svn.apache.org/viewvc?rev=777548&view=rev
Log:
JCR-2085: add JCR2 related versioning tests

Modified:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeCancelMergeTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeCheckedoutSubNodeTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeDoneMergeTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNodeIteratorTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNodeTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNonVersionableSubNodeTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeSubNodeTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionAbortTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionComputeTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionCopyTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionIgnoreTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionInitializeTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionGraphTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionHistoryTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionLabelTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/WorkspaceRestoreTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeCancelMergeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeCancelMergeTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeCancelMergeTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeCancelMergeTest.java Fri May 22 14:38:51 2009
@@ -21,6 +21,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
 
 /**
  * <code>MergeCancelMergeTest</code> contains tests dealing with nodes on which
@@ -43,7 +44,8 @@
 
         nodeToMerge = testRootNodeW2.getNode(nodeName1);
         // node has to be checked out while merging
-        nodeToMerge.checkout();
+        VersionManager versionManager = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        versionManager.checkout(nodeToMerge.getPath());
     }
 
     protected void tearDown() throws Exception {
@@ -99,15 +101,19 @@
      * initialize a versionable node on default and second workspace
      */
     protected void initNodes() throws RepositoryException {
+
+        VersionManager versionManager = testRootNode.getSession().getWorkspace().getVersionManager();
+
         // create a versionable node
         // nodeName1
         Node topVNode = testRootNode.addNode(nodeName1, versionableNodeType);
         topVNode.setProperty(propertyName1, topVNode.getName());
+        String path = topVNode.getPath();
 
         // save default workspace
-        testRootNode.save();
-        topVNode.checkin();
-        topVNode.checkout();
+        testRootNode.getSession().save();
+        versionManager.checkin(path);
+        versionManager.checkout(path);
 
         log.println("test nodes created successfully on " + workspace.getName());
 
@@ -117,4 +123,52 @@
 
         testRootNodeW2 = (Node) superuserW2.getItem(testRoot);
     }
+
+    /**
+     * Merge.cancelMerge(V): has the effect of removing the reference to V' from
+     * the jcr:mergeFailed property of N. <br> without adding it to
+     * jcr:predecessors.<br> Branches will not be joined.<br>
+     */
+    public void testMergeNodeCancelMergeJcr2() throws RepositoryException {
+        // create 2 independent versions for a node and its corresponding node
+        // so merge fails for this node
+    
+        // default workspace
+        Node originalNode = testRootNode.getNode(nodeName1);
+        VersionManager vmWsp1 = originalNode.getSession().getWorkspace().getVersionManager();
+        String originalPath = originalNode.getPath();
+        vmWsp1.checkout(originalPath);
+        vmWsp1.checkin(originalPath);
+    
+        // second workspace
+        VersionManager vmWsp2 = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        String path = nodeToMerge.getPath();
+        vmWsp2.checkin(path);
+    
+        // "merge" the clonedNode with the newNode from the default workspace
+        vmWsp2.checkout(path);
+        vmWsp2.merge(path, workspace.getName(), true);
+    
+        // get predecessors
+        Version[] predecessors = vmWsp2.getBaseVersion(path).getPredecessors();
+        // get mergeFailed property
+        Property mergeFailedProperty = nodeToMerge.getProperty(jcrMergeFailed);
+        Value[] mergeFailedReferences = mergeFailedProperty.getValues();
+    
+        for (int i = 0; i < mergeFailedReferences.length; i++) {
+            String id = mergeFailedReferences[i].getString();
+            vmWsp2.cancelMerge(path, (Version) superuser.getNodeByIdentifier(id));
+        }
+    
+        // check predecessors - unchanged
+        Version[] predecessorsAfterCancel = vmWsp2.getBaseVersion(path).getPredecessors();
+        assertTrue(predecessors.length == predecessorsAfterCancel.length);
+    
+        // check mergeFailed property - reference removed
+        if (nodeToMerge.hasProperty(jcrMergeFailed)) {
+            Property mergeFailedPropertyAfterCancelMerge = nodeToMerge.getProperty(jcrMergeFailed);
+            Value[] mergeFailedReferencesAfterCancelMerge = mergeFailedPropertyAfterCancelMerge.getValues();
+            assertTrue(mergeFailedReferences.length > mergeFailedReferencesAfterCancelMerge.length);
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeCheckedoutSubNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeCheckedoutSubNodeTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeCheckedoutSubNodeTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeCheckedoutSubNodeTest.java Fri May 22 14:38:51 2009
@@ -19,6 +19,7 @@
 import javax.jcr.MergeException;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
+import javax.jcr.version.VersionManager;
 
 /**
  * <code>MergeCheckedoutSubNodeTest</code> contains tests dealing with
@@ -41,7 +42,8 @@
 
         nodeToMerge = testRootNodeW2.getNode(nodeName1);
         // node has to be checked out while merging
-        nodeToMerge.checkout();
+        VersionManager versionManager = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        versionManager.checkout(nodeToMerge.getPath());
     }
 
     protected void tearDown() throws Exception {
@@ -74,6 +76,31 @@
     }
 
     /**
+     * VersionManager.merge(): If V' of a versionable subnode N' in the source workspace
+     * is a successor of V (the base version of a subnode N in this workspace),
+     * calling merge must fail.
+     */
+    public void testFailIfCorrespondingNodeIsSuccessorJcr2() throws RepositoryException {
+        // make V' of a subnode N' in source workspace be a successor version of
+        // the base version of the corresponding subnode.
+        Node n = testRootNode.getNode(nodeName1 + "/" + nodeName2);
+        VersionManager versionManager = n.getSession().getWorkspace().getVersionManager();
+        String path = n.getPath();
+        versionManager.checkout(path);
+        versionManager.checkin(path);
+        versionManager.checkout(path);
+
+        try {
+            // merge, besteffort set to false to stop at the first failure
+            nodeToMerge.getSession().getWorkspace().getVersionManager().merge(nodeToMerge.getPath(), workspace.getName(), false);
+            fail("Merging a checkedout node if the version V' of the corresponding node is a successor of this node's base version must fail.");
+
+        } catch (MergeException e) {
+            // success
+        }
+    }
+
+    /**
      * Node.merge(): If V' of a versionable subnode N' in the source workspace
      * is a predeccessor of V or V' identical to V (the base version of a
      * subnode N in this workspace), calling merge must be leave.
@@ -97,6 +124,30 @@
     }
 
     /**
+     * VersionManager.merge(): If V' of a versionable subnode N' in the source workspace
+     * is a predeccessor of V or V' identical to V (the base version of a
+     * subnode N in this workspace), calling merge must be leave.
+     */
+    public void testLeaveIfCorrespondingNodeIsPredeccessorJcr2() throws RepositoryException {
+        // make V' of a subnode N' in source workspace be a predeccessor version of
+        // the base version of the corresponding subnode.
+        Node n = testRootNodeW2.getNode(nodeName1 + "/" + nodeName2);
+        VersionManager versionManager = n.getSession().getWorkspace().getVersionManager();
+        String path = n.getPath();
+        versionManager.checkout(path);
+        n.setProperty(propertyName1, CHANGED_STRING);
+        testRootNodeW2.getSession().save();
+        versionManager.checkin(path);
+        versionManager.checkout(path);
+
+        // merge, besteffort set to false to stop at the first failure
+        nodeToMerge.getSession().getWorkspace().getVersionManager().merge(nodeToMerge.getPath(), workspace.getName(), false);
+
+        // check if subnode has status "leave"
+        assertTrue(n.getProperty(propertyName1).getString().equals(CHANGED_STRING));
+    }
+
+    /**
      * initialize a two-step-hierarchy on default and second workspace
      */
     protected void initNodes() throws RepositoryException {
@@ -111,7 +162,7 @@
         subNvNode.setProperty(propertyName1, subNvNode.getName());
 
         // save default workspace
-        testRootNode.save();
+        testRootNode.getSession().save();
 
         log.println("test nodes created successfully on " + workspace.getName());
 

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeDoneMergeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeDoneMergeTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeDoneMergeTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeDoneMergeTest.java Fri May 22 14:38:51 2009
@@ -21,6 +21,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
 
 /**
  * <code>MergeDoneMergeTest</code> contains test dealing with nodes on which
@@ -42,7 +43,8 @@
 
         nodeToMerge = testRootNodeW2.getNode(nodeName1);
         // node has to be checked out while merging
-        nodeToMerge.checkout();
+        VersionManager versionManager = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        versionManager.checkout(nodeToMerge.getPath());
 
     }
 
@@ -92,18 +94,66 @@
     }
 
     /**
+     * VersionManager.doneMerge(V) throws VersionException if V is not among the Vs in the
+     * jcr:mergeFailed prop. <br> with adding it to jcr:predecessors.<br>
+     * Branches will be joined.<br>
+     */
+    public void testMergeNodeDoneMergeJcr2() throws RepositoryException {
+        // create 2 independent versions for a node and its corresponding node
+        // so merge fails for this node
+
+        // default workspace
+        Node originalNode = testRootNode.getNode(nodeName1);
+        VersionManager vmWsp1 = originalNode.getSession().getWorkspace().getVersionManager();
+        String originalPath = originalNode.getPath();
+        vmWsp1.checkout(originalPath);
+        vmWsp1.checkin(originalPath);
+
+        // second workspace
+        VersionManager vmWsp2 = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        String path = nodeToMerge.getPath();
+        vmWsp2.checkin(path);
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        vmWsp2.checkout(path);
+        vmWsp2.merge(path, workspace.getName(), true);
+
+        // get predecessors
+        Version[] predecessors = nodeToMerge.getBaseVersion().getPredecessors();
+        // get mergeFailed property
+        Property mergeFailedProperty = nodeToMerge.getProperty(jcrMergeFailed);
+        Value[] mergeFailedReferences = mergeFailedProperty.getValues();
+
+        for (int i = 0; i < mergeFailedReferences.length; i++) {
+            String id = mergeFailedReferences[i].getString();
+            vmWsp2.doneMerge(path, (Version) superuser.getNodeByIdentifier(id));
+        }
+
+        // check mergeFailed property - reference moved to predecessor
+        if (nodeToMerge.hasProperty(jcrMergeFailed)) {
+            Property mergeFailedPropertyAfterCancelMerge = nodeToMerge.getProperty(jcrMergeFailed);
+            Value[] mergeFailedReferencesAfterCancelMerge = mergeFailedPropertyAfterCancelMerge.getValues();
+            assertTrue(mergeFailedReferences.length > mergeFailedReferencesAfterCancelMerge.length);
+        }
+    }
+
+    /**
      * initialize a versionable node on default and second workspace
      */
     protected void initNodes() throws RepositoryException {
+
+        VersionManager versionManager = testRootNode.getSession().getWorkspace().getVersionManager();
+
         // create a versionable node
         // nodeName1
         Node topVNode = testRootNode.addNode(nodeName1, versionableNodeType);
         topVNode.setProperty(propertyName1, topVNode.getName());
+        String path = topVNode.getPath();
 
         // save default workspace
-        testRootNode.save();
-        topVNode.checkin();
-        topVNode.checkout();
+        testRootNode.getSession().save();
+        versionManager.checkin(path);
+        versionManager.checkout(path);
 
         log.println("test nodes created successfully on " + workspace.getName());
 

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNodeIteratorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNodeIteratorTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNodeIteratorTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNodeIteratorTest.java Fri May 22 14:38:51 2009
@@ -18,6 +18,7 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Node;
+import javax.jcr.version.VersionManager;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -86,12 +87,56 @@
     }
 
     /**
+     * Tests if VersionManager.merge() when bestEffort is true returns a NodeIterator
+     * containing all nodes that received a fail.
+     */
+    public void testNodeIteratorJcr2() throws RepositoryException {
+
+        Node nodeToMerge = testRootNodeW2.getNode(nodeName1);
+
+        Iterator failedNodes = nodeToMerge.getSession().getWorkspace().getVersionManager().merge(
+                nodeToMerge.getPath(), workspace.getName(), true);
+
+        List nodeList = new ArrayList();
+        while (failedNodes.hasNext()) {
+            nodeList.add(failedNodes.next());
+        }
+
+        assertEquals("Node.merge() does not return a NodeIterator with " +
+                "expected number of elements.",
+                expectedFailedNodes.length,
+                nodeList.size());
+
+        // re-aquire iterator, has been consumed to get size
+        failedNodes = nodeList.iterator();
+        compareReturnedWithExpected:
+        while (failedNodes.hasNext()) {
+            String path = ((Node) failedNodes.next()).getPath();
+            for (int i = 0; i < expectedFailedNodes.length; i++) {
+                if (expectedFailedNodes[i] != null) {
+                    String expectedPath = expectedFailedNodes[i].getPath();
+                    if (path.equals(expectedPath)) {
+                        // to assure every failed node appears only once in the
+                        // NodeIterator, set each found expected node to null
+                        expectedFailedNodes[i] = null;
+                        continue compareReturnedWithExpected;
+                    }
+                }
+            }
+            fail("Node.merge() must return a NodeIterator over all " +
+                    "nodes that did receive a result of fail.");
+        }
+    }
+
+    /**
      * initialize some versionable nodes on default and second workspace
      */
     protected void initNodes() throws RepositoryException {
 
         // create some versionable node in default workspace (WS1)
 
+        VersionManager versionManager = testRootNode.getSession().getWorkspace().getVersionManager();
+
         Node mergeRootNode = testRootNode.addNode(nodeName1, versionableNodeType);
 
         Node nodeWS1_1 = mergeRootNode.addNode(nodeName1, versionableNodeType);
@@ -100,23 +145,22 @@
         Node nodeWS1_2Sub1 = nodeWS1_2.addNode(nodeName1, versionableNodeType);
         Node nodeWS1_3 = mergeRootNode.addNode(nodeName3, versionableNodeType);
 
-        testRootNode.save();
-
-        nodeWS1_1.checkin(); // create version 1.0
-        nodeWS1_1.checkout();
+        testRootNode.getSession().save();
 
-        nodeWS1_1Sub1.checkin(); // create version 1.0
-        nodeWS1_1Sub1.checkout();
+        versionManager.checkin(nodeWS1_1.getPath()); // create version 1.0
+        versionManager.checkout(nodeWS1_1.getPath());
 
-        nodeWS1_2.checkin(); // create version 1.0
-        nodeWS1_2.checkout();
+        versionManager.checkin(nodeWS1_1Sub1.getPath()); // create version 1.0
+        versionManager.checkout(nodeWS1_1Sub1.getPath());
 
-        nodeWS1_2Sub1.checkin(); // create version 1.0
-        nodeWS1_2Sub1.checkout();
+        versionManager.checkin(nodeWS1_2.getPath()); // create version 1.0
+        versionManager.checkout(nodeWS1_2.getPath());
 
-        nodeWS1_3.checkin(); // create version 1.0
-        nodeWS1_3.checkout();
+        versionManager.checkin(nodeWS1_2Sub1.getPath()); // create version 1.0
+        versionManager.checkout(nodeWS1_2Sub1.getPath());
 
+        versionManager.checkin(nodeWS1_3.getPath()); // create version 1.0
+        versionManager.checkout(nodeWS1_3.getPath());
 
         workspaceW2.clone(workspace.getName(), mergeRootNode.getPath(), mergeRootNode.getPath(), true);
 
@@ -127,14 +171,14 @@
 
         // create version branches for some of the nodes
 
-        nodeWS2_1.checkin(); // create version 1.1
-        nodeWS1_1.checkin(); // create version 1.0.1
+        versionManager.checkin(nodeWS2_1.getPath()); // create version 1.1
+        versionManager.checkin(nodeWS1_1.getPath()); // create version 1.0.1
 
-        nodeWS2_2.checkin(); // create version 1.1
-        nodeWS1_2.checkin(); // create version 1.0.1
+        versionManager.checkin(nodeWS2_2.getPath()); // create version 1.1
+        versionManager.checkin(nodeWS1_2.getPath()); // create version 1.0.1
 
-        nodeWS2_2Sub1.checkin(); // create version 1.1
-        nodeWS1_2Sub1.checkin(); // create version 1.0.1
+        versionManager.checkin(nodeWS2_2Sub1.getPath()); // create version 1.1
+        versionManager.checkin(nodeWS1_2Sub1.getPath()); // create version 1.0.1
 
         // set the nodes with version branches in expectedFailedNodes
         expectedFailedNodes[0] = nodeWS1_1;

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNodeTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNodeTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNodeTest.java Fri May 22 14:38:51 2009
@@ -19,6 +19,7 @@
 import org.apache.jackrabbit.test.NotExecutableException;
 
 import javax.jcr.version.VersionException;
+import javax.jcr.version.VersionManager;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.InvalidItemStateException;
@@ -52,7 +53,8 @@
 
         nodeToMerge = testRootNodeW2.getNode(nodeName1);
         // node has to be checked out while merging
-        nodeToMerge.checkout();
+        VersionManager versionManager = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        versionManager.checkout(nodeToMerge.getPath());
 
     }
 
@@ -77,6 +79,22 @@
     }
 
     /**
+     * VersionManager.merge(): InvalidItemStateException if unsaved changes within the
+     * current Session<br>
+     */
+    public void testMergeNodeWithUnsavedStatesJcr2() throws RepositoryException {
+        // set a property and do not save workspace
+        nodeToMerge.setProperty(propertyName1, CHANGED_STRING);
+        try {
+            nodeToMerge.getSession().getWorkspace().getVersionManager().merge(
+                    nodeToMerge.getPath(), workspace.getName(), false);
+            fail("InvalidItemStateException if unsaved changes within the current Session was expected.");
+        } catch (InvalidItemStateException e) {
+            // success
+        }
+    }
+
+    /**
      * Perform a merge on a node with a unkwnown workspacename
      */
     public void testMergeUnknownWorkspaceName() throws RepositoryException {
@@ -88,6 +106,18 @@
     }
 
     /**
+     * Perform a merge on a node with a unkwnown workspacename
+     */
+    public void testMergeUnknownWorkspaceNameJcr2() throws RepositoryException {
+        try {
+            nodeToMerge.getSession().getWorkspace().getVersionManager().merge(
+                    nodeToMerge.getPath(), getNonExistingWorkspaceName(superuser), false);
+        } catch (NoSuchWorkspaceException e) {
+            // success expected exception
+        }
+    }
+
+    /**
      * Node.merge(): If this node does not have a corresponding node in the
      * indicated workspace <br> then the merge method returns quietly and no
      * changes are made.<br>
@@ -104,6 +134,24 @@
     }
 
     /**
+     * VersionManager.merge(): If this node does not have a corresponding node in the
+     * indicated workspace <br> then the merge method returns quietly and no
+     * changes are made.<br>
+     */
+    public void testMergeNodeNonCorrespondingNodeJcr2() throws RepositoryException {
+        // create new node - this node has no corresponding node in default workspace
+        Node subNode = nodeToMerge.addNode(nodeName3, versionableNodeType);
+        subNode.setProperty(propertyName1, CHANGED_STRING);
+        superuserW2.save();
+        VersionManager versionManager = subNode.getSession().getWorkspace().getVersionManager();
+        String path = subNode.getPath();
+        versionManager.checkin(path);
+
+        versionManager.merge(path, workspace.getName(), true);
+        assertTrue(subNode.getProperty(propertyName1).getString().equals(CHANGED_STRING));
+    }
+
+    /**
      * Node.merge(): versionable subNode N checked-in: If V is neither a
      * successor of, predecessor of, nor identical with V', then the merge
      * result for N is failed<br>
@@ -132,6 +180,38 @@
     }
 
     /**
+     * VersionManager.merge(): versionable subNode N checked-in: If V is neither a
+     * successor of, predecessor of, nor identical with V', then the merge
+     * result for N is failed<br>
+     */
+    public void testMergeNodeVersionAmbiguousJcr2() throws RepositoryException {
+        // create 2 independent versions for a node and its corresponding node
+        // so merge fails for this node
+
+        // default workspace
+        Node originalNode = testRootNode.getNode(nodeName1);
+        VersionManager vmWsp1 = originalNode.getSession().getWorkspace().getVersionManager();
+        String originalPath = originalNode.getPath();
+        vmWsp1.checkout(originalPath);
+        vmWsp1.checkin(originalPath);
+
+        // second workspace
+        VersionManager vmWsp2 = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        String path = nodeToMerge.getPath();
+        vmWsp2.checkin(path);
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        // besteffort set to false to stop at the first failure
+        try {
+            vmWsp2.checkout(path);
+            vmWsp2.merge(path, workspace.getName(), false);
+            fail("Node has ambigous versions. Merge must throw a MergeException");
+        } catch (MergeException e) {
+            // success if the merge exception thrown
+        }
+    }
+
+    /**
      * Node.merge(): bestEffort is true > any merge-failure (represented by the
      * version in the workspace) is reported in the jcrMergeFailed property<br>
      */
@@ -172,6 +252,50 @@
     }
 
     /**
+     * VersionManager.merge(): bestEffort is true > any merge-failure (represented by the
+     * version in the workspace) is reported in the jcrMergeFailed property<br>
+     */
+    public void testMergeNodeBestEffortTrueCheckMergeFailedPropertyJcr2() throws RepositoryException {
+        // create 2 independent versions for a node and its corresponding node
+        // so merge fails for this node
+
+        // default workspace
+        Node originalNode = testRootNode.getNode(nodeName1);
+        VersionManager vmWsp1 = originalNode.getSession().getWorkspace().getVersionManager();
+        String originalPath = originalNode.getPath();
+        vmWsp1.checkout(originalPath);
+        vmWsp1.checkin(originalPath);
+
+        // second workspace
+        VersionManager vmWsp2 = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        String path = nodeToMerge.getPath();
+        vmWsp2.checkin(path);
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        // besteffort set to true to report all failures
+        vmWsp2.checkout(path);
+        vmWsp2.merge(path, workspace.getName(), true);
+
+        // success merge exception was raised as expected
+        // jcrMergeFailed should contains reference to the V' as it is a different branche
+        String expectedReferenceUUID = originalNode.getBaseVersion().getUUID();
+        Property mergeFailedProperty = nodeToMerge.getProperty(jcrMergeFailed);
+        Value[] references = mergeFailedProperty.getValues();
+        boolean referenceFound = false;
+        if (references != null) {
+            for (int i = 0; i < references.length; i++) {
+                String referenceUUID = references[i].getString();
+                if (referenceUUID.equals(expectedReferenceUUID)) {
+                    referenceFound = true;
+                    break; // it's not necessary to loop thru all the references
+                }
+            }
+
+            assertTrue("reference to expected version that give the failure wasnt found in the mergeFailed", referenceFound);
+        }
+    }
+
+    /**
      * if mergeFailedProperty is present > VersionException<br>
      */
     public void disable_testMergeNodeForceFailure() throws RepositoryException {
@@ -200,6 +324,38 @@
     }
 
     /**
+     * if mergeFailedProperty is present > VersionException<br>
+     */
+    public void disable_testMergeNodeForceFailureJcr2() throws RepositoryException {
+        // create 2 independent versions for a node and its corresponding node
+        // so merge fails for this node
+
+        // default workspace
+        Node originalNode = testRootNode.getNode(nodeName1);
+        VersionManager vmWsp1 = originalNode.getSession().getWorkspace().getVersionManager();
+        String originalPath = originalNode.getPath();
+        vmWsp1.checkout(originalPath);
+        vmWsp1.checkin(originalPath);
+
+        // second workspace
+        VersionManager vmWsp2 = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        String path = nodeToMerge.getPath();
+        vmWsp2.checkin(path);
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        // besteffort set to true to report all failures
+        vmWsp2.checkout(path);
+        vmWsp2.merge(path, workspace.getName(), true);
+
+        try {
+            vmWsp2.merge(path, workspace.getName(), true);
+            fail("Merge failed for node in earlier merge operations. Because the mergeFailedProperty is present, merge must throw a VersionException");
+        } catch (VersionException e) {
+            // success version exception expected
+        }
+    }
+
+    /**
      * Node.merge(): bestEffort is false and any merge fails a MergeException is
      * thrown.<br>
      */
@@ -223,6 +379,32 @@
     }
 
     /**
+     * VersionManager.merge(): bestEffort is false and any merge fails a MergeException is
+     * thrown.<br>
+     */
+    public void testMergeNodeBestEffortFalseJcr2() throws RepositoryException {
+        /// create successor versions for a node
+        // so merge fails for this node
+
+        // default workspace
+        Node originalNode = testRootNode.getNode(nodeName1);
+        VersionManager vmWsp1 = originalNode.getSession().getWorkspace().getVersionManager();
+        String originalPath = originalNode.getPath();
+        vmWsp1.checkout(originalPath);
+        vmWsp1.checkin(originalPath);
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        // merge, besteffort set to false
+        try {
+            nodeToMerge.getSession().getWorkspace().getVersionManager().merge(
+                    nodeToMerge.getPath(), workspace.getName(), false);
+            fail("bestEffort is false and any merge should throw a MergeException.");
+        } catch (MergeException e) {
+            // successful
+        }
+    }
+
+    /**
      * A MergeVersionException is thrown if bestEffort is false and a
      * versionable node is encountered whose corresponding node's base version
      * is on a divergent branch from this node's base version.
@@ -252,6 +434,39 @@
     }
 
     /**
+     * A MergeVersionException is thrown if bestEffort is false and a
+     * versionable node is encountered whose corresponding node's base version
+     * is on a divergent branch from this node's base version.
+     */
+    public void testMergeNodeBestEffortFalseAmbiguousVersionsJcr2() throws RepositoryException {
+        /// create 2 independent base versions for a node and its corresponding node
+        // so merge fails for this node
+
+        // default workspace
+        Node originalNode = testRootNode.getNode(nodeName1);
+        VersionManager vmWsp1 = originalNode.getSession().getWorkspace().getVersionManager();
+        String originalPath = originalNode.getPath();
+        vmWsp1.checkout(originalPath);
+        vmWsp1.checkin(originalPath);
+
+        // second workspace
+        VersionManager vmWsp2 = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        String path = nodeToMerge.getPath();
+        vmWsp2.checkin(path);
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        vmWsp2.checkout(path);
+
+        // merge, besteffort set to false
+        try {
+            vmWsp2.merge(path, workspace.getName(), false);
+            fail("BestEffort is false and corresponding node's version is ambiguous. Merge should throw a MergeException.");
+        } catch (MergeException e) {
+            // successful
+        }
+    }
+
+    /**
      * Tests if a {@link LockException} is thrown when merge is called on a
      * locked node.
      * @throws NotExecutableException if repository does not support locking.
@@ -259,8 +474,6 @@
     public void disable_testMergeLocked()
             throws NotExecutableException, RepositoryException {
 
-        Session session = testRootNode.getSession();
-
         if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
             throw new NotExecutableException("Locking is not supported.");
         }
@@ -300,18 +513,69 @@
     }
 
     /**
+     * Tests if a {@link LockException} is thrown when merge is called on a
+     * locked node.
+     * @throws NotExecutableException if repository does not support locking.
+     */
+    public void disable_testMergeLockedJcr2()
+            throws NotExecutableException, RepositoryException {
+
+        if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
+            throw new NotExecutableException("Locking is not supported.");
+        }
+
+        // try to make nodeToMerge lockable if it is not
+        if (!nodeToMerge.isNodeType(mixLockable)) {
+            if (nodeToMerge.canAddMixin(mixLockable)) {
+                nodeToMerge.addMixin(mixLockable);
+            } else {
+                throw new NotExecutableException("Node " + nodeToMerge.getName() + " is not lockable and " +
+                        "does not allow to add mix:lockable");
+            }
+        }
+        nodeToMerge.getParent().getSession().save();
+
+        // lock the node
+        // remove first slash of path to get rel path to root
+        String pathRelToRoot = nodeToMerge.getPath().substring(1);
+        // access node through another session to lock it
+        Session session2 = helper.getSuperuserSession();
+        try {
+            Node node2 = session2.getRootNode().getNode(pathRelToRoot);
+            node2.getSession().getWorkspace().getLockManager().lock(node2.getPath(), false, false, 60, "");
+
+            try {
+                nodeToMerge.getSession().getWorkspace().getVersionManager().merge(
+                        nodeToMerge.getPath(), workspace.getName(), false);
+                fail("merge must throw a LockException if applied on a " +
+                        "locked node");
+            } catch (LockException e) {
+                // success
+            }
+
+            node2.getSession().getWorkspace().getLockManager().unlock(node2.getPath());
+        } finally {
+            session2.logout();
+        }
+    }
+
+    /**
      * initialize a versionable node on default and second workspace
      */
     protected void initNodes() throws RepositoryException {
+
+        VersionManager versionManager = testRootNode.getSession().getWorkspace().getVersionManager();
+
         // create a versionable node
         // nodeName1
         Node topVNode = testRootNode.addNode(nodeName1, versionableNodeType);
         topVNode.setProperty(propertyName1, topVNode.getName());
+        String path = topVNode.getPath();
 
         // save default workspace
-        testRootNode.save();
-        topVNode.checkin();
-        topVNode.checkout();
+        testRootNode.getSession().save();
+        versionManager.checkin(path);
+        versionManager.checkout(path);
 
         log.println("test nodes created successfully on " + workspace.getName());
 

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNonVersionableSubNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNonVersionableSubNodeTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNonVersionableSubNodeTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeNonVersionableSubNodeTest.java Fri May 22 14:38:51 2009
@@ -58,6 +58,30 @@
     }
 
     /**
+     * VersionManager.merge(): nonversionable subNode N: if it has no versionable
+     * ancestor, then it is updated to reflect the state of its corresponding
+     * node.<br>
+     */
+    public void testMergeNodeNonVersionableSubNodeNonVersionableAncestorJcr2() throws RepositoryException {
+        String nodeToMergePath = nodeName1 + "/" + nodeName2 + "/" + nodeName3;
+
+        // node to merge in second workspace
+        Node nodeToMerge = testRootNodeW2.getNode(nodeToMergePath);
+        // corresponding node to nodeToMerge in default workspace
+        Node correspondingNode = testRootNode.getNode(nodeToMergePath);
+
+        // modify value for non'v node in workspace2 so we can check if node in workspace2 after merge is updated
+        // to reflect the state of its corresponding node in default workspace....
+        nodeToMerge.setProperty(propertyName1, CHANGED_STRING);
+        nodeToMerge.getSession().save();
+        nodeToMerge.getSession().getWorkspace().getVersionManager().merge(
+                nodeToMerge.getPath(), workspace.getName(), true);
+
+        // test if modification on non-v node is done according to corresponding node.
+        assertTrue(nodeToMerge.getProperty(propertyName1).getString().equals(correspondingNode.getName()));
+    }
+
+    /**
      * Node.merge(): nonversionable subNode N: if the merge result of its
      * nearest versionable ancestor is update,<br> then it is updated to reflect
      * the state of its corresponding node.<br>
@@ -91,6 +115,39 @@
     }
 
     /**
+     * VersionManager.merge(): nonversionable subNode N: if the merge result of its
+     * nearest versionable ancestor is update,<br> then it is updated to reflect
+     * the state of its corresponding node.<br>
+     */
+    public void testMergeNodeNonVersionableSubNodeUpdateJcr2() throws RepositoryException {
+        // modify non versionable subnode so we can check if it's updated after merge
+        String changedString = CHANGED_STRING + System.currentTimeMillis();
+        String nvSubNodePath = nodeName2 + "/" + nodeName3;
+
+        // versionable ancestor to merge in first workspace (N)
+        Node n = testRootNodeW2.getNode(nodeName1);
+
+        // versionable ancestor to merge in second workspace (N')
+        Node np = testRootNodeW2.getNode(nodeName1);
+
+        // checkout N and make change
+        n.getSession().getWorkspace().getVersionManager().checkout(n.getPath());
+        Node nvSubNode = n.getNode(nvSubNodePath);
+        nvSubNode.setProperty(propertyName1, changedString);
+        n.getSession().save();
+        n.getSession().getWorkspace().getVersionManager().checkin(n.getPath());
+
+        // merge change into N'
+        np.getSession().getWorkspace().getVersionManager().merge(np.getPath(), workspaceW2.getName(), true);
+
+        // corresponding node to nvSubNode in 2nd workspace
+        Node nvSubNodeP = np.getNode(nvSubNodePath);
+
+        // test if modification on N was merged into N' subnode
+        assertTrue(nvSubNodeP.getProperty(propertyName1).getString().equals(changedString));
+    }
+
+    /**
      * Node.merge(): nonversionable subNode N: is left unchanged if the nearest
      * versionable ancestor has state leave.<br>
      */
@@ -123,6 +180,38 @@
     }
 
     /**
+     * VersionManager.merge(): nonversionable subNode N: is left unchanged if the nearest
+     * versionable ancestor has state leave.<br>
+     */
+    public void testMergeNodeNonVersionableSubNodeLeaveJcr2() throws RepositoryException {
+        // modify non versionable subnode so we can check if it's updated after merge
+        String changedString = CHANGED_STRING + System.currentTimeMillis();
+        String nvSubNodePath = nodeName2 + "/" + nodeName3;
+
+        // versionable ancestor to merge in first workspace (N)
+        Node n = testRootNodeW2.getNode(nodeName1);
+
+        // versionable ancestor to merge in second workspace (N')
+        Node np = testRootNodeW2.getNode(nodeName1);
+
+        // checkout N' and make change
+        np.getSession().getWorkspace().getVersionManager().checkout(np.getPath());
+        Node nvSubNodeP = np.getNode(nvSubNodePath);
+        nvSubNodeP.setProperty(propertyName1, changedString);
+        np.getSession().save();
+        np.getSession().getWorkspace().getVersionManager().checkin(np.getPath());
+
+        // merge into N'
+        np.getSession().getWorkspace().getVersionManager().merge(np.getPath(), workspaceW2.getName(), true);
+
+        // corresponding node to nvSubNode in 2nd workspace
+        Node nvSubNode = np.getNode(nvSubNodePath);
+
+        // test if modification on N' was not modified
+        assertTrue(nvSubNode.getProperty(propertyName1).getString().equals(changedString));
+    }
+
+    /**
      * initialize a three-step-hierarchy on default and second workspace
      */
     protected void initNodes() throws RepositoryException {
@@ -142,7 +231,7 @@
         subSubNvNode.setProperty(propertyName1, subSubNvNode.getName());
 
         // save default workspace
-        testRootNode.save();
+        testRootNode.getSession().save();
 
         log.println("test nodes created successfully on " + workspace.getName());
 

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeSubNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeSubNodeTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeSubNodeTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/MergeSubNodeTest.java Fri May 22 14:38:51 2009
@@ -19,6 +19,7 @@
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
+import javax.jcr.version.VersionManager;
 
 /**
  * <code>MergeSubNodeTest</code> contains tests dealing with sub nodes in the
@@ -42,7 +43,8 @@
 
         nodeToMerge = testRootNodeW2.getNode(nodeName1);
         // node has to be checked out while merging
-        nodeToMerge.checkout();
+        VersionManager versionManager = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        versionManager.checkout(nodeToMerge.getPath());
 
     }
 
@@ -82,6 +84,40 @@
     }
 
     /**
+     * VersionManager.merge(): versionable subNode N: If N has status leave but parent is
+     * update, then the subnode N is removed<br> retrieve the initialised node
+     * to perform operations we need before for this test<br>
+     */
+    public void disable_testRemoveNodeFromSourceWorkspaceAndMergeWithUpdateJcr2() throws RepositoryException {
+        // status 'update' for parent
+        VersionManager versionManager = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        String path = nodeToMerge.getPath();
+        versionManager.checkin(path);
+        versionManager.checkout(path);
+
+        // status 'leave' for subnode
+        Node originalNode = testRootNode.getNode(nodeName1);
+        Node originalSubNode = originalNode.getNode(nodeName2);
+        VersionManager originalVersionManager = originalSubNode.getSession().getWorkspace().getVersionManager();
+        String originalSubPath = originalSubNode.getPath();
+        originalVersionManager.checkout(originalSubPath);
+        originalVersionManager.checkin(originalSubPath);
+
+        // "merge" the nodeToMerge with the newNode from the default workspace
+        // besteffort set to false to stop at the first failure
+        versionManager.merge(path, workspace.getName(), false);
+
+        // if merge passed newSubNode1 should be also removed from workspace2
+        assertFalse("subNode1 not removed from " + workspaceW2.getName() + " as expected", nodeToMerge.hasNode(nodeName2));
+
+        // return version info about the clonedNode as it must also be updated
+        final String originalBaseVersionId = originalVersionManager.getBaseVersion(originalNode.getPath()).getIdentifier();
+        final String clonedBaseVersionId = versionManager.getBaseVersion(path).getIdentifier();
+
+        assertTrue("clonedNode has different version UUID than expected, it should be updated with the newNode version UUID", originalBaseVersionId.equals(clonedBaseVersionId));
+    }
+
+    /**
      * Node.merge(): versionable subNode N checked-in: If V' is a successor (to
      * any degree) of V, then the merge result for N is update<br> modify a node
      * on the workspace1 and then merge the one in workspace2 with the one in
@@ -104,7 +140,35 @@
         final String clonedBaseVersionUUID = nodeToMerge.getBaseVersion().getUUID();
 
         assertTrue("clonedNode has different version UUID than expected, it should be updated with the newNode version UUID", originalBaseVersionUUID.equals(clonedBaseVersionUUID));
+    }
+
+    /**
+     * VersionManager.merge(): versionable subNode N checked-in: If V' is a successor (to
+     * any degree) of V, then the merge result for N is update<br> modify a node
+     * on the workspace1 and then merge the one in workspace2 with the one in
+     * workspace1 precondition is that the node in workspace2 is checked in
+     */
+    public void disable_testMergeNodeFromUpdatedSourceWorkspaceJcr2() throws RepositoryException {
+        Node originalNode = testRootNode.getNode(nodeName1);
+        VersionManager originalVersionManager = originalNode.getSession().getWorkspace().getVersionManager();
+        String originalPath = originalNode.getPath();
+
+        // update nodeName1 on workspace1
+        originalVersionManager.checkout(originalPath);
+        originalVersionManager.checkin(originalPath);
+
+        testRootNode.getSession().save();
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        // besteffort set to false to stop at the first failure
+        VersionManager versionManager = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        String path = nodeToMerge.getPath();
+        versionManager.merge(path, workspace.getName(), false);
+
+        final String originalBaseVersionId = originalVersionManager.getBaseVersion(originalPath).getIdentifier();
+        final String clonedBaseVersionId = versionManager.getBaseVersion(path).getIdentifier();
 
+        assertTrue("clonedNode has different version UUID than expected, it should be updated with the newNode version UUID", originalBaseVersionId.equals(clonedBaseVersionId));
     }
 
     /**
@@ -130,6 +194,32 @@
     }
 
     /**
+     * VersionManager.merge(): versionable subNode N checked-in: If V' is a predecessor
+     * (to any degree) of V or if V and V' are identical (i.e., are actually the
+     * same version), then the merge result for N is leave<br> modify a node on
+     * the workspace2 and then merge the one in workspace2 with the one in
+     * workspace1<br> the node in workspace2 should be updated<br> precondition
+     * is that the node in workspace2 is checked in
+     */
+    public void testMergeNodeFromOlderSourceWorkspaceJcr2() throws RepositoryException {
+
+        VersionManager versionManager = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        String path = nodeToMerge.getPath();
+
+        // touch the version on workspace2
+        versionManager.checkin(path);
+        versionManager.checkout(path);
+
+        String baseVersionIdbeforeMerge = versionManager.getBaseVersion(path).getIdentifier();
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        // besteffort set to false to stop at the first failure
+        versionManager.merge(path, workspace.getName(), false);
+
+        assertTrue("clonedNode has different UUID than expected, it should be left unchanged", baseVersionIdbeforeMerge .equals(versionManager.getBaseVersion(path).getIdentifier()));
+    }
+
+    /**
      * Node.merge(): bestEffort is true > (sub)node which could not be merged
      * are not affected.<br>
      */
@@ -167,6 +257,46 @@
     }
 
     /**
+     * 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()));
+    }
+
+    /**
      * Node.merge(): For each versionable node N in the subtree rooted at this
      * node,<br> a merge test is performed comparing N with its corresponding
      * node in workspace, N'.<br>
@@ -187,6 +317,28 @@
     }
 
     /**
+     * VersionManager.merge(): For each versionable node N in the subtree rooted at this
+     * node,<br> a merge test is performed comparing N with its corresponding
+     * node in workspace, N'.<br>
+     */
+    public void disable_testMergeNodeSubNodesMergeTestJcr2() throws RepositoryException {
+        //setCheckProperty(nodeToMerge);
+        VersionManager versionManager = nodeToMerge.getSession().getWorkspace().getVersionManager();
+        String path = nodeToMerge.getPath();
+        versionManager.checkout(path);
+
+        versionManager.merge(path, workspace.getName(), true);
+
+        // check subnodes if they were touched
+        for (NodeIterator ni = nodeToMerge.getNodes(); ni.hasNext();) {
+            Node n = ni.nextNode();
+            if (versionManager.getBaseVersion(n.getPath()) != null) {
+                assertTrue(n.getProperty(propertyName1).getString().equals(CHANGED_STRING));
+            }
+        }
+    }
+
+    /**
      * initialize a two-step-hierarchy on default and second workspace
      */
     protected void initNodes() throws RepositoryException {
@@ -201,7 +353,7 @@
         subNvNode.setProperty(propertyName1, subNvNode.getName());
 
         // save default workspace
-        testRootNode.save();
+        testRootNode.getSession().save();
 
         log.println("test nodes created successfully on " + workspace.getName());
 

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionAbortTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionAbortTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionAbortTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionAbortTest.java Fri May 22 14:38:51 2009
@@ -21,6 +21,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.version.OnParentVersionAction;
 import javax.jcr.version.VersionException;
+import javax.jcr.version.VersionManager;
 
 /**
  * <code>OnParentVersionAbortTest</code> tests the OnParentVersion {@link OnParentVersionAction#ABORT ABORT}
@@ -54,6 +55,23 @@
     }
 
     /**
+     * Test the restore of a OnParentVersion-ABORT property
+     *
+     * @throws javax.jcr.RepositoryException
+     */
+    public void testRestorePropJcr2() throws RepositoryException {
+        try {
+            VersionManager versionManager = p.getSession().getWorkspace().getVersionManager();
+            String path = p.getParent().getPath();
+            versionManager.checkout(path);
+            versionManager.checkin(path);
+            fail("On checkin of N which has a property with OnParentVersion ABORT defined, an UnsupportedRepositoryOperationException must be thrown.");
+        } catch (VersionException e) {
+            // success
+        }
+    }
+
+    /**
      * Test the restore of a OnParentVersion-ABORT node
      *
      * @throws RepositoryException
@@ -70,4 +88,22 @@
             // success
         }
     }
+
+    /**
+     * Test the restore of a OnParentVersion-ABORT node
+     *
+     * @throws RepositoryException
+     * @throws NotExecutableException
+     */
+    public void testRestoreNodeJcr2() throws RepositoryException, NotExecutableException {
+        // create child node with OPV-ABORT behaviour
+        addChildNode(OPVAction);
+        testRootNode.getSession().save();
+        try {
+            versionableNode.getSession().getWorkspace().getVersionManager().checkin(versionableNode.getPath());
+            fail("On checkin of N which has a child node with OnParentVersion ABORT defined, an UnsupportedRepositoryOperationException must be thrown.");
+        } catch (VersionException e) {
+            // success
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionComputeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionComputeTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionComputeTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionComputeTest.java Fri May 22 14:38:51 2009
@@ -20,6 +20,7 @@
 import javax.jcr.Node;
 import javax.jcr.version.OnParentVersionAction;
 import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
 
 /**
  * <code>OnParentVersionComputeTest</code> tests the OnParentVersion {@link OnParentVersionAction#COMPUTE COMPUTE}
@@ -56,4 +57,26 @@
 
         assertEquals("On restore of a OnParentVersion-COMPUTE property P, the current P in the workspace will be left unchanged.", p.getString(), newPropValue);
     }
+
+    /**
+     * 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);
+    }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionCopyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionCopyTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionCopyTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionCopyTest.java Fri May 22 14:38:51 2009
@@ -20,6 +20,7 @@
 import javax.jcr.Node;
 import javax.jcr.version.OnParentVersionAction;
 import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
 
 /**
  * <code>OnParentVersionCopyTest</code> tests the OnParentVersion {@link OnParentVersionAction#COPY COPY}
@@ -76,4 +77,35 @@
         // todo: add proper comparison of restored node. equals does not work
         // assertEquals("On restore of a OnParentVersion-COPY child node, the node needs to be restored, replacing the current node in the workspace.", childNode, superuser.getItem(initialNodePath));
     }
+
+    /**
+     * Test the restore of a OnParentVersion-COPY node
+     *
+     * @throws javax.jcr.RepositoryException
+     */
+    public void testRestoreNodeJcr2() throws RepositoryException {
+        // prepare for node test
+        Node childNode = addChildNode(OPVAction);
+        Node nodeParent = childNode.getParent();
+        // todo: added next line. correct? -> angela
+        nodeParent.getSession().save();
+
+        VersionManager versionManager = nodeParent.getSession().getWorkspace().getVersionManager();
+        String path = nodeParent.getPath();
+        versionManager.checkout(path);
+        Version v = versionManager.checkin(path);
+
+        initialNodePath = childNode.getPath();
+        versionManager.checkout(path);
+        childNode.remove();
+        nodeParent.getSession().save();
+
+        versionManager.restore(v, false);
+
+        if (!superuser.itemExists(initialNodePath)) {
+            fail("On restore of a OnParentVersion-COPY child node, the node needs to be restored, replacing the current node in the workspace.");
+        }
+        // todo: add proper comparison of restored node. equals does not work
+        // assertEquals("On restore of a OnParentVersion-COPY child node, the node needs to be restored, replacing the current node in the workspace.", childNode, superuser.getItem(initialNodePath));
+    }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionIgnoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionIgnoreTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionIgnoreTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionIgnoreTest.java Fri May 22 14:38:51 2009
@@ -20,6 +20,7 @@
 import javax.jcr.Node;
 import javax.jcr.version.OnParentVersionAction;
 import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
 
 /**
  * <code>OnParentVersionIgnoreTest</code> tests the OnParentVersion {@link OnParentVersionAction#IGNORE IGNORE}
@@ -58,6 +59,28 @@
     }
 
     /**
+     * Test the restore of a OnParentVersion-IGNORE 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-IGNORE property P, the current value of P must be left unchanged.", p.getString(), newPropValue);
+    }
+
+    /**
      * Test the restore of a OnParentVersion-Ignore node
      *
      * @throws javax.jcr.RepositoryException
@@ -79,4 +102,27 @@
         }
     }
 
+    /**
+     * Test the restore of a OnParentVersion-Ignore node
+     *
+     * @throws javax.jcr.RepositoryException
+     */
+    public void testRestoreNodeJcr2() throws RepositoryException {
+
+        VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
+        String path = versionableNode.getPath();
+        versionManager.checkout(path);
+        Version v = versionManager.checkin(path);
+        versionManager.checkout(path);
+
+        // add 'ignore' child
+        String childName = addChildNode(OPVAction).getName();
+        versionableNode.getSession().save();
+
+        versionManager.restore(v, false);
+
+        if (!versionableNode.hasNode(childName)) {
+            fail("On restore of a OnParentVersion-Ignore child node, the node needs to be untouched.");
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionInitializeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionInitializeTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionInitializeTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/OnParentVersionInitializeTest.java Fri May 22 14:38:51 2009
@@ -20,6 +20,7 @@
 import javax.jcr.Node;
 import javax.jcr.version.OnParentVersionAction;
 import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
 
 /**
  * <code>OnParentVersionInitializeTest</code> tests the {@link OnParentVersionAction#INITIALIZE INITIALIZE}
@@ -56,4 +57,26 @@
 
         assertEquals("On restore of a OnParentVersion-INITIALIZE property P, the current value of P must be left unchanged.", p.getString(), newPropValue);
     }
+
+    /**
+     * Test the restore of a OnParentVersion-INITIALIZE 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-INITIALIZE property P, the current value of P must be left unchanged.", p.getString(), newPropValue);
+    }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionGraphTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionGraphTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionGraphTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionGraphTest.java Fri May 22 14:38:51 2009
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.test.api.version;
 
 import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
 import javax.jcr.RepositoryException;
 import javax.jcr.Property;
 import javax.jcr.Value;
@@ -48,6 +49,22 @@
     }
 
     /**
+     * Test that the initial base version after creation of a versionable node
+     * points to the root version.
+     *
+     * @throws javax.jcr.RepositoryException
+     */
+    public void testInitialBaseVersionPointsToRootVersionJcr2() throws RepositoryException {
+
+        VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
+        String path = versionableNode.getPath();
+        Version rV = versionManager.getVersionHistory(path).getRootVersion();
+        Version bV = versionManager.getBaseVersion(path);
+
+        assertTrue("After creation of a versionable node the node's baseVersion must point to the rootVersion in the version history.", rV.isSame(bV));
+    }
+
+    /**
      * Test if after creation of a versionable node N the multi-value
      * REFERENCE property jcr:predecessors of N is initialized to contain a
      * single UUID, that of the root version (the same as jcr:baseVersion).
@@ -69,6 +86,27 @@
     }
 
     /**
+     * Test if after creation of a versionable node N the multi-value
+     * REFERENCE property jcr:predecessors of N is initialized to contain a
+     * single UUID, that of the root version (the same as jcr:baseVersion).
+     *
+     * @throws RepositoryException
+     */
+    public void testInitialNodePredecessorsJcr2() throws RepositoryException {
+
+        Property predecessors = versionableNode.getProperty(jcrPredecessors);
+        Value[] values = predecessors.getValues();
+        Version rV = versionableNode.getSession().getWorkspace().getVersionManager().getVersionHistory(versionableNode.getPath()).getRootVersion();
+        if (values.length != 1) {
+            fail("The jcr:predecessors property of a versionable node must be initialized to contain a single value");
+        }
+
+        Value initialVal = values[0];
+
+        assertTrue("The jcr:predecessors property of a versionable node is initialized to contain a single UUID, that of the root version", initialVal.equals(superuser.getValueFactory().createValue(rV)));
+    }
+
+    /**
      * Test if the root version does not have any predecessor versions.
      *
      * @throws RepositoryException
@@ -79,6 +117,16 @@
     }
 
     /**
+     * Test if the root version does not have any predecessor versions.
+     *
+     * @throws RepositoryException
+     */
+    public void testRootVersionHasNoPredecessorJcr2() throws RepositoryException {
+        Version[] predec = versionableNode.getSession().getWorkspace().getVersionManager().getVersionHistory(versionableNode.getPath()).getRootVersion().getPredecessors();
+        assertTrue("The root version may not have any predecessors.", predec.length == 0);
+    }
+
+    /**
      * Test if UnsupportedRepositoryOperationException is thrown when calling
      * Node.getVersionHistory() on a non-versionable node.
      *
@@ -92,4 +140,19 @@
             //success
         }
     }
+
+    /**
+     * Test if UnsupportedRepositoryOperationException is thrown when calling
+     * Node.getVersionHistory() on a non-versionable node.
+     *
+     * @throws RepositoryException
+     */
+    public void testGetBaseVersionOnNonVersionableNodeJcr2() throws RepositoryException {
+        try {
+            nonVersionableNode.getSession().getWorkspace().getVersionManager().getBaseVersion(nonVersionableNode.getPath());
+            fail("Node.getBaseVersion() must throw UnsupportedRepositoryOperationException if the node is not versionable.");
+        } catch (UnsupportedRepositoryOperationException e) {
+            //success
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message