jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r157794 [1/2] - in incubator/jackrabbit/trunk: applications/test/ applications/test/repository/nodetypes/ src/test/org/apache/jackrabbit/test/api/
Date Wed, 16 Mar 2005 20:01:53 GMT
Author: mreutegg
Date: Wed Mar 16 12:01:45 2005
New Revision: 157794

URL: http://svn.apache.org/viewcvs?view=rev&rev=157794
Log:
Test cases for Workspace methods: clone, copy, move

Added:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyBetweenTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceReferenceableTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceSameNameSibsTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceVersionableTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneReferenceableTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneSameNameSibsTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneVersionableTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesReferenceableTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesSameNameSibsTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesVersionableTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyReferenceableTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopySameNameSibsTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyVersionableTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceMoveReferenceableTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceMoveSameNameSibsTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceMoveTest.java   (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceMoveVersionableTest.java   (with props)
Modified:
    incubator/jackrabbit/trunk/applications/test/repository/nodetypes/custom_nodetypes.xml
    incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java

Modified: incubator/jackrabbit/trunk/applications/test/repository/nodetypes/custom_nodetypes.xml
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/applications/test/repository/nodetypes/custom_nodetypes.xml?view=diff&r1=157793&r2=157794
==============================================================================
--- incubator/jackrabbit/trunk/applications/test/repository/nodetypes/custom_nodetypes.xml (original)
+++ incubator/jackrabbit/trunk/applications/test/repository/nodetypes/custom_nodetypes.xml Wed Mar 16 12:01:45 2005
@@ -210,6 +210,19 @@
     <propertyDef name="test:multiProperty" requiredType="undefined" autoCreate="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="true" />
     <childNodeDef name="*" defaultPrimaryType="test:setProperty" autoCreate="false" mandatory="false" onParentVersion="COPY" protected="false" sameNameSibs="false" />
   </nodeType>
+  
+  <!-- Defines a nodetype with a ChildNodeDef that does not allow same name siblings -->
+  <nodeType name="test:sameNameSibsFalseChildNodeDef" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+    <supertypes>
+      <supertype>nt:base</supertype>
+    </supertypes>
+    <propertyDef name="*" requiredType="undefined" autoCreate="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false"/>
+    <childNodeDef name="*" defaultPrimaryType="test:sameNameSibsFalseChildNodeDef" autoCreate="false" mandatory="false" onParentVersion="COMPUTE" protected="false" sameNameSibs="false">
+      <requiredPrimaryTypes>
+        <requiredPrimaryType>nt:base</requiredPrimaryType>
+      </requiredPrimaryTypes>
+    </childNodeDef>
+  </nodeType>  
 
 </nodeTypes>
 

Modified: incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties?view=diff&r1=157793&r2=157794
==============================================================================
--- incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties (original)
+++ incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.properties Wed Mar 16 12:01:45 2005
@@ -195,6 +195,22 @@
 javax.jcr.tck.SetPropertyStringTest.propertyname2=test:multiProperty
 javax.jcr.tck.SetPropertyStringTest.nodetype=test:setProperty
 
+# Test class: WorkspaceCloneSameNameSibsTest
+javax.jcr.tck.WorkspaceCloneSameNameSibsTest.sameNameSibsFalseNodeType=test:sameNameSibsFalseChildNodeDef
+javax.jcr.tck.WorkspaceCloneSameNameSibsTest.sameNameSibsTrueNodeType=nt:unstructured
+
+# Test class: WorkspaceCopyBetweenWorkspacesSameNameSibsTest
+javax.jcr.tck.WorkspaceCopyBetweenWorkspacesSameNameSibsTest.sameNameSibsFalseNodeType=test:sameNameSibsFalseChildNodeDef
+javax.jcr.tck.WorkspaceCopyBetweenWorkspacesSameNameSibsTest.sameNameSibsTrueNodeType=nt:unstructured
+
+# Test class: WorkspaceCopySameNameSibsTest
+javax.jcr.tck.WorkspaceCopySameNameSibsTest.sameNameSibsFalseNodeType=test:sameNameSibsFalseChildNodeDef
+javax.jcr.tck.WorkspaceCopySameNameSibsTest.sameNameSibsTrueNodeType=nt:unstructured
+
+# Test class: WorkspaceMoveSameNameSibsTest
+javax.jcr.tck.WorkspaceMoveSameNameSibsTest.sameNameSibsFalseNodeType=test:sameNameSibsFalseChildNodeDef
+javax.jcr.tck.WorkspaceMoveSameNameSibsTest.sameNameSibsTrueNodeType=nt:unstructured
+
 # ------------------------------------------------------------------------------
 # observation configuration
 # ------------------------------------------------------------------------------

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyBetweenTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyBetweenTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyBetweenTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyBetweenTest.java Wed Mar 16 12:01:45 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;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+
+/**
+ * <code>AbstractWorkspaceCopyCloneBetweenWorkspacesTest</code> is the abstract
+ * base class for all copying and cloning related test classes between
+ * workspaces.
+ */
+abstract class AbstractWorkspaceCopyBetweenTest extends AbstractWorkspaceCopyTest {
+
+    /**
+     * The superuser session for the non default workspace
+     */
+    protected Session superuserW2;
+
+    /**
+     * The workspace in the non default session.
+     */
+    Workspace workspaceW2;
+
+    /**
+     * The testroot node in the non default session
+     */
+    Node testRootNodeW2;
+
+    /**
+     * A referenceable node in default workspace
+     */
+    protected Node node1W2;
+
+    /**
+     * A non-referenceable node in default workspace
+     */
+    protected Node node2W2;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // init second workspace
+        superuserW2 = helper.getSuperuserSession(workspaceName);
+        workspaceW2 = superuserW2.getWorkspace();
+
+        initNodesW2();
+    }
+
+    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();) {
+                            Node n = children.nextNode();
+                            n.remove();
+                        }
+                        superuserW2.save();
+                    }
+                }
+            } finally {
+                superuserW2.logout();
+            }
+        }
+        super.tearDown();
+    }
+
+
+    private void initNodesW2() throws RepositoryException {
+
+        // testroot
+        if (superuserW2.getRootNode().hasNode(testPath)) {
+            testRootNodeW2 = superuserW2.getRootNode().getNode(testPath);
+        } else {
+            testRootNodeW2 = superuserW2.getRootNode().addNode(testPath, testNodeType);
+            superuserW2.save();
+        }
+
+        // some test nodes
+        superuserW2.getWorkspace().copy(workspace.getName(), node1.getPath(), node1.getPath());
+        node1W2 = testRootNodeW2.getNode(node1.getName());
+
+        superuserW2.getWorkspace().copy(workspace.getName(), node2.getPath(), node2.getPath());
+        node2W2 = testRootNodeW2.getNode(node2.getName());
+
+        testRootNodeW2.save();
+    }
+}

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,79 @@
+/*
+ * 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;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Workspace;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * <code>AbstractWorkspaceCopyTest</code> is the abstract base class for all
+ * copying/moving related test classes in one workspace.
+ */
+abstract class AbstractWorkspaceCopyTest extends AbstractJCRTest {
+
+    /**
+     * A referenceable node in default workspace
+     */
+    protected Node node1;
+
+    /**
+     * A non-referenceable node in default workspace
+     */
+    protected Node node2;
+
+
+    /**
+     * The workspace in the default session.
+     */
+    Workspace workspace;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        initNodes();
+
+        workspace = superuser.getWorkspace();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+
+    /**
+     * Build persistent referenceable and non-referenceable nodes<br>
+     */
+    private void initNodes() {
+        // create a referenceable node
+        try {
+            node1 = testRootNode.addNode(nodeName1, testNodeType);
+        } catch (RepositoryException e) {
+            fail("Failed to create test node." + e.getMessage());
+        }
+        // create a non-referenceable node
+        try {
+            node2 = testRootNode.addNode(nodeName2, testNodeType);
+            testRootNode.save();
+        } catch (RepositoryException e) {
+            fail("Failed to createtest node." + e.getMessage());
+        }
+    }
+
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceReferenceableTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceReferenceableTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceReferenceableTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceReferenceableTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeManager;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+/**
+ * <code>AbstractWorkspaceReferenceableTest</code> is the abstract base class for all
+ * copying/moving/cloning related test classes with referenceable nodes in workspace.
+ */
+abstract class AbstractWorkspaceReferenceableTest extends AbstractWorkspaceCopyBetweenTest {
+
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // we assume referencing is supported by repository
+        NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
+
+        // assert that this repository supports references
+        try {
+            NodeType referenceableNt = ntMgr.getNodeType(mixReferenceable);
+            if (referenceableNt == null) {
+                throw new NotExecutableException("Repository does not support Referencing: mixin nodetype '" + mixReferenceable + "' is missing.");
+            }
+        } catch (NoSuchNodeTypeException e) {
+            throw new NotExecutableException("Repository does not support Referencing: mixin nodetype '" + mixReferenceable + "' is missing.");
+        }
+    }
+
+    /**
+     * add the mix:referenceable mixin type to a node.
+     *
+     * @param parent
+     * @param node
+     * @return referenceable node.
+     */
+    protected Node addMixinReferenceableToNode(Node parent, Node node) throws RepositoryException {
+        NodeType nodetype = node.getPrimaryNodeType();
+        if (!nodetype.isNodeType(mixReferenceable)) {
+            node.addMixin(mixReferenceable);
+        }
+        parent.save();
+
+        return node;
+    }
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceSameNameSibsTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceSameNameSibsTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceSameNameSibsTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceSameNameSibsTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,106 @@
+/*
+ * 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;
+
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeDef;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeManager;
+
+import org.apache.jackrabbit.test.NotExecutableException;
+
+/**
+ * <code>AbstractWorkspaceSameNameSibsTest</code> is the abstract base class for
+ * all copying/moving/cloning related test classes with samename siblings
+ * allowed in workspace.
+ */
+abstract class AbstractWorkspaceSameNameSibsTest extends AbstractWorkspaceCopyBetweenTest {
+
+    /**
+     * Node type with sameNameSibs=true ChildNodeDef
+     */
+    protected final String PROP_SAME_NAME_SIBS_TRUE_NODE_TYPE = "sameNameSibsTrueNodeType";
+
+    /**
+     * Node type with sameNameSibs=false ChildNodeDef
+     */
+    protected final String PROP_SAME_NAME_SIBS_FALSE_NODE_TYPE = "sameNameSibsFalseNodeType";
+
+    /**
+     * A node type where same-name siblings are allowed
+     */
+    protected NodeType sameNameSibsTrueNodeType;
+
+    /**
+     * A node type where NO same-name siblings allowed
+     */
+    protected NodeType sameNameSibsFalseNodeType;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // we assume sameNameSibs is supported by repository
+        NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
+
+        // sameNameSibs ALLOWED
+        // make sure 'sameNameSibsTrue' nodetype is properly defined
+        try {
+            sameNameSibsTrueNodeType = ntMgr.getNodeType(getProperty(PROP_SAME_NAME_SIBS_TRUE_NODE_TYPE));
+            if (sameNameSibsTrueNodeType == null) {
+                fail("Property 'sameNameSibsTrueNodeType' does not define a nodetype where sameNameSibs are allowed: '" + sameNameSibsTrueNodeType.getName() + "'");
+            } else {
+                NodeDef[] childNodeDefs = sameNameSibsTrueNodeType.getDeclaredChildNodeDefs();
+                boolean isSameNameSibs = false;
+                for (int i = 0; i < childNodeDefs.length; i++) {
+                    if (childNodeDefs[i].allowSameNameSibs()) {
+                        isSameNameSibs = true;
+                        break;
+                    }
+                }
+                if (!isSameNameSibs) {
+                    throw new NotExecutableException("Property 'sameNameSibsTrueNodeType' does not define a nodetype where sameNameSibs are allowed: '" + sameNameSibsTrueNodeType.getName() + "'");
+                }
+            }
+        } catch (NoSuchNodeTypeException e) {
+            fail("Property 'sameNameSibsTrueNodeType' does not define an existing nodetype: '" + sameNameSibsTrueNodeType + "'");
+        }
+
+        // sameNameSibs NOT ALLOWED
+        // make sure 'sameNameSibsFalse' nodetype is properly defined
+        try {
+            sameNameSibsFalseNodeType = ntMgr.getNodeType(getProperty(PROP_SAME_NAME_SIBS_FALSE_NODE_TYPE));
+            if (sameNameSibsFalseNodeType == null) {
+                fail("Property 'sameNameSibsFalseNodeType' does define a nodetype where sameNameSibs are allowed: '" + sameNameSibsFalseNodeType.getName() + "'");
+            } else {
+                NodeDef[] childNodeDefs = sameNameSibsFalseNodeType.getDeclaredChildNodeDefs();
+                boolean isSameNameSibs = true;
+                for (int i = 0; i < childNodeDefs.length; i++) {
+                    if (!childNodeDefs[i].allowSameNameSibs()) {
+                        isSameNameSibs = false;
+                        break;
+                    }
+                }
+                if (isSameNameSibs) {
+                    fail("Property 'sameNameSibsFalseNodeType' does define a nodetype where sameNameSibs are allowed: '" + sameNameSibsFalseNodeType.getName() + "'");
+                }
+            }
+        } catch (NoSuchNodeTypeException e) {
+            fail("Property 'sameNameSibsFalseNodeType' does not define an existing nodetype: '" + sameNameSibsFalseNodeType + "'");
+        }
+
+    }
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceVersionableTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceVersionableTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceVersionableTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/AbstractWorkspaceVersionableTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeManager;
+
+import org.apache.jackrabbit.test.NotExecutableException;
+
+/**
+ * <code>AbstractWorkspaceReferenceableTest</code> is the abstract base class
+ * for all copying/moving/cloning related test classes with versionable nodes in
+ * workspace.
+ */
+abstract class AbstractWorkspaceVersionableTest extends AbstractWorkspaceCopyBetweenTest {
+
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // we assume versioning is supported by repository
+        NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
+
+        // assert that this repository supports versioning
+        try {
+            NodeType versionableNt = ntMgr.getNodeType(mixVersionable);
+            if (versionableNt == null) {
+                throw new NotExecutableException("Repository does not support versioning: mixin nodetype '" + mixVersionable + "' is missing.");
+            }
+        } catch (NoSuchNodeTypeException e) {
+            throw new NotExecutableException("Repository does not support versioning: mixin nodetype '" + mixVersionable + "' is missing.");
+        }
+    }
+
+    /**
+     * add the mix:versionable mixin type to a node.
+     */
+    protected Node addMixinVersionableToNode(Node parent, Node node) throws RepositoryException {
+        NodeType nodetype = node.getPrimaryNodeType();
+        if (!nodetype.isNodeType(mixVersionable)) {
+            node.addMixin(mixVersionable);
+        }
+        parent.save();
+
+        return node;
+    }
+}
\ No newline at end of file

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

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java?view=diff&r1=157793&r2=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java Wed Mar 16 12:01:45 2005
@@ -99,6 +99,23 @@
         suite.addTestSuite(NodeCanAddMixinTest.class);
         suite.addTestSuite(NodeRemoveMixinTest.class);
 
+        suite.addTestSuite(WorkspaceCloneReferenceableTest.class);
+        suite.addTestSuite(WorkspaceCloneSameNameSibsTest.class);
+        suite.addTestSuite(WorkspaceCloneTest.class);
+        suite.addTestSuite(WorkspaceCloneVersionableTest.class);
+        suite.addTestSuite(WorkspaceCopyBetweenWorkspacesReferenceableTest.class);
+        suite.addTestSuite(WorkspaceCopyBetweenWorkspacesSameNameSibsTest.class);
+        suite.addTestSuite(WorkspaceCopyBetweenWorkspacesTest.class);
+        suite.addTestSuite(WorkspaceCopyBetweenWorkspacesVersionableTest.class);
+        suite.addTestSuite(WorkspaceCopyReferenceableTest.class);
+        suite.addTestSuite(WorkspaceCopySameNameSibsTest.class);
+        suite.addTestSuite(WorkspaceCopyTest.class);
+        suite.addTestSuite(WorkspaceCopyVersionableTest.class);
+        suite.addTestSuite(WorkspaceMoveReferenceableTest.class);
+        suite.addTestSuite(WorkspaceMoveSameNameSibsTest.class);
+        suite.addTestSuite(WorkspaceMoveTest.class);
+        suite.addTestSuite(WorkspaceMoveVersionableTest.class);
+
         return suite;
     }
 }

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneReferenceableTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneReferenceableTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneReferenceableTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneReferenceableTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,133 @@
+/*
+ * 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;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>WorkspaceCloneReferenceableTest</code> contains tests for cloning
+ * referenceable nodes between workspaces.
+ *
+ * @test
+ * @sources WorkspaceCloneReferenceableTest.java
+ * @executeClass org.apache.jackrabbit.test.api.WorkspaceCloneReferenceableTest
+ * @keywords level2
+ */
+public class WorkspaceCloneReferenceableTest extends AbstractWorkspaceReferenceableTest {
+
+    /**
+     * In the case of referenceable nodes clone preserves the node's UUID so
+     * that the new node in the destination workspcace has the same UUID as the
+     * node in the source workspace.
+     */
+    public void testCloneNodesReferenceableNodesOriginalUUID() throws RepositoryException {
+        // add mixin referenceable to node1
+        addMixinReferenceableToNode(testRootNode, node1);
+
+        // copy referenceable node below non-referenceable node
+        String dstAbsPath = node2W2.getPath() + "/" + node1.getName();
+        workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true);
+
+        // uuid of copied node should be different than original node uuid
+        String originalUUID = node1.getUUID();
+        Node copiedNode = node2W2.getNode(node1.getName());
+        String copiedUUID = copiedNode.getUUID();
+
+        assertTrue(originalUUID.equals(copiedUUID));
+    }
+
+    /**
+     * If removeExisting is true then the existing node is removed from its
+     * current location and the cloned node with the same UUID from srcWorkspace
+     * is copied to this workspace as part of the copied subtree (that is, not
+     * into the former location of the old node). The subtree of the cloned node
+     * will reflect the clones state in srcWorkspace, in other words the
+     * existing node will be moved and changed.
+     */
+    public void testCloneNodesRemoveExistingTrue() throws RepositoryException {
+        // add mixin referenceable to node1
+        /*addMixinReferenceableToNode(testRootNode, node1);
+
+        // clone a node from default workspace to have the same uuid on second workspace
+        String dstAbsPath = node2W2.getPath() + "/" + nodeName2;
+        workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true);
+        Node clonedNode = node2W2.getNode(nodeName2);
+
+        // clone node1 from default workspace to second workspace
+        dstAbsPath = node2W2.getPath() + "/" + nodeName3;
+        //@TODO: Testcase corrupts workspace and functionality is not implemented right now, so it's commented.
+        workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true);
+        Node clonedNode2 = node2W2.getNode(nodeName3);
+
+        // because a node with same uuid exists (cloned node in earlier step - nodeName2), the existing node (and its subtree)
+        // should be removed ...
+        assertFalse(testRootNodeW2.hasNode(clonedNode.getName()));
+
+        // ... and is copied to this workspace as part of the copied subtree (that is, not into the former location of the old node).
+        Node clonedNodeMoved = clonedNode2.getNode(clonedNode.getName());
+        assertTrue(testRootNodeW2.hasNode(clonedNodeMoved.getName()));*/
+        fail("Testcase corrupts workspace, so it's commented.");
+    }
+
+    /**
+     * If removeExisting is false then a UUID collision causes this method to
+     * throw a ItemExistsException and no changes are made.
+     */
+    public void testCloneNodesRemoveExistingFalse() throws RepositoryException {
+        // add mixin referenceable to node1
+        /*addMixinReferenceableToNode(testRootNode, node1);
+
+        // clone a node from default workspace to have the same uuid on second workspace
+        workspaceW2.clone(workspace.getName(), node1.getPath(), testRootNodeW2.getPath() + "/" + nodeName2, false);
+
+        // clone node1 from default workspace to second workspace
+        try {
+            //@TODO: Testcase corrupts workspace, so it's commented.
+            workspaceW2.clone(workspace.getName(), node1.getPath(), testRootNodeW2.getPath() + "/" + nodeName3, false);
+            fail("If removeExisting is false then a UUID collision should throw a ItemExistsException");
+        } catch (ItemExistsException e) {
+            // successful
+        } */
+
+        fail("Testcase corrupts workspace, so it's commented.");
+    }
+
+    /**
+     * The clone method clones both referenceable and nonreferenceable nodes.
+     */
+    public void testCloneNodesReferenceableAndNonreferenceable() throws RepositoryException {
+        // clone referenceable node
+
+        // add mixin referenceable to node1
+        addMixinReferenceableToNode(testRootNode, node1);
+        if (node1.isNodeType(mixReferenceable)) {
+            workspaceW2.clone(workspace.getName(), node1.getPath(), testRootNodeW2.getPath() + "/" + nodeName2, false);
+        } else {
+            fail("Node should be referenceable.");
+        }
+
+        // clone nonreferenceable node
+        if (node2.isNodeType(mixReferenceable)) {
+            fail("Node should not be referenceable.");
+        } else {
+            workspaceW2.clone(workspace.getName(), node2.getPath(), testRootNodeW2.getPath() + "/" + nodeName2, false);
+            assertTrue(testRootNodeW2.hasNode(nodeName2));
+        }
+    }
+
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneSameNameSibsTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneSameNameSibsTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneSameNameSibsTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneSameNameSibsTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,87 @@
+/*
+ * 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;
+
+import javax.jcr.ItemExistsException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>WorkspaceCloneSameNameSibsTest</code> contains tests for cloning nodes
+ * as same name siblings between workspace.
+ *
+ * @test
+ * @sources WorkspaceCloneSameNameSibsTest.java
+ * @executeClass org.apache.jackrabbit.test.api.WorkspaceCopySameNameSibsTest
+ * @keywords level2
+ */
+public class WorkspaceCloneSameNameSibsTest extends AbstractWorkspaceSameNameSibsTest {
+
+    /**
+     * If ordering is supported by the node type of the parent node of the new
+     * location, then the newly moved node is appended to the end of the child
+     * node list.
+     */
+    public void testCloneNodesOrderingSupportedByParent() throws RepositoryException {
+        // test assumes that repositry supports Orderable Child Node Support (optional)
+        /*String[] orderList = {nodeName1, nodeName2, nodeName3};
+
+        // copy node three times below a node and check the order
+        for (int i = 0; i < orderList.length; i++) {
+            workspaceW2.clone(workspace.getName(), node1.getPath(), node2.getPath() + "/" + orderList[i], true);
+        }
+
+
+        // check regarding orderList with the counter if nodes are added at the end
+        int cnt = 0;
+        NodeIterator iter = node2.getNodes();
+        while (iter.hasNext()) {
+            Node n = (Node) iter.nextNode();
+
+            assertTrue(n.getName().equals(orderList[cnt]));
+            cnt++;
+        } */
+        //@TODO: Testcase corrupts workspace, so it's commented.
+        fail("Testcase corrupts workspace, so it's commented.");
+    }
+
+    /**
+     * An ItemExistsException is thrown if a node or property already exists at
+     * destAbsPath.
+     * @tck.config sameNameSibsFalseNodeType name of a node type that does not
+     * allows same name siblings.
+     * @tck.config nodeName3 name of a child node that does not allow same name
+     * siblings..
+     */
+    public void testCloneNodesNodeExistsAtDestPath() throws RepositoryException {
+        // create a parent node where allowSameNameSiblings are set to false
+        Node snsfNode = testRootNodeW2.addNode(nodeName3, sameNameSibsFalseNodeType.getName());
+        testRootNodeW2.save();
+
+        String dstAbsPath = snsfNode.getPath() + "/" + node1W2.getName();
+        workspaceW2.copy(node1W2.getPath(), dstAbsPath);
+
+        // try to copy again the node to same destAbsPath
+        // property already exist
+        try {
+            workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true);
+            fail("Node exists below '" + dstAbsPath + "'. Test should fail.");
+        } catch (ItemExistsException e) {
+            // successful
+        }
+    }
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,172 @@
+/*
+ * 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;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.lock.LockException;
+
+/**
+ * <code>WorkspaceCloneTest</code> contains tests for cloning nodes between
+ * workspace.
+ *
+ * @test
+ * @sources WorkspaceCloneTest.java
+ * @executeClass org.apache.jackrabbit.test.api.WorkspaceCloneTest
+ * @keywords level2
+ */
+public class WorkspaceCloneTest extends AbstractWorkspaceCopyBetweenTest {
+
+    /**
+     * If successful, the changes are persisted immediately, there is no need to
+     * call save.
+     */
+    public void testCloneNodes() throws RepositoryException {
+        // clone referenceable node below non-referenceable node
+        String dstAbsPath = node2W2.getPath() + "/" + node1.getName();
+        workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true);
+
+        // there should not be any pending changes after clone
+        assertFalse(superuserW2.hasPendingChanges());
+    }
+
+    /**
+     * A NoSuchWorkspaceException is thrown if srcWorkspace does not exist.
+     */
+    public void testCloneNodesUnvalidWorkspace() throws RepositoryException {
+        // clone a node to a non-existing workspace
+        String dstAbsPath = node2W2.getPath() + "/" + node1.getName();
+        try {
+            workspaceW2.clone(getNonExistingWorkspaceName(superuser), node1.getPath(), dstAbsPath, true);
+            fail("Unvalid Source Workspace should throw NoSuchWorkspaceException.");
+        } catch (NoSuchWorkspaceException e) {
+            // successful
+        }
+    }
+
+    /**
+     * The destAbsPath provided must not have an index on its final element. If
+     * it does, then a RepositoryException is thrown. Strictly speaking, the
+     * destAbsPath parameter is actually an absolute path to the parent node of
+     * the new location, appended with the new name desired for the copied node.
+     * It does not specify a position within the child node ordering.
+     */
+    public void testCloneNodesAbsolutePath() {
+        try {
+            // copy referenceable node to an absolute path containing index
+            String dstAbsPath = node2W2.getPath() + "/" + node1.getName() + "[2]";
+            workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true);
+            fail("Cloning a node to an absolute path containing index should not be possible.");
+        } catch (RepositoryException e) {
+            // successful
+        }
+    }
+
+    /**
+     * A ConstraintViolationException is thrown if the operation would violate a
+     * node-type or other implementation-specific constraint.
+     */
+    public void testCloneNodesConstraintViolationException() throws RepositoryException {
+        // if parent node is nt:base then no sub nodes can be created
+        Node subNodesNotAllowedNode = testRootNodeW2.addNode(nodeName3, ntBase);
+        testRootNodeW2.save();
+        try {
+            String dstAbsPath = subNodesNotAllowedNode.getPath() + "/" + node2.getName();
+            workspaceW2.clone(workspace.getName(), node2.getPath(), dstAbsPath, true);
+            fail("Cloning a node below a node which can not have any sub nodes should throw a ConstraintViolationException.");
+        } catch (ConstraintViolationException e) {
+            // successful
+        }
+    }
+
+
+    /**
+     * An AccessDeniedException is thrown if the current session (i.e., the
+     * session that was used to acquire this Workspace object) does not have
+     * sufficient access permissions to complete the operation.
+     */
+    public void testCloneNodesAccessDenied() throws RepositoryException {
+        // logout and get read only session
+        superuser.logout();
+        Session readOnlySuperuser = helper.getReadOnlySession();
+
+        String dstAbsPath = node2.getPath() + "/" + node1.getName();
+        try {
+            readOnlySuperuser.getWorkspace().clone(workspaceW2.getName(), node1.getPath(), dstAbsPath, true);
+            fail("Cloning in a read-only session should throw an AccessDeniedException.");
+        } catch (AccessDeniedException e) {
+            // successful
+        }
+    }
+
+    /**
+     * A PathNotFoundException is thrown if the node at srcAbsPath or the parent
+     * of the new node at destAbsPath does not exist.
+     */
+    public void testCloneNodesPathNotExisting() throws RepositoryException {
+
+        String srcAbsPath = node1.getPath();
+        String dstAbsPath = node2W2.getPath() + "/" + node1.getName();
+
+        // srcAbsPath is not existing
+        String unvalidSrcPath = srcAbsPath + "unvalid";
+        try {
+            workspaceW2.clone(workspace.getName(), unvalidSrcPath, dstAbsPath, true);
+            fail("Not existing source path '" + unvalidSrcPath + "' should throw PathNotFoundException.");
+        } catch (PathNotFoundException e) {
+            // successful
+        }
+
+        // dstAbsPath parent is not existing
+        String unvalidDstParentPath = node2W2.getPath() + "unvalid/" + node1.getName();
+        try {
+            workspaceW2.clone(workspace.getName(), srcAbsPath, unvalidDstParentPath, true);
+            fail("Not existing destination parent path '" + unvalidDstParentPath + "' should throw PathNotFoundException.");
+        } catch (PathNotFoundException e) {
+            // successful
+        }
+    }
+
+    /**
+     * A LockException is thrown if a lock prevents the copy.
+     */
+    public void testCloneNodesLocked() throws RepositoryException {
+        // we assume repository supports locking
+        String dstAbsPath = node2W2.getPath() + "/" + node1.getName();
+
+        // add mixin "lockable" to be able to lock the node
+        if (!node2W2.getPrimaryNodeType().isNodeType(mixLockable)) {
+            node2W2.addMixin(mixLockable);
+            testRootNodeW2.save();
+        }
+
+        // lock dst parent node
+        node2W2.lock(true, true);
+
+        try {
+            workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true);
+            fail("LockException was expected.");
+        } catch (LockException e) {
+            // successful
+        }
+    }
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneVersionableTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneVersionableTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneVersionableTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCloneVersionableTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.version.VersionException;
+
+
+/**
+ * <code>WorkspaceCloneVersionableTest</code> contains tests for cloning
+ * versionable nodes between workspace.
+ *
+ * @test
+ * @sources WorkspaceCloneVersionableTest.java
+ * @executeClass org.apache.jackrabbit.test.api.WorkspaceCloneVersionableTest
+ * @keywords level2 versioning
+ */
+public class WorkspaceCloneVersionableTest extends AbstractWorkspaceVersionableTest {
+
+    /**
+     * A VersionException is thrown if the parent node of destAbsPath is
+     * versionable and checked-in, or is non-versionable but its nearest
+     * versionable ancestor is checked-in.
+     */
+    public void testCloneNodesVersionableAndCheckedIn() throws RepositoryException {
+        // prepare the test data
+        // create a non-versionable node below a versionable node
+        // required for having a nearest versionable ancestor to a nonversionable sub node
+        String dstAbsPath = node1W2.getPath() + "/" + node2.getName();
+        workspaceW2.copy(workspace.getName(), node1.getPath(), dstAbsPath);
+
+        // make parent node versionable and check-in
+        addMixinVersionableToNode(testRootNodeW2, node1W2);
+        node1W2.checkin();
+
+        // 1. parent node of destAbsPath is non-versionable but its nearest versionable ancestor is checked-in
+        try {
+            workspaceW2.clone(workspace.getName(), node2.getPath(), dstAbsPath + "/" + node2.getName(), true);
+            fail("Cloning a node to a node's versionable and checked-in nearest ancestor node of destAbsPath should throw VersionException.");
+        } catch (VersionException e) {
+            // successful
+        }
+
+        // 2. parent node of destAbsPath is versionable and checked-in
+        try {
+            workspaceW2.clone(workspace.getName(), node2.getPath(), node1W2.getPath() + "/" + node2.getName(), true);
+            fail("Cloning a node to a versionable and checked-in parent node of destAbsPath should throw VersionException.");
+        } catch (VersionException e) {
+            // successful
+        }
+    }
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesReferenceableTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesReferenceableTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesReferenceableTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesReferenceableTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,53 @@
+/*
+ * 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;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>WorkspaceCopyBetweenWorkspacesReferenceableTest</code> contains tests
+ * for copying referenceable nodes between workspace.
+ *
+ * @test
+ * @sources WorkspaceCopyBetweenWorkspacesReferenceableTest.java
+ * @executeClass org.apache.jackrabbit.test.api.WorkspaceCopyBetweenWorkspacesReferenceableTest
+ * @keywords level2
+ */
+public class WorkspaceCopyBetweenWorkspacesReferenceableTest extends AbstractWorkspaceReferenceableTest {
+
+    /**
+     * Copies of referenceable nodes (nodes with UUIDs) are automatically given
+     * new UUIDs.
+     */
+    public void testCopyNodesReferenceableNodesNewUUID() throws RepositoryException {
+        // add mixin referenceable to node1
+        addMixinReferenceableToNode(testRootNode, node1);
+        
+        // copy referenceable node below non-referenceable node
+        String dstAbsPath = node2W2.getPath() + "/" + node1.getName();
+        workspaceW2.copy(workspace.getName(), node1.getPath(), dstAbsPath);
+
+        // uuid of copied node should be different than original node uuid
+        String originalUUID = node1.getUUID();
+        Node copiedNode = node2W2.getNode(node1.getName());
+        String copiedUUID = copiedNode.getUUID();
+
+        assertFalse(originalUUID.equals(copiedUUID));
+    }
+
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesSameNameSibsTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesSameNameSibsTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesSameNameSibsTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesSameNameSibsTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,85 @@
+/*
+ * 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;
+
+import javax.jcr.ItemExistsException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>WorkspaceCopyBetweenWorkspacesSameNameSibsTest</code> contains tests
+ * for copying nodes as same name siblings between workspace.
+ *
+ * @test
+ * @sources WorkspaceCopyBetweenWorkspacesSameNameSibsTest.java
+ * @executeClass org.apache.jackrabbit.test.api.WorkspaceCopyBetweenWorkspacesSameNameSibsTest
+ * @keywords level2
+ */
+public class WorkspaceCopyBetweenWorkspacesSameNameSibsTest extends AbstractWorkspaceSameNameSibsTest {
+
+    /**
+     * If ordering is supported by the node type of the parent node of the new
+     * location, then the newly moved node is appended to the end of the child
+     * node list.
+     */
+    public void testCopyNodesOrderingSupportedByParent() throws RepositoryException {
+        // test assumes that repositry supports Orderable Child Node Support (optional)
+        String[] orderList = {nodeName1, nodeName2, nodeName3};
+
+        // copy node three times below a node and check the order
+        for (int i = 0; i < orderList.length; i++) {
+            workspaceW2.copy(workspace.getName(), node1.getPath(), node2.getPath() + "/" + orderList[i]);
+        }
+
+        // check regarding orderList if nodes are added at the end
+        int cnt = 0;
+        NodeIterator iter = node2.getNodes();
+        while (iter.hasNext()) {
+            Node n = (Node) iter.nextNode();
+
+            assertTrue(n.getName().equals(orderList[cnt]));
+            cnt++;
+        }
+    }
+
+    /**
+     * An ItemExistsException is thrown if a node or property already exists at
+     * destAbsPath.
+     * @tck.config sameNameSibsFalseNodeType name of a node type that does not
+     * allows same name siblings.
+     * @tck.config nodeName3 name of a child node that does not allow same name
+     * siblings..
+     */
+    public void testCopyNodesNodeExistsAtDestPath() throws RepositoryException {
+        // create a parent node where allowSameNameSiblings are set to false
+        Node snsfNode = testRootNodeW2.addNode(nodeName3, sameNameSibsFalseNodeType.getName());
+        testRootNodeW2.save();
+
+        String dstAbsPath = snsfNode.getPath() + "/" + node1.getName();
+        workspaceW2.copy(node1.getPath(), dstAbsPath);
+
+        // try to copy again the node to same destAbsPath
+        // property already exist
+        try {
+            workspaceW2.copy(workspace.getName(), node1.getPath(), dstAbsPath);
+            fail("Node exists below '" + dstAbsPath + "'. Test should fail.");
+        } catch (ItemExistsException e) {
+            // successful
+        }
+    }
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,180 @@
+/*
+ * 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;
+
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Repository;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+
+/**
+ * <code>WorkspaceCopyBetweenWorkspacesTest</code> contains tests for copying
+ * nodes between workspace.<br>
+ *
+ * @test
+ * @sources WorkspaceCopyBetweenWorkspacesTest.java
+ * @executeClass org.apache.jackrabbit.test.api.WorkspaceCopyBetweenWorkspacesTest
+ * @keywords level2
+ */
+public class WorkspaceCopyBetweenWorkspacesTest extends AbstractWorkspaceCopyBetweenTest {
+
+    /**
+     * Operation is performed entirely within the persistent workspace, it does
+     * not involve transient storage and therefore does not require a save
+     */
+    public void testCopyNodes() throws RepositoryException {
+        // copy referenceable node below non-referenceable node
+        String dstAbsPath = node2W2.getPath() + "/" + node1.getName();
+        workspaceW2.copy(workspace.getName(), node1.getPath(), dstAbsPath);
+
+        // there should not be any pending changes after copy
+        assertFalse(superuserW2.hasPendingChanges());
+    }
+
+    /**
+     * A NoSuchWorkspaceException is thrown if srcWorkspace does not exist.
+     */
+    public void testCopyNodesUnvalidWorkspace() throws RepositoryException {
+        // copy referenceable node below non-referenceable node to a non-existing workspace
+        String dstAbsPath = node2W2.getPath() + "/" + node1.getName();
+        try {
+            superuserW2.getWorkspace().copy(getNonExistingWorkspaceName(superuser), node1.getPath(), dstAbsPath);
+            fail("Unvalid Source Workspace should throw NoSuchWorkspaceException.");
+        } catch (NoSuchWorkspaceException e) {
+            // successful
+        }
+    }
+
+
+    /**
+     * The destAbsPath provided must not have an index on its final element. If
+     * it does, then a RepositoryException is thrown. Strictly speaking, the
+     * destAbsPath parameter is actually an absolute path to the parent node of
+     * the new location, appended with the new name desired for the copied node.
+     * It does not specify a position within the child node ordering.
+     */
+    public void testCopyNodesAbsolutePath() {
+        try {
+            // copy referenceable node to an absolute path containing index
+            String dstAbsPath = node2W2.getPath() + "/" + node1.getName() + "[2]";
+            workspaceW2.copy(workspace.getName(), node1.getPath(), dstAbsPath);
+            fail("Copying a node to an absolute path containing index should not be possible.");
+        } catch (RepositoryException e) {
+            // successful
+        }
+    }
+
+    /**
+     * A ConstraintViolationException is thrown if the operation would violate a
+     * node-type or other implementation-specific constraint.
+     */
+    public void testCopyNodesConstraintViolationException() throws RepositoryException {
+        // if parent node is nt:base then no sub nodes can be created
+        Node subNodesNotAllowedNode = testRootNodeW2.addNode(nodeName3, ntBase);
+        testRootNodeW2.save();
+        try {
+            String dstAbsPath = subNodesNotAllowedNode.getPath() + "/" + node2.getName();
+            workspaceW2.copy(workspace.getName(), node2.getPath(), dstAbsPath);
+            fail("Copying a node below a node which can not have any sub nodes should throw a ConstraintViolationException.");
+        } catch (ConstraintViolationException e) {
+            // successful
+        }
+    }
+
+
+    /**
+     * An AccessDeniedException is thrown if the current session (i.e., the
+     * session that was used to acquire this Workspace object) does not have
+     * sufficient access permissions to complete the operation.
+     */
+    public void testCopyNodesAccessDenied() throws RepositoryException {
+        // logout and get read only session
+        superuser.logout();
+        Session readOnlySuperuser = helper.getReadOnlySession();
+
+        String dstAbsPath = node2.getPath() + "/" + node1.getName();
+        try {
+            readOnlySuperuser.getWorkspace().copy(workspaceW2.getName(), node1W2.getPath(), dstAbsPath);
+            fail("Copy in a read-only session should throw an AccessDeniedException.");
+        } catch (AccessDeniedException e) {
+            // successful
+        }
+    }
+
+    /**
+     * A PathNotFoundException is thrown if the node at srcAbsPath or the parent
+     * of the new node at destAbsPath does not exist.
+     */
+    public void testCopyNodesPathNotExisting() throws RepositoryException {
+
+        String srcAbsPath = node1.getPath();
+        String dstAbsPath = node2W2.getPath() + "/" + node1.getName();
+
+        // srcAbsPath is not existing
+        String unvalidSrcPath = srcAbsPath + "unvalid";
+        try {
+            workspaceW2.copy(workspace.getName(), unvalidSrcPath, dstAbsPath);
+            fail("Not existing source path '" + unvalidSrcPath + "' should throw PathNotFoundException.");
+        } catch (PathNotFoundException e) {
+            // successful
+        }
+
+        // dstAbsPath parent is not existing
+        String unvalidDstParentPath = node2W2.getPath() + "unvalid/" + node1.getName();
+        try {
+            workspaceW2.copy(workspace.getName(), srcAbsPath, unvalidDstParentPath);
+            fail("Not existing destination parent path '" + unvalidDstParentPath + "' should throw PathNotFoundException.");
+        } catch (PathNotFoundException e) {
+            // successful
+        }
+    }
+
+    /**
+     * A LockException is thrown if a lock prevents the copy.
+     */
+    public void testCopyNodesLocked() throws RepositoryException, NotExecutableException {
+        if (superuser.getRepository().getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) == null) {
+            throw new NotExecutableException("Repository does not support locking.");
+        }
+        // we assume repository supports locking
+        String dstAbsPath = node2W2.getPath() + "/" + node1.getName();
+
+        // add mixin "lockable" to be able to lock the node
+        if (!node2W2.getPrimaryNodeType().isNodeType(mixLockable)) {
+            node2W2.addMixin(mixLockable);
+            testRootNodeW2.save();
+        }
+
+        // lock dst parent node
+        node2W2.lock(true, true);
+
+        try {
+            workspaceW2.copy(workspace.getName(), node1.getPath(), dstAbsPath);
+            fail("LockException was expected.");
+        } catch (LockException e) {
+            // successful
+        }
+    }
+
+}

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesVersionableTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesVersionableTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesVersionableTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyBetweenWorkspacesVersionableTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.version.VersionException;
+
+/**
+ * <code>WorkspaceCopyBetweenWorkspacesVersionableTest</code> contains tests for
+ * copying versionable nodes between workspace.
+ *
+ * @test
+ * @sources WorkspaceCopyBetweenWorkspacesVersionableTest.java
+ * @executeClass org.apache.jackrabbit.test.api.WorkspaceCopyBetweenWorkspacesVersionableTest
+ * @keywords level2 versioning
+ */
+public class WorkspaceCopyBetweenWorkspacesVersionableTest extends AbstractWorkspaceVersionableTest {
+
+    /**
+     * A VersionException is thrown if the parent node of destAbsPath is
+     * versionable and checked-in, or is non-versionable but its nearest
+     * versionable ancestor is checked-in.
+     */
+    public void testCopyNodesVersionableAndCheckedIn() throws RepositoryException {
+        // prepare the test data
+        // create a non-versionable node below a versionable node
+        // required for having a nearest versionable ancestor to a nonversionable sub node
+        String dstAbsPath = node1W2.getPath() + "/" + node2.getName();
+        workspaceW2.copy(workspace.getName(), node1.getPath(), dstAbsPath);
+
+        // make parent node versionable and check-in
+        addMixinVersionableToNode(testRootNodeW2, node1W2);
+        node1W2.checkin();
+
+        // 1. parent node of destAbsPath is non-versionable but its nearest versionable ancestor is checked-in
+        try {
+            workspaceW2.copy(workspace.getName(), node2.getPath(), dstAbsPath + "/" + node2.getName());
+            fail("Copying a node to a node's versionable and checked-in nearest ancestor node of destAbsPath should throw VersionException.");
+        } catch (VersionException e) {
+            // successful
+        }
+
+        // 2. parent node of destAbsPath is versionable and checked-in
+        try {
+            workspaceW2.copy(workspace.getName(), node2.getPath(), node1W2.getPath() + "/" + node2.getName());
+            fail("Copying a node to a versionable and checked-in parent node of destAbsPath should throw VersionException.");
+        } catch (VersionException e) {
+            // successful
+        }
+    }
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyReferenceableTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyReferenceableTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyReferenceableTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyReferenceableTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>WorkspaceCopyReferenceableTest</code> contains tests for copying
+ * referenceable nodes in one workspace.
+ *
+ * @test
+ * @sources WorkspaceCopyReferenceableTest.java
+ * @executeClass org.apache.jackrabbit.test.api.WorkspaceCopyReferenceableTest
+ * @keywords level2
+ */
+public class WorkspaceCopyReferenceableTest extends AbstractWorkspaceReferenceableTest {
+
+    /**
+     * Copies of referenceable nodes (nodes with UUIDs) are automatically given
+     * new UUIDs.
+     */
+    public void testCopyNodesNewUUID() throws RepositoryException {
+        // add mixin referenceable to node1
+        addMixinReferenceableToNode(testRootNode, node1);
+        
+        // copy referenceable node below non-referenceable node
+        String dstAbsPath = node2.getPath() + "/" + node1.getName();
+        workspace.copy(node1.getPath(), dstAbsPath);
+
+        // uuid of copied node should be different than original node uuid
+        String originalUUID = node1.getUUID();
+        Node copiedNode = node2.getNode(node1.getName());
+        String copiedUUID = copiedNode.getUUID();
+
+        assertFalse(originalUUID.equals(copiedUUID));
+    }
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopySameNameSibsTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopySameNameSibsTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopySameNameSibsTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopySameNameSibsTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,85 @@
+/*
+ * 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;
+
+import javax.jcr.ItemExistsException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>WorkspaceCopySameNameSibsTest</code> contains tests for copying nodes
+ * as same name siblings in one workspace.
+ *
+ * @test
+ * @sources WorkspaceCopySameNameSibsTest.java
+ * @executeClass org.apache.jackrabbit.test.api.WorkspaceCopySameNameSibsTest
+ * @keywords level2
+ */
+public class WorkspaceCopySameNameSibsTest extends AbstractWorkspaceSameNameSibsTest {
+
+    /**
+     * If ordering is supported by the node type of the parent node of the new
+     * location, then the newly moved node is appended to the end of the child
+     * node list.
+     */
+    public void testCopyNodesOrderingSupportedByParent() throws RepositoryException {
+        // test assumes that repositry supports Orderable Child Node Support (optional)
+        String[] orderList = {nodeName1, nodeName2, nodeName3};
+
+        // copy node three times below a node and check the order
+        for (int i = 0; i < orderList.length; i++) {
+            workspace.copy(node1.getPath(), node2.getPath() + "/" + orderList[i]);
+        }
+
+        // check regarding orderList if nodes are added at the end
+        int cnt = 0;
+        NodeIterator iter = node2.getNodes();
+        while (iter.hasNext()) {
+            Node n = (Node) iter.nextNode();
+
+            assertTrue(n.getName().equals(orderList[cnt]));
+            cnt++;
+        }
+    }
+
+    /**
+     * An ItemExistsException is thrown if a node or property already exists at
+     * destAbsPath.
+     * @tck.config sameNameSibsFalseNodeType name of a node type that does not
+     * allows same name siblings.
+     * @tck.config nodeName3 name of a child node that does not allow same name
+     * siblings..
+     */
+    public void testCopyNodesNodeExistsAtDestPath() throws RepositoryException {
+        // create a parent node where allowSameNameSiblings are set to false
+        Node snsfNode = testRootNode.addNode(nodeName3, sameNameSibsFalseNodeType.getName());
+        testRootNode.save();
+
+        String dstAbsPath = snsfNode.getPath() + "/" + node1.getName();
+        workspace.copy(node1.getPath(), dstAbsPath);
+
+        // try to copy again the node to same destAbsPath
+        // property already exist
+        try {
+            workspace.copy(node1.getPath(), dstAbsPath);
+            fail("Node exists below '" + dstAbsPath + "'. Test should fail.");
+        } catch (ItemExistsException e) {
+            // successful
+        }
+    }
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,157 @@
+/*
+ * 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;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+
+/**
+ * <code>WorkspaceCopyTest</code> contains tests for copying nodes in one
+ * workspace.
+ *
+ * @test
+ * @sources WorkspaceCopyTest.java
+ * @executeClass org.apache.jackrabbit.test.api.WorkspaceCopyTest
+ * @keywords level2
+ */
+public class WorkspaceCopyTest extends AbstractWorkspaceCopyTest {
+
+    /**
+     * Operation is performed entirely within the persistent workspace, it does
+     * not involve transient storage and therefore does not require a save
+     */
+    public void testCopyNodes() throws RepositoryException {
+        // copy referenceable node below non-referenceable node
+        String dstAbsPath = node2.getPath() + "/" + node1.getName();
+        workspace.copy(node1.getPath(), dstAbsPath);
+
+        // there should not be any pending changes after copy
+        assertFalse(superuser.hasPendingChanges());
+    }
+
+    /**
+     * The destAbsPath provided must not have an index on its final element. If
+     * it does, then a RepositoryException is thrown. Strictly speaking, the
+     * destAbsPath parameter is actually an absolute path to the parent node of
+     * the new location, appended with the new name desired for the copied node.
+     * It does not specify a position within the child node ordering.
+     */
+    public void testCopyNodesAbsolutePath() {
+        try {
+            // copy referenceable node to an absolute path containing index
+            String dstAbsPath = node2.getPath() + "/" + node1.getName() + "[2]";
+            workspace.copy(node1.getPath(), dstAbsPath);
+            fail("Copying a node to an absolute path containing index should not be possible.");
+        } catch (RepositoryException e) {
+            // successful
+
+        }
+    }
+
+    /**
+     * A ConstraintViolationException is thrown if the operation would violate a
+     * node-type or other implementation-specific constraint.
+     */
+    public void testCopyNodesConstraintViolationException() throws RepositoryException {
+        // if parent node is nt:base then no sub nodes can be created
+        Node subNodesNotAllowedNode = testRootNode.addNode(nodeName3, ntBase);
+        testRootNode.save();
+        try {
+            String dstAbsPath = subNodesNotAllowedNode.getPath() + "/" + node2.getName();
+            workspace.copy(node2.getPath(), dstAbsPath);
+            fail("Copying a node below a node which can not have any sub nodes should throw a ConstraintViolationException.");
+        } catch (ConstraintViolationException e) {
+            // successful
+        }
+    }
+
+    /**
+     * An AccessDeniedException is thrown if the current session (i.e., the
+     * session that was used to acquire this Workspace object) does not have
+     * sufficient access permissions to complete the operation.
+     */
+    public void testCopyNodesAccessDenied() throws RepositoryException {
+        // logout and get read only session
+        superuser.logout();
+        Session readOnlySuperuser = helper.getReadOnlySession();
+
+        String dstAbsPath = node2.getPath() + "/" + node1.getName();
+        try {
+            readOnlySuperuser.getWorkspace().copy(node1.getPath(), dstAbsPath);
+            fail("Copy in a read-only session should throw an AccessDeniedException.");
+        } catch (AccessDeniedException e) {
+            // successful
+        }
+    }
+
+    /**
+     * A PathNotFoundException is thrown if the node at srcAbsPath or the parent
+     * of the new node at destAbsPath does not exist.
+     */
+    public void testCopyNodesPathNotExisting() throws RepositoryException {
+
+        String srcAbsPath = node1.getPath();
+        String dstAbsPath = node2.getPath() + "/" + node1.getName();
+
+        // srcAbsPath is not existing
+        String invalidSrcPath = srcAbsPath + "invalid";
+        try {
+            workspace.copy(invalidSrcPath, dstAbsPath);
+            fail("Not existing source path '" + invalidSrcPath + "' should throw PathNotFoundException.");
+        } catch (PathNotFoundException e) {
+            // successful
+        }
+
+        // dstAbsPath parent is not existing
+        String invalidDstParentPath = node2.getPath() + "invalid/" + node1.getName();
+        try {
+            workspace.copy(srcAbsPath, invalidDstParentPath);
+            fail("Not existing destination parent path '" + invalidDstParentPath + "' should throw PathNotFoundException.");
+        } catch (PathNotFoundException e) {
+            // successful
+        }
+    }
+
+    /**
+     * A LockException is thrown if a lock prevents the copy.
+     */
+    public void testCopyNodesLocked() throws RepositoryException {
+        // we assume repository supports locking
+        String dstAbsPath = node2.getPath() + "/" + node1.getName();
+
+        // add mixin "lockable" to be able to lock the node
+        if (!node2.getPrimaryNodeType().isNodeType(mixLockable)) {
+            node2.addMixin(mixLockable);
+            testRootNode.save();
+        }
+
+        // lock dst parent node
+        node2.lock(true, true);
+
+        try {
+            workspace.copy(node1.getPath(), dstAbsPath);
+            fail("LockException was expected.");
+        } catch (LockException e) {
+            // successful
+        }
+    }
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyVersionableTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyVersionableTest.java?view=auto&rev=157794
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyVersionableTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/WorkspaceCopyVersionableTest.java Wed Mar 16 12:01:45 2005
@@ -0,0 +1,67 @@
+/*
+ * 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;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.version.VersionException;
+
+
+/**
+ * <code>WorkspaceCopyVersionableTest</code> contains tests for copying
+ * versionable nodes in one workspace.
+ *
+ * @test
+ * @sources WorkspaceCopyVersionableTest.java
+ * @executeClass org.apache.jackrabbit.test.api.WorkspaceCopyVersionableTest
+ * @keywords level2 versionable
+ */
+public class WorkspaceCopyVersionableTest extends AbstractWorkspaceVersionableTest {
+
+    /**
+     * A VersionException is thrown if the parent node of destAbsPath is
+     * versionable and checked-in, or is non-versionable but its nearest
+     * versionable ancestor is checked-in.
+     */
+    public void testCopyNodesVersionableAndCheckedIn() throws RepositoryException {
+        // prepare the test data
+        // create a non-versionable node below a versionable node
+        // required for having a nearest versionable ancestor to a nonversionable sub node
+        String dstAbsPath = node1.getPath() + "/" + node2.getName();
+        workspace.copy(node2.getPath(), dstAbsPath);
+
+        // make parent node versionable and check-in
+        addMixinVersionableToNode(testRootNode, node1);
+        node1.checkin();
+
+        // 1. parent node of destAbsPath is non-versionable but its nearest versionable ancestor is checked-in
+        try {
+            workspace.copy(node2.getPath(), dstAbsPath + "/" + node2.getName());
+            fail("Copying a node to a node's versionable and checked-in nearest ancestor node of destAbsPath should throw VersionException.");
+        } catch (VersionException e) {
+            // successful
+        }
+
+        // 2. parent node of destAbsPath is versionable and checked-in
+        try {
+            workspace.copy(node2.getPath(), node1.getPath() + "/" + node2.getName());
+            fail("Copying a node to a versionable and checked-in parent node of destAbsPath should throw VersionException.");
+        } catch (VersionException e) {
+            // successful
+        }
+    }
+
+}
\ No newline at end of file

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



Mime
View raw message