jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r157964 - in incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version: GetCreatedTest.java GetPredecessorsTest.java MergeNodeTest.java TestAll.java
Date Thu, 17 Mar 2005 19:06:24 GMT
Author: mreutegg
Date: Thu Mar 17 11:06:21 2005
New Revision: 157964

URL: http://svn.apache.org/viewcvs?view=rev&rev=157964
Log:
Test cases for Version.getPredecessors() and Version.getCreated().

Added:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/GetCreatedTest.java
  (with props)
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/GetPredecessorsTest.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNodeTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/TestAll.java

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/GetCreatedTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/GetCreatedTest.java?view=auto&rev=157964
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/GetCreatedTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/GetCreatedTest.java
Thu Mar 17 11:06:21 2005
@@ -0,0 +1,68 @@
+/*
+ * 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 java.util.Calendar;
+import java.util.GregorianCalendar;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.Version;
+
+/**
+ * <code>GetCreatedTest</code> provides test methods covering {@link
+ * javax.jcr.version.Version#getCreated()}.
+ *
+ * @test
+ * @sources GetCreatedTest.java
+ * @executeClass org.apache.jackrabbit.test.api.version.GetCreatedTest
+ * @keywords versioning
+ */
+public class GetCreatedTest extends AbstractVersionTest {
+
+    /**
+     * Returns the date this version was created.
+     */
+    public void testGetCreated() throws RepositoryException {
+
+        // create version
+        versionableNode.checkout();
+        Version version = versionableNode.checkin();
+
+        Calendar now = GregorianCalendar.getInstance();
+        now.add(Calendar.SECOND, 1);
+
+        assertTrue("Method getCreated() should return a creation date before current date.",
version.getCreated().before(now));
+    }
+
+
+    /**
+     * Returns the date this version was created. This corresponds to the value
+     * of the jcr:created property in the nt:version node that represents this
+     * version.
+     */
+    public void testGetCreatedCheckAgainstProperty() throws RepositoryException {
+
+        // create version
+        versionableNode.checkout();
+        Version version = versionableNode.checkin();
+
+        Calendar calGetCreated = version.getCreated();
+        Calendar calCreatedProp = version.getProperty(jcrCreated).getValue().getDate();
+
+        assertEquals("Method getCreated() should return value of the jcr:created property.",
calGetCreated, calCreatedProp);
+    }
+
+}
\ No newline at end of file

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

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/GetPredecessorsTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/GetPredecessorsTest.java?view=auto&rev=157964
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/GetPredecessorsTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/GetPredecessorsTest.java
Thu Mar 17 11:06:21 2005
@@ -0,0 +1,46 @@
+/*
+ * 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.version.Version;
+
+/**
+ * <code>GetPredecessorsTest</code>  provides test methods covering {@link
+ * javax.jcr.version.Version#getPredecessors()}.
+ *
+ * @test
+ * @sources GetPredecessorsTest.java
+ * @executeClass org.apache.jackrabbit.test.api.version.GetPredecessorsTest
+ * @keywords versioning
+ */
+public class GetPredecessorsTest extends AbstractVersionTest {
+
+    /**
+     * Returns the predecessor versions of this version. This corresponds to
+     * returning all the nt:version nodes whose jcr:successors property includes
+     * a reference to the nt:version node that represents this version. A
+     * RepositoryException is thrown if an error occurs.
+     */
+    public void testGetPredecessors() throws RepositoryException {
+        // create a new version
+        versionableNode.checkout();
+        Version version = versionableNode.checkin();
+
+        assertTrue("Version should have at minimum one predecessor version.", version.getPredecessors().length
> 0);
+    }
+}
\ No newline at end of file

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

Modified: 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=diff&r1=157963&r2=157964
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNodeTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/MergeNodeTest.java
Thu Mar 17 11:06:21 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.test.api.version;
 
+import org.apache.jackrabbit.test.NotExecutableException;
+
 import javax.jcr.version.VersionException;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -24,6 +26,9 @@
 import javax.jcr.Property;
 import javax.jcr.Value;
 import javax.jcr.MergeException;
+import javax.jcr.Session;
+import javax.jcr.Repository;
+import javax.jcr.lock.LockException;
 
 /**
  * <code>MergeNodeTest</code> contains tests dealing with general merge node
@@ -115,6 +120,7 @@
         try {
             nodeToMerge.checkout();
             nodeToMerge.merge(workspace.getName(), false);
+            fail("Node has ambigous versions. Merge must throw a VersionException");
         } catch (VersionException e) {
             // success if the version exception thrown
         }
@@ -182,6 +188,7 @@
 
         try {
             nodeToMerge.merge(workspace.getName(), true);
+            fail("Merge failed for node in earlier merge operations. Because the mergeFailedProperty
is present, merge must throw a VersionException");
         } catch (VersionException e) {
             // success version exception expected
         }
@@ -192,7 +199,31 @@
      * thrown.<br>
      */
     public void testMergeNodeBestEffortFalse() throws RepositoryException {
-        /// create 2 independent versions for a node and its corresponding node
+        /// create successor versions for a node
+        // so merge fails for this node
+
+        // default workspace
+        Node originalNode = testRootNode.getNode(nodeName1);
+        originalNode.checkout();
+        originalNode.checkin();
+
+        // "merge" the clonedNode with the newNode from the default workspace
+        // 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
+        }
+    }
+
+    /**
+     * A MergeVersionException is thrown if bestEffort is false and a
+     * versionable node is encountered whose corresponding node's base version
+     * is on a divergent branch from this node's base version.
+     */
+    public void testMergeNodeBestEffortFalseAmbiguousVersions() throws RepositoryException
{
+        /// create 2 independent base versions for a node and its corresponding node
         // so merge fails for this node
 
         // default workspace
@@ -204,18 +235,61 @@
         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.");
+            fail("BestEffort is false and corresponding node's version is ambiguous. Merge
should throw a MergeException.");
         } catch (MergeException e) {
             // successful
         }
     }
 
+    /**
+     * Tests if a {@link LockException} is thrown when merge is called on a
+     * locked node.
+     * @throws NotExecutableException if repository does not support locking.
+     */
+    public void testMergeLocked()
+            throws NotExecutableException, RepositoryException {
+
+        Session session = testRootNode.getSession();
+
+        if (session.getRepository().getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) ==
null) {
+            throw new NotExecutableException("Locking is not supported.");
+        }
+
+        // try to make nodeToMerge lockable if it is not
+        if (!nodeToMerge.isNodeType(mixLockable)) {
+            if (nodeToMerge.canAddMixin(mixLockable)) {
+                nodeToMerge.addMixin(mixLockable);
+            } else {
+                throw new NotExecutableException("Node " + nodeToMerge.getName() + " is not
lockable and " +
+                        "does not allow to add mix:lockable");
+            }
+        }
+        nodeToMerge.getParent().save();
+
+        // lock the node
+        // remove first slash of path to get rel path to root
+        String pathRelToRoot = nodeToMerge.getPath().substring(1);
+        // access node through another session to lock it
+        Session session2 = helper.getSuperuserSession();
+        Node node2 = session2.getRootNode().getNode(pathRelToRoot);
+        node2.lock(false, false);
+
+        try {
+            nodeToMerge.merge(workspace.getName(), false);
+            fail("merge must throw a LockException if applied on a " +
+                    "locked node");
+        } catch (LockException e) {
+            // success
+        }
+
+        node2.unlock();
+        session2.logout();
+    }
 
     /**
      * initialize a versionable node on default and second workspace
@@ -234,6 +308,8 @@
         log.println("test nodes created successfully on " + workspace.getName());
 
         // clone the newly created node from src workspace into second workspace
+        // todo clone on testRootNode does not seem to work.
+        // workspaceW2.clone(workspace.getName(), testRootNode.getPath(), testRootNode.getPath(),
true);
         workspaceW2.clone(workspace.getName(), topVNode.getPath(), topVNode.getPath(), true);
         log.println(topVNode.getPath() + " cloned on " + superuserW2.getWorkspace().getName()
+ " at " + topVNode.getPath());
 

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/TestAll.java?view=diff&r1=157963&r2=157964
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/TestAll.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/TestAll.java
Thu Mar 17 11:06:21 2005
@@ -51,6 +51,8 @@
         //suite.addTestSuite(OnParentVersionIgnoreTest.class);
         //suite.addTestSuite(OnParentVersionInitializeTest.class);
         suite.addTestSuite(GetReferencesNodeTest.class);
+        suite.addTestSuite(GetPredecessorsTest.class);
+        suite.addTestSuite(GetCreatedTest.class);
 
         return suite;
     }



Mime
View raw message