jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r156952 - in incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version: AbstractMergeTest.java MergeCancelMergeTest.java MergeCheckedoutSubNodeTest.java MergeDoneMergeTest.java MergeNodeTest.java MergeNonVersionableSubNodeTest.java MergeSubNodeTest.java
Date Thu, 10 Mar 2005 14:33:19 GMT
Author: mreutegg
Date: Thu Mar 10 06:33:08 2005
New Revision: 156952

URL: http://svn.apache.org/viewcvs?view=rev&rev=156952
Log:
Test cases for Node.merge().

Added:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/AbstractMergeTest.java
  (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeCancelMergeTest.java
  (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeCheckedoutSubNodeTest.java
  (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeDoneMergeTest.java
  (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNodeTest.java
  (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNonVersionableSubNodeTest.java
  (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeSubNodeTest.java
  (with props)

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/AbstractMergeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/AbstractMergeTest.java?view=auto&rev=156952
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/AbstractMergeTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/AbstractMergeTest.java
Thu Mar 10 06:33:08 2005
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api.version;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeManager;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * <code>AbstractMergeTest</code> is the abstract base class for all merge
+ * related test classes.
+ */
+public abstract class AbstractMergeTest extends AbstractJCRTest {
+
+    private static final String PROP_VERSIONABLE_NODE_TYPE = "versionableNodeType";
+
+    // global variable used in different tests
+
+    protected String versionableNodeType;
+    protected String nonVersionableNodeType;
+
+    /**
+     * The superuser session for the second workspace
+     */
+    protected Session superuserW2;
+
+    /**
+     * The default workspace
+     */
+    protected Workspace workspace;
+
+    /**
+     * The second workspace
+     */
+    protected Workspace workspaceW2;
+
+    /**
+     * The test root node in second workspace to test
+     */
+    protected Node testRootNodeW2;
+
+    /**
+     * The modified string to check
+     */
+    protected static final String CHANGED_STRING = "changed";
+
+    /**
+     * Initialising used variables coming from the properties file.<br> Setup
+     * some nodes on the 2 workspaces.<br>
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        NodeTypeManager ntm = superuser.getWorkspace().getNodeTypeManager();
+
+        // versionable node type
+        versionableNodeType = getProperty(PROP_VERSIONABLE_NODE_TYPE);
+        if (versionableNodeType == null) {
+            fail("Property '" + PROP_VERSIONABLE_NODE_TYPE + "' is not defined.");
+        }
+
+        NodeType vNt = ntm.getNodeType(versionableNodeType);
+        if (!vNt.isNodeType(mixVersionable)) {
+            fail("Property '" + PROP_VERSIONABLE_NODE_TYPE + "' does not define a versionable
nodetype.");
+        }
+
+        // non versionable node type
+        // test node type defines always a non versionable node type
+        nonVersionableNodeType = testNodeType;
+        if (nonVersionableNodeType == null) {
+            fail("Property '" + testNodeType + "' is not defined.");
+        }
+
+        NodeType nvNt = ntm.getNodeType(nonVersionableNodeType);
+        if (nvNt.isNodeType(mixVersionable)) {
+            fail("Property '" + testNodeType + "' does define a versionable nodetype.");
+        }
+
+        // initialise a new session on second workspace as superuser
+        superuserW2 = helper.getSuperuserSession(workspaceName);
+
+        workspace = superuser.getWorkspace();
+        workspaceW2 = superuserW2.getWorkspace();
+
+        // get/create test root node on second workspace
+        if (testPath.length() == 0) {
+            // test root is the root node
+            testRootNodeW2 = superuserW2.getRootNode();
+        } else if (!superuserW2.getRootNode().hasNode(testPath)) {
+            testRootNodeW2 = superuserW2.getRootNode().addNode(testPath, testNodeType);
+        } else {
+            testRootNodeW2 = superuserW2.getRootNode().getNode(testPath);
+        }
+
+        // initialize test nodes
+        initNodes();
+    }
+
+    /**
+     * Tidy the testRootNodes of both workspaces, then logout sessions
+     *
+     * @throws Exception
+     */
+    protected void tearDown() throws Exception {
+        // remove all test nodes in second workspace
+        if (superuserW2 != null) {
+            try {
+                if (!isReadOnly) {
+                    // do a 'rollback'
+                    superuserW2.refresh(false);
+                    Node rootW2 = superuserW2.getRootNode();
+                    if (rootW2.hasNode(testPath)) {
+                        // clean test root
+                        testRootNodeW2 = rootW2.getNode(testPath);
+                        for (NodeIterator children = testRootNodeW2.getNodes(); children.hasNext();)
{
+                            children.nextNode().remove();
+                        }
+                        rootW2.save();
+                    }
+                }
+            } finally {
+                superuserW2.logout();
+            }
+        }
+
+        super.tearDown();
+    }
+
+    // initialize nodes
+    abstract void initNodes() throws RepositoryException;
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/AbstractMergeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeCancelMergeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeCancelMergeTest.java?view=auto&rev=156952
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeCancelMergeTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeCancelMergeTest.java
Thu Mar 10 06:33:08 2005
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api.version;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.version.Version;
+
+/**
+ * <code>MergeCancelMergeTest</code> contains tests dealing with nodes on which
+ * cancelMerge is called.
+ *
+ * @test
+ * @sources MergeCancelMergeTest.java
+ * @executeClass org.apache.jackrabbit.test.api.version.MergeCancelMergeTest
+ * @keywords versioning
+ */
+public class MergeCancelMergeTest extends AbstractMergeTest {
+
+    /**
+     * node to merge
+     */
+    Node nodeToMerge;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        nodeToMerge = testRootNodeW2.getNode(nodeName1);
+        // node has to be checked out while merging
+        nodeToMerge.checkout();
+    }
+
+    /**
+     * 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 testMergeNodeCancelMerge() 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);
+        originalNode.checkout();
+        originalNode.checkin();
+
+        // second workspace
+        nodeToMerge.checkin();
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        nodeToMerge.checkout();
+        nodeToMerge.merge(workspace.getName(), true);
+
+        // get predecessors
+        Version[] predecessors = nodeToMerge.getBaseVersion().getPredecessors();
+        // get mergeFailed property
+        Property mergeFailedProperty = nodeToMerge.getProperty(jcrMergeFailed);
+        Value[] mergeFailedReferences = mergeFailedProperty.getValues();
+
+        Version bv = nodeToMerge.getBaseVersion();
+        nodeToMerge.cancelMerge(bv);
+
+        // check predecessors - unchanged
+        Version[] predecessorsAfterCancel = nodeToMerge.getBaseVersion().getPredecessors();
+        assertTrue(predecessors.length == predecessorsAfterCancel.length);
+
+        // check mergeFailed property - reference removed
+        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 {
+        // create a versionable node
+        // nodeName1
+        Node topVNode = testRootNode.addNode(nodeName1, versionableNodeType);
+        topVNode.setProperty(propertyName1, topVNode.getName());
+
+        // save default workspace
+        testRootNode.save();
+        topVNode.checkin();
+        topVNode.checkout();
+
+        log.println("test nodes created successfully on " + workspace.getName());
+
+        // clone the newly created node from src workspace into second workspace
+        workspaceW2.clone(workspace.getName(), topVNode.getPath(), topVNode.getPath(), true);
+        log.println(topVNode.getPath() + " cloned on " + superuserW2.getWorkspace().getName()
+ " at " + topVNode.getPath());
+
+        testRootNodeW2 = (Node) superuserW2.getItem(testRoot);
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeCancelMergeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeCheckedoutSubNodeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeCheckedoutSubNodeTest.java?view=auto&rev=156952
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeCheckedoutSubNodeTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeCheckedoutSubNodeTest.java
Thu Mar 10 06:33:08 2005
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api.version;
+
+import javax.jcr.MergeException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>MergeCheckedoutSubNodeTest</code> contains tests dealing with
+ * checked-out nodes in the subtree of the node on which merge is called.
+ *
+ * @test
+ * @sources MergeCheckedoutSubNodeTest.java
+ * @executeClass org.apache.jackrabbit.test.api.version.MergeCheckedoutSubNodeTest
+ * @keywords versioning
+ */
+public class MergeCheckedoutSubNodeTest extends AbstractMergeTest {
+
+    /**
+     * node to merge
+     */
+    Node nodeToMerge;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        nodeToMerge = testRootNodeW2.getNode(nodeName1);
+        // node has to be checked out while merging
+        nodeToMerge.checkout();
+    }
+
+    /**
+     * Node.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 testFailIfCorrespondingNodeIsSuccessor() throws RepositoryException {
+        try {
+            // make V' of a subnode N' in source workspace be a successor version of
+            // the base version of the corresponding subnode.
+            Node n = nodeToMerge.getNode(nodeName2);
+            n.checkout();
+            n.checkin();
+
+            n.checkout();
+
+            // merge, besteffort set to false to stop at the first failure
+            nodeToMerge.merge(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.
+     */
+    public void testLeaveIfCorrespondingNodeIsPredeccessor() 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 = testRootNode.getNode(nodeName1 + "/" + nodeName2);
+        n.checkout();
+        n.setProperty(propertyName1, CHANGED_STRING);
+        testRootNode.save();
+        n.checkin();
+
+        n.checkout();
+
+        // merge, besteffort set to false to stop at the first failure
+        nodeToMerge.merge(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 {
+        // create a versionable parent node
+        // nodeName1
+        Node topVNode = testRootNode.addNode(nodeName1, versionableNodeType);
+        topVNode.setProperty(propertyName1, topVNode.getName());
+
+        // create a versionable sub node
+        // nodeName1/nodeName2
+        Node subNvNode = topVNode.addNode(nodeName2, versionableNodeType);
+        subNvNode.setProperty(propertyName1, subNvNode.getName());
+
+        // save default workspace
+        testRootNode.save();
+
+        log.println("test nodes created successfully on " + workspace.getName());
+
+        // clone the newly created node from src workspace into second workspace
+        workspaceW2.clone(workspace.getName(), topVNode.getPath(), topVNode.getPath(), true);
+        log.println(topVNode.getPath() + " cloned on " + superuserW2.getWorkspace().getName()
+ " at " + topVNode.getPath());
+
+        testRootNodeW2 = (Node) superuserW2.getItem(testRoot);
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeCheckedoutSubNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeDoneMergeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeDoneMergeTest.java?view=auto&rev=156952
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeDoneMergeTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeDoneMergeTest.java
Thu Mar 10 06:33:08 2005
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api.version;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.version.Version;
+
+/**
+ * <code>MergeDoneMergeTest</code> contains test dealing with nodes on which
+ * doneMerge is called.
+ *
+ * @test
+ * @sources MergeDoneMergeTest.java
+ * @executeClass org.apache.jackrabbit.test.api.version.MergeDoneMergeTest
+ * @keywords versioning
+ */
+public class MergeDoneMergeTest extends AbstractMergeTest {
+    /**
+     * node to merge
+     */
+    Node nodeToMerge;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        nodeToMerge = testRootNodeW2.getNode(nodeName1);
+        // node has to be checked out while merging
+        nodeToMerge.checkout();
+
+    }
+
+    /**
+     * Node.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 testMergeNodeDoneMerge() 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);
+        originalNode.checkout();
+        originalNode.checkin();
+
+        // second workspace
+        nodeToMerge.checkin();
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        nodeToMerge.checkout();
+        nodeToMerge.merge(workspace.getName(), true);
+
+        // get predecessors
+        Version[] predecessors = nodeToMerge.getBaseVersion().getPredecessors();
+        // get mergeFailed property
+        Property mergeFailedProperty = nodeToMerge.getProperty(jcrMergeFailed);
+        Value[] mergeFailedReferences = mergeFailedProperty.getValues();
+
+        Version bv = nodeToMerge.getBaseVersion();
+        nodeToMerge.doneMerge(bv);
+
+        // check predecessors - added new predecessor
+        Version[] predecessorsAfterCancel = nodeToMerge.getBaseVersion().getPredecessors();
+        assertTrue(predecessors.length < predecessorsAfterCancel.length);
+
+        // check mergeFailed property - reference moved to predecessor
+        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 {
+        // create a versionable node
+        // nodeName1
+        Node topVNode = testRootNode.addNode(nodeName1, versionableNodeType);
+        topVNode.setProperty(propertyName1, topVNode.getName());
+
+        // save default workspace
+        testRootNode.save();
+        topVNode.checkin();
+        topVNode.checkout();
+
+        log.println("test nodes created successfully on " + workspace.getName());
+
+        // clone the newly created node from src workspace into second workspace
+        workspaceW2.clone(workspace.getName(), topVNode.getPath(), topVNode.getPath(), true);
+        log.println(topVNode.getPath() + " cloned on " + superuserW2.getWorkspace().getName()
+ " at " + topVNode.getPath());
+
+        testRootNodeW2 = (Node) superuserW2.getItem(testRoot);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeDoneMergeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNodeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNodeTest.java?view=auto&rev=156952
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNodeTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNodeTest.java
Thu Mar 10 06:33:08 2005
@@ -0,0 +1,242 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api.version;
+
+import javax.jcr.version.VersionException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Property;
+import javax.jcr.Value;
+import javax.jcr.MergeException;
+
+/**
+ * <code>MergeNodeTest</code> contains tests dealing with general merge node
+ * calls.
+ *
+ * @test
+ * @sources MergeNodeTest.java
+ * @executeClass org.apache.jackrabbit.test.api.version.MergeNodeTest
+ * @keywords versioning
+ */
+
+public class MergeNodeTest extends AbstractMergeTest {
+
+    /**
+     * node to merge
+     */
+    Node nodeToMerge;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        nodeToMerge = testRootNodeW2.getNode(nodeName1);
+        // node has to be checked out while merging
+        nodeToMerge.checkout();
+
+    }
+
+    /**
+     * Node.merge(): InvalidItemStateException if unsaved changes within the
+     * current Session<br>
+     */
+    public void testMergeNodeWithUnsavedStates() throws RepositoryException {
+        // set a property and do not save workspace
+        nodeToMerge.setProperty(propertyName1, CHANGED_STRING);
+        try {
+            nodeToMerge.merge(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 {
+        try {
+            nodeToMerge.merge(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>
+     */
+    public void testMergeNodeNonCorrespondingNode() 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();
+        subNode.checkin();
+
+        subNode.merge(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>
+     */
+    public void testMergeNodeVersionAmbiguous() 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);
+        originalNode.checkout();
+        originalNode.checkin();
+
+        // second workspace
+        nodeToMerge.checkin();
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        // besteffort set to false to stop at the first failure
+        try {
+            nodeToMerge.checkout();
+            nodeToMerge.merge(workspace.getName(), false);
+        } catch (VersionException e) {
+            // success if the version exception thrown
+        }
+    }
+
+    /**
+     * Node.merge(): bestEffort is true > any merge-failure (represented by the
+     * version in the workspace) is reported in the jcrMergeFailed property<br>
+     */
+    public void testMergeNodeBestEffortTrueCheckMergeFailedProperty() 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);
+        originalNode.checkout();
+        originalNode.checkin();
+
+        // second workspace
+        nodeToMerge.checkin();
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        // besteffort set to true to report all failures
+        nodeToMerge.checkout();
+        nodeToMerge.merge(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 testMergeNodeForceFailure() 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);
+        originalNode.checkout();
+        originalNode.checkin();
+
+        // second workspace
+        nodeToMerge.checkin();
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        // besteffort set to true to report all failures
+        nodeToMerge.checkout();
+        nodeToMerge.merge(workspace.getName(), true);
+
+        try {
+            nodeToMerge.merge(workspace.getName(), true);
+        } catch (VersionException e) {
+            // success version exception expected
+        }
+    }
+
+    /**
+     * Node.merge(): bestEffort is false and any merge fails a MergeException is
+     * thrown.<br>
+     */
+    public void testMergeNodeBestEffortFalse() 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);
+        originalNode.checkout();
+        originalNode.checkin();
+
+        // second workspace
+        nodeToMerge.checkin();
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        // besteffort set to true to report all failures
+        nodeToMerge.checkout();
+
+        // merge, besteffort set to false
+        try {
+            nodeToMerge.merge(workspace.getName(), false);
+            fail("bestEffort is false and any merge should throw a MergeException.");
+        } catch (MergeException e) {
+            // successful
+        }
+    }
+
+
+    /**
+     * initialize a versionable node on default and second workspace
+     */
+    protected void initNodes() throws RepositoryException {
+        // create a versionable node
+        // nodeName1
+        Node topVNode = testRootNode.addNode(nodeName1, versionableNodeType);
+        topVNode.setProperty(propertyName1, topVNode.getName());
+
+        // save default workspace
+        testRootNode.save();
+        topVNode.checkin();
+        topVNode.checkout();
+
+        log.println("test nodes created successfully on " + workspace.getName());
+
+        // clone the newly created node from src workspace into second workspace
+        workspaceW2.clone(workspace.getName(), topVNode.getPath(), topVNode.getPath(), true);
+        log.println(topVNode.getPath() + " cloned on " + superuserW2.getWorkspace().getName()
+ " at " + topVNode.getPath());
+
+        testRootNodeW2 = (Node) superuserW2.getItem(testRoot);
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNonVersionableSubNodeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNonVersionableSubNodeTest.java?view=auto&rev=156952
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNonVersionableSubNodeTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNonVersionableSubNodeTest.java
Thu Mar 10 06:33:08 2005
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api.version;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+
+/**
+ * <code>MergeNonVersionableSubNodeTest</code> contains test dealing with
+ * nonversionable nodes in the subtree of the node on which merge is called.
+ *
+ * @test
+ * @sources MergeNonVersionableSubNodeTest.java
+ * @executeClass org.apache.jackrabbit.test.api.version.MergeNonVersionableSubNodeTest
+ * @keywords versioning
+ */
+public class MergeNonVersionableSubNodeTest extends AbstractMergeTest {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    /**
+     * Node.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 testMergeNodeNonVersionableSubNodeNonVersionableAncestor() 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.save();
+        nodeToMerge.merge(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>
+     */
+    public void testMergeNodeNonVersionableSubNodeUpdate() throws RepositoryException {
+        // modify non versionable subnode so we can check if it's updated after merge
+        String nvSubNodePath = nodeName1 + "/" + nodeName2 + "/" + nodeName3;
+        Node nvSubNode = testRootNodeW2.getNode(nvSubNodePath);
+        nvSubNode.setProperty(propertyName1, CHANGED_STRING);
+        superuserW2.save();
+
+        // versionable ancestor to merge in second workspace
+        Node nodeToMerge = testRootNodeW2.getNode(nodeName1);
+
+        // make sure the ancestor will get status 'update' on merge: V is predeccessor of
V'
+        nodeToMerge.checkout();
+        nodeToMerge.checkin();
+
+        nodeToMerge.checkout();
+        nodeToMerge.merge(workspace.getName(), true);
+
+        // corresponding node to nvSubNode in default workspace
+        Node correspondingSubNode = testRootNode.getNode(nvSubNodePath);
+
+        // test if modification on non-v node is done according to corresponding node.
+        assertTrue(nvSubNode.getProperty(propertyName1).getString().equals(correspondingSubNode.getName()));
+    }
+
+    /**
+     * Node.merge(): nonversionable subNode N: is left unchanged if the nearest
+     * versionable ancestor has state leave.<br>
+     */
+    public void testMergeNodeNonVersionableSubNodeLeave() throws RepositoryException {
+        // modify non versionable subnode so we can check if it's updated after merge
+        String nvSubNodePath = nodeName1 + "/" + nodeName2 + "/" + nodeName3;
+        Node nvSubNode = testRootNodeW2.getNode(nvSubNodePath);
+        nvSubNode.setProperty(propertyName1, CHANGED_STRING);
+        superuserW2.save();
+
+        // versionable ancestor to merge in second workspace
+        Node nodeToMerge = testRootNodeW2.getNode(nodeName1);
+
+        // make sure the ancestor will get status 'leave' on merge: V is successor of V'
+        Node correspondingNodeToMerge = testRootNode.getNode(nodeName1);
+        correspondingNodeToMerge.checkout();
+        correspondingNodeToMerge.checkin();
+
+        nodeToMerge.checkout();
+        nodeToMerge.merge(workspace.getName(), true);
+
+        // test if modification on non-v node is unchanged.
+        assertTrue(nvSubNode.getProperty(propertyName1).getString().equals(CHANGED_STRING));
+    }
+
+    /**
+     * initialize a three-step-hierarchy on default and second workspace
+     */
+    protected void initNodes() throws RepositoryException {
+        // create a versionable parent node
+        // nodeName1
+        Node topVNode = testRootNode.addNode(nodeName1, versionableNodeType);
+        topVNode.setProperty(propertyName1, topVNode.getName());
+
+        // create a non'versionable sub node
+        // nodeName1/nodeName2
+        Node subNvNode = topVNode.addNode(nodeName2, testNodeType);
+        subNvNode.setProperty(propertyName1, subNvNode.getName());
+
+        // create a non'versionable sub node below nonversionable node
+        // nodeName1/nodeName2/nodeName3
+        Node subSubNvNode = subNvNode.addNode(nodeName3, testNodeType);
+        subSubNvNode.setProperty(propertyName1, subSubNvNode.getName());
+
+        // save default workspace
+        testRootNode.save();
+
+        log.println("test nodes created successfully on " + workspace.getName());
+
+        // clone the newly created node from src workspace into second workspace
+        workspaceW2.clone(workspace.getName(), topVNode.getPath(), topVNode.getPath(), true);
+        log.println(topVNode.getPath() + " cloned on " + superuserW2.getWorkspace().getName()
+ " at " + topVNode.getPath());
+
+        testRootNodeW2 = (Node) superuserW2.getItem(testRoot);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNonVersionableSubNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeSubNodeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeSubNodeTest.java?view=auto&rev=156952
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeSubNodeTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeSubNodeTest.java
Thu Mar 10 06:33:08 2005
@@ -0,0 +1,210 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api.version;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>MergeSubNodeTest</code> contains tests dealing with sub nodes in the
+ * subtree of the node on which merge is called.
+ *
+ * @test
+ * @sources MergeSubNodeTest.java
+ * @executeClass org.apache.jackrabbit.test.api.version.MergeSubNodeTest
+ * @keywords versioning
+ */
+
+public class MergeSubNodeTest extends AbstractMergeTest {
+
+    /**
+     * node to merge
+     */
+    Node nodeToMerge;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        nodeToMerge = testRootNodeW2.getNode(nodeName1);
+        // node has to be checked out while merging
+        nodeToMerge.checkout();
+
+    }
+
+    /**
+     * Node.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 testRemoveNodeFromSourceWorkspaceAndMergeWithUpdate() throws RepositoryException
{
+        // status 'update' for parent
+        nodeToMerge.checkin();
+        nodeToMerge.checkout();
+
+        // status 'leave' for subnode
+        Node originalNode = testRootNode.getNode(nodeName1);
+        Node originalSubNode = originalNode.getNode(nodeName2);
+        originalSubNode.checkout();
+        originalSubNode.checkin();
+
+        // "merge" the nodeToMerge with the newNode from the default workspace
+        // besteffort set to false to stop at the first failure
+        nodeToMerge.merge(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 originalBaseVersionUUID = originalNode.getBaseVersion().getUUID();
+        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));
+    }
+
+    /**
+     * 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
+     * workspace1 precondition is that the node in workspace2 is checked in
+     */
+    public void testMergeNodeFromUpdatedSourceWorkspace() throws RepositoryException {
+        Node originalNode = testRootNode.getNode(nodeName1);
+
+        // update nodeName1 on workspace1
+        originalNode.checkout();
+        originalNode.checkin();
+
+        testRootNode.save();
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        // besteffort set to false to stop at the first failure
+        nodeToMerge.merge(workspace.getName(), false);
+
+        final String originalBaseVersionUUID = originalNode.getBaseVersion().getUUID();
+        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));
+
+    }
+
+    /**
+     * Node.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 testMergeNodeFromOlderSourceWorkspace() throws RepositoryException {
+        // touch the version on workspace2
+        nodeToMerge.checkin();
+        nodeToMerge.checkout();
+
+        String baseVersionUUIDbeforeMerge = nodeToMerge.getBaseVersion().getUUID();
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        // besteffort set to false to stop at the first failure
+        nodeToMerge.merge(workspace.getName(), false);
+
+        assertTrue("clonedNode has different UUID than expected, it should be left unchanged",
baseVersionUUIDbeforeMerge.equals(nodeToMerge.getBaseVersion().getUUID()));
+    }
+
+    /**
+     * Node.merge(): bestEffort is true > (sub)node which could not be merged
+     * are not affected.<br>
+     */
+    public void testMergeNodeBestEffortTrue() throws RepositoryException {
+        // create 2 new nodes with two independent versions
+        // so merge fails for this node
+        Node originalNode = testRootNode.getNode(nodeName1);
+        originalNode.checkout();
+        Node subNode = originalNode.getNode(nodeName2);
+        // will be unchanged after merge
+        subNode.checkout();
+        subNode.setProperty(propertyName1, CHANGED_STRING);
+        // will be updated
+        originalNode.setProperty(propertyName1, CHANGED_STRING);
+        superuser.save();
+        subNode.checkin();
+        originalNode.checkin();
+
+        Node subNodeW2 = nodeToMerge.getNode(nodeName2);
+        subNodeW2.checkout();
+        subNodeW2.setProperty(propertyName1, CHANGED_STRING);
+        superuserW2.save();
+        subNodeW2.checkin();
+
+        nodeToMerge.checkout();
+
+        // merge, besteffort set to true
+        nodeToMerge.merge(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>
+     */
+    public void testMergeNodeSubNodesMergeTest() throws RepositoryException {
+        //setCheckProperty(nodeToMerge);
+        nodeToMerge.checkout();
+
+        nodeToMerge.merge(workspace.getName(), true);
+
+        // check subnodes if they were touched
+        for (NodeIterator ni = nodeToMerge.getNodes(); ni.hasNext();) {
+            Node n = ni.nextNode();
+            if (n.getBaseVersion() != null) {
+                assertTrue(n.getProperty(propertyName1).getString().equals(CHANGED_STRING));
+            }
+        }
+    }
+
+    /**
+     * initialize a two-step-hierarchy on default and second workspace
+     */
+    protected void initNodes() throws RepositoryException {
+        // create a versionable parent node
+        // nodeName1
+        Node topVNode = testRootNode.addNode(nodeName1, versionableNodeType);
+        topVNode.setProperty(propertyName1, topVNode.getName());
+
+        // create a versionable sub node
+        // nodeName1/nodeName2
+        Node subNvNode = topVNode.addNode(nodeName2, versionableNodeType);
+        subNvNode.setProperty(propertyName1, subNvNode.getName());
+
+        // save default workspace
+        testRootNode.save();
+
+        log.println("test nodes created successfully on " + workspace.getName());
+
+        // clone the newly created node from src workspace into second workspace
+        workspaceW2.clone(workspace.getName(), topVNode.getPath(), topVNode.getPath(), true);
+        log.println(topVNode.getPath() + " cloned on " + superuserW2.getWorkspace().getName()
+ " at " + topVNode.getPath());
+
+        testRootNodeW2 = (Node) superuserW2.getItem(testRoot);
+    }
+
+}

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeSubNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message