jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r157760 - in incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api: NodeTest.java lock/LockTest.java
Date Wed, 16 Mar 2005 14:56:08 GMT
Author: mreutegg
Date: Wed Mar 16 06:56:07 2005
New Revision: 157760

URL: http://svn.apache.org/viewcvs?view=rev&rev=157760
Log:
Added lock related test cases.

Modified:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/LockTest.java

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeTest.java?view=diff&r1=157759&r2=157760
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeTest.java Wed Mar
16 06:56:07 2005
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.test.api;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
 
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.Session;
@@ -28,6 +29,8 @@
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.ItemExistsException;
 import javax.jcr.PathNotFoundException;
+import javax.jcr.Repository;
+import javax.jcr.lock.LockException;
 import java.util.StringTokenizer;
 
 /**
@@ -615,6 +618,90 @@
         }
     }
 
+    /**
+     * Tests if <code>Node.remove()</code> does not throw a
+     * <code>LockException</code> if <code>Node</code> is locked.
+     * <p/>
+     * The test creates a node <code>nodeName1</code> of type
+     * <code>testNodeType</code> under <code>testRoot</code> and
locks the node
+     * with the superuser session. Then the test removes
+     * <code>nodeName1</code>.
+     */
+    public void testRemoveNodeLockedItself()
+            throws LockException, NotExecutableException, RepositoryException {
+
+        Session session = testRootNode.getSession();
+
+        if (session.getRepository().getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) ==
null) {
+            throw new NotExecutableException("Locking is not supported.");
+        }
+
+        // create a node that is lockable
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        // or try to make it lockable if it is not
+        if (!node.isNodeType(mixLockable)) {
+            if (node.canAddMixin(mixLockable)) {
+                node.addMixin(mixLockable);
+            } else {
+                throw new NotExecutableException("Node " + nodeName1 + " is not lockable
and does not " +
+                        "allow to add mix:lockable");
+            }
+        }
+        testRootNode.save();
+
+        node.lock(true, true);
+
+        // test fails if a LockException is thrown when removing the node
+        // (remove must be possible since the parent is not locked)
+        node.remove();
+    }
+
+    /**
+     * Tests if <code>Node.remove()</code> throws a <code>LockException</code>
+     * if the parent node of <code>Node</code> is locked.
+     * <p/>
+     * The test creates a node <code>nodeName1</code> of type
+     * <code>testNodeType</code> under <code>testRoot</code>, adds
a child node
+     * <code>nodeName2</code> and locks it with the superuser session. Then the
+     * test tries to remove the <code>nodeName2</code>.
+     */
+    public void testRemoveNodeParentLocked()
+            throws LockException, NotExecutableException, RepositoryException {
+
+        Session session = testRootNode.getSession();
+
+        if (session.getRepository().getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) ==
null) {
+            throw new NotExecutableException("Locking is not supported.");
+        }
+
+        // create a node that is lockable
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        // or try to make it lockable if it is not
+        if (!node.isNodeType(mixLockable)) {
+            if (node.canAddMixin(mixLockable)) {
+                node.addMixin(mixLockable);
+            } else {
+                throw new NotExecutableException("Node " + nodeName1 + " is not lockable
and does not " +
+                        "allow to add mix:lockable");
+            }
+        }
+        // create a child node
+        Node subNode = node.addNode(nodeName2, testNodeType);
+        testRootNode.save();
+
+        node.lock(true, true);
+
+        try {
+            subNode.remove();
+            fail("Node.remove() must throw a LockException if the parent " +
+                    "of the node is locked");
+        } catch (LockException e) {
+            // success
+        }
+
+        // unlock to remove node at tearDown()
+        node.unlock();
+    }
 
     /**
      * Tests object identity, meaning two nodes objects accuired through the
@@ -1034,4 +1121,4 @@
             // ok
         }
     }
-}
\ No newline at end of file
+}

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/LockTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/LockTest.java?view=diff&r1=157759&r2=157760
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/LockTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/LockTest.java
Wed Mar 16 06:56:07 2005
@@ -137,6 +137,96 @@
     }
 
     /**
+     * Test to get the lock holding node of a node
+     */
+    public void testGetNode() throws Exception {
+        // create new node with a sub node and lock it
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        n1.addMixin(mixLockable);
+        Node n1Sub = n1.addNode(nodeName1, testNodeType);
+        n1Sub.addMixin(mixLockable);
+        testRootNode.save();
+
+        // lock node
+        n1.lock(true, true);
+
+        assertEquals("getNode() must return the lock holder",
+                n1.getPath(),
+                n1.getLock().getNode().getPath());
+
+        assertEquals("getNode() must return the lock holder",
+                n1.getPath(),
+                n1Sub.getLock().getNode().getPath());
+
+        n1.unlock();
+    }
+
+    /**
+     * Test if getLockOwner() returns the same value as returned by
+     * Session.getUserId at the time that the lock was placed
+     */
+    public void testGetLockOwnerProperty() throws Exception {
+        // create new node and lock it
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        n1.addMixin(mixLockable);
+        testRootNode.save();
+
+        // lock node
+        Lock lock = n1.lock(false, true);
+
+        if (n1.getSession().getUserId() == null) {
+            assertFalse("jcr:lockOwner must not exist if Session.getUserId() returns null",
+                    n1.hasProperty(jcrLockOwner));
+        } else {
+            assertEquals("getLockOwner() must return the same value as stored " +
+                    "in property " + jcrLockOwner + " of the lock holding " +
+                    "node",
+                    n1.getProperty(jcrLockOwner).getString(),
+                    lock.getLockOwner());
+        }
+        n1.unlock();
+    }
+
+    /**
+     * Test if getLockOwner() returns the same value as returned by
+     * Session.getUserId at the time that the lock was placed
+     */
+    public void testGetLockOwner() throws Exception {
+        // create new node and lock it
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        n1.addMixin(mixLockable);
+        testRootNode.save();
+
+        // lock node
+        Lock lock = n1.lock(false, true);
+
+        assertEquals("getLockOwner() must return the same value as returned " +
+                "by Session.getUserId at the time that the lock was placed",
+                testRootNode.getSession().getUserId(),
+                lock.getLockOwner());
+
+        n1.unlock();
+    }
+
+    /**
+     * Test if a shallow lock does not lock the child nodes of the locked node.
+     */
+    public void testShallowLock() throws Exception {
+        // create new nodes
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        n1.addMixin(mixReferenceable);
+        n1.addMixin(mixLockable);
+        Node n2 = n1.addNode(nodeName2, testNodeType);
+        testRootNode.save();
+
+        // lock parent node
+        n1.lock(false, true);
+
+        assertFalse("Shallow lock must not lock the child nodes of a node.",
+                n2.isLocked());
+    }
+
+    /**
      * Test parent/child lock
      */
     public void testParentChildLock() throws Exception {



Mime
View raw message