You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2009/05/22 16:38:52 UTC

svn commit: r777548 [2/2] - /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionHistoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionHistoryTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionHistoryTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionHistoryTest.java Fri May 22 14:38:51 2009
@@ -37,6 +37,7 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
 import javax.jcr.lock.LockException;
+import javax.jcr.lock.LockManager;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeType;
@@ -59,6 +60,7 @@
 
     protected VersionHistory vHistory;
     private Version version;
+    private VersionManager versionManager;
 
     /**
      * helper class used in testAccept()
@@ -82,9 +84,10 @@
     protected void setUp() throws Exception {
         super.setUp();
 
-        version = versionableNode.checkin();
+        versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
+        version = versionManager.checkin(versionableNode.getPath());
 
-        vHistory = versionableNode.getVersionHistory();
+        vHistory = versionManager.getVersionHistory(versionableNode.getPath());
 
 
         if (vHistory == null) {
@@ -206,6 +209,35 @@
     }
 
     /**
+     * Test that {@link VersionHistory#getAllVersions()} returns an iterator
+     * containing the root version and all versions that have been created by
+     * Node.checkin().
+     *
+     * @see javax.jcr.version.VersionHistory#getAllVersions()
+     */
+    public void testGetAllVersionsJcr2() throws RepositoryException {
+        int cnt = 5;
+        HashMap versions = new HashMap();
+        Version v = vHistory.getRootVersion();
+        versions.put(v.getIdentifier(), v);
+        for (int i = 0; i < cnt; i++) {
+            v = versionManager.checkin(versionableNode.getPath());
+            versions.put(v.getIdentifier(), v);
+            versionManager.checkout(versionableNode.getPath());
+        }
+
+        VersionIterator it = vHistory.getAllVersions();
+        while (it.hasNext()) {
+            v = it.nextVersion();
+            if (!versions.containsKey(v.getIdentifier())) {
+                fail("VersionHistory.getAllVersions() must only contain the root version and versions, that have been created by a Node.checkin() call.");
+            }
+            versions.remove(v.getIdentifier());
+        }
+        assertTrue("VersionHistory.getAllVersions() must contain the root version and all versions that have been created with a Node.checkin() call.", versions.isEmpty());
+    }
+
+    /**
      * Test that {@link VersionHistory#getAllFrozenNodes()} returns an iterator
      * containing the frozen nodes of all versions that have been created by
      * {@link VersionManager#checkpoint(String)}.
@@ -255,6 +287,19 @@
     }
 
     /**
+     * Test if UnsupportedRepositoryOperationException is thrown when calling
+     * Node.getVersionHistory() on a non-versionable node.
+     */
+    public void testGetVersionHistoryOnNonVersionableNodeJcr2() throws RepositoryException {
+        try {
+            versionManager.getVersionHistory(nonVersionableNode.getPath());
+            fail("Node.getVersionHistory() must throw UnsupportedRepositoryOperationException if the node is not versionable.");
+        } catch (UnsupportedRepositoryOperationException e) {
+            //success
+        }
+    }
+
+    /**
      * Test VersionHistory.getVersion(String versionName) if 'versionName' is
      * the name of an existing version (created by Node.checkin()).
      *
@@ -262,7 +307,7 @@
      */
     public void testGetVersion() throws RepositoryException {
 
-        Version v = versionableNode.checkin();
+        Version v = versionManager.checkin(versionableNode.getPath());
         Version v2 = vHistory.getVersion(v.getName());
 
         assertTrue("VersionHistory.getVersion(String versionName) must return the version that is identified by the versionName specified, if versionName is the name of a version created by Node.checkin().", v.isSame(v2));
@@ -284,7 +329,7 @@
     public void testAddMixin() throws Exception {
         try {
             vHistory.addMixin(mixVersionable);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.addMixin(String) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
@@ -298,13 +343,13 @@
     public void testAddNode() throws Exception {
         try {
             vHistory.addNode(nodeName4);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.addNode(String) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             vHistory.addNode(nodeName4, ntBase);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.addNode(String,String) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
@@ -331,6 +376,18 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.cancelMerge(Version)</code> throws an
+     * {@link javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testCancelMergeJcr2() throws Exception {
+        try {
+            versionManager.cancelMerge(vHistory.getPath(), version);
+            fail("VersionHistory.cancelMerge(Version) did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>VersionHistory.checkin()</code> throws an {@link
      * javax.jcr.UnsupportedRepositoryOperationException}
      */
@@ -343,6 +400,18 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.checkin()</code> throws an {@link
+     * javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testCheckinJcr2() throws Exception {
+        try {
+            versionManager.checkin(vHistory.getPath());
+            fail("VersionHistory.checkin() did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>VersionHistory.checkout()</code> throws an {@link
      * javax.jcr.UnsupportedRepositoryOperationException}
      */
@@ -355,6 +424,18 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.checkout()</code> throws an {@link
+     * javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testCheckoutJcr2() throws Exception {
+        try {
+            versionManager.checkout(vHistory.getPath());
+            fail("VersionHistory.checkout() did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>VersionHistory.doneMerge(Version)</code> throws an {@link
      * javax.jcr.UnsupportedRepositoryOperationException}
      */
@@ -367,6 +448,18 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.doneMerge(Version)</code> throws an {@link
+     * javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testDoneMergeJcr2() throws Exception {
+        try {
+            versionManager.doneMerge(vHistory.getPath(), version);
+            fail("VersionHistory should not be versionable: VersionHistory.doneMerge(Version) did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>VersionHistory.getAncestor(int)</code> returns the right
      * ancestor
      */
@@ -387,6 +480,18 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.getBaseVersion()</code> throws an {@link
+     * javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testGetBaseVersionJcr2() throws Exception {
+        try {
+            versionManager.getBaseVersion(vHistory.getPath());
+            fail("VersionHistory.getBaseVersion() did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>VersionHistory.getCorrespondingNodePath(String)</code>
      * returns the right path
      */
@@ -421,6 +526,18 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.getLock()</code> throws an {@link
+     * javax.jcr.lock.LockException}
+     */
+    public void testGetLockJcr2() throws Exception {
+        try {
+            vHistory.getSession().getWorkspace().getLockManager().getLock(vHistory.getPath());
+            fail("VersionHistory should not be lockable: VersionHistory.getLock() did not throw a LockException");
+        } catch (LockException success) {
+        }
+    }
+
+    /**
      * Tests if <code>VersionHistory.getMixinNodeTypes()</code> does not return
      * null.
      */
@@ -556,6 +673,13 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.getIdentifier()</code> returns the right UUID
+     */
+    public void testGetIdentifier() throws Exception {
+        assertEquals("VersionHistory.getIdentifier() did not return the right Id", versionableNode.getProperty(jcrVersionHistory).getString(), vHistory.getIdentifier());
+    }
+
+    /**
      * Tests if <code>VersionHistory.getVersionHistory()</code> throws an {@link
      * javax.jcr.UnsupportedRepositoryOperationException}
      */
@@ -568,6 +692,18 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.getVersionHistory()</code> throws an {@link
+     * javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testGetVersionHistoryJcr2() throws Exception {
+        try {
+            versionManager.getVersionHistory(vHistory.getPath());
+            fail("VersionHistory.getVersionHistory() did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>VersionHistory.hasNode(String)</code> returns the right
      * <code>boolean</code> value
      */
@@ -608,6 +744,14 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.holdsLock()</code> returns
+     * <code>false</code>
+     */
+    public void testHoldsLockJcr2() throws Exception {
+        assertFalse("VersionHistory.holdsLock() did not return false", vHistory.getSession().getWorkspace().getLockManager().holdsLock(vHistory.getPath()));
+    }
+
+    /**
      * Tests if <code>VersionHistory.isCheckedOut()</code> returns
      * <code>true</code>
      */
@@ -616,6 +760,14 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.isCheckedOut()</code> returns
+     * <code>true</code>
+     */
+    public void testIsCheckedOutJcr2() throws Exception {
+        assertTrue("VersionHistory.isCheckedOut() did not return true", versionManager.isCheckedOut(vHistory.getPath()));
+    }
+
+    /**
      * Tests if <code>VersionHistory.isLocked()</code> returns
      * <code>false</code>
      */
@@ -624,6 +776,14 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.isLocked()</code> returns
+     * <code>false</code>
+     */
+    public void testIsLockedJcr2() throws Exception {
+        assertFalse("VersionHistory.isLocked() did not return false", vHistory.getSession().getWorkspace().getLockManager().isLocked(vHistory.getPath()));
+    }
+
+    /**
      * Tests if <code>VersionHistory.isModified()</code> returns
      * <code>false</code>
      */
@@ -689,6 +849,35 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.lock(boolean, boolean)</code> throws a
+     * {@link javax.jcr.lock.LockException}
+     */
+    public void testLockJcr2() throws Exception {
+        LockManager lockManager = vHistory.getSession().getWorkspace().getLockManager();
+        String path = vHistory.getPath();
+        try {
+            lockManager.lock(path, true, true, 60, "");
+            fail("VersionHistory should not be lockable: VersionHistory.lock(true,true) did not throw a LockException");
+        } catch (LockException success) {
+        }
+        try {
+            lockManager.lock(path, true, false, 60, "");
+            fail("VersionHistory should not be lockable: VersionHistory.lock(true,false) did not throw a LockException");
+        } catch (LockException success) {
+        }
+        try {
+            lockManager.lock(path, false, true, 60, "");
+            fail("VersionHistory should not be lockable: VersionHistory.lock(false,true) did not throw a LockException");
+        } catch (LockException success) {
+        }
+        try {
+            lockManager.lock(path, false, false, 60, "");
+            fail("VersionHistory should not be lockable: VersionHistory.lock(false,false) did not throw a UnsupportedRepositoryOperationException");
+        } catch (LockException success) {
+        }
+    }
+
+    /**
      * Tests if <code>VersionHistory.merge(String)</code> throws an
      * {@link javax.jcr.nodetype.ConstraintViolationException}
      */
@@ -706,6 +895,25 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.merge(String)</code> throws an
+     * {@link javax.jcr.nodetype.ConstraintViolationException}
+     */
+/*
+    TODO: check why this fails
+    public void testMergeJcr2() throws Exception {
+        try {
+            versionManager.merge(vHistory.getPath(), workspaceName, true);
+            fail("VersionHistory.merge(String, true) did not throw an ConstraintViolationException");
+        } catch (ConstraintViolationException success) {
+        }
+        try {
+            versionManager.merge(vHistory.getPath(), workspaceName, false);
+            fail("VersionHistory.merge(String, false) did not throw an ConstraintViolationException");
+        } catch (ConstraintViolationException success) {
+        }
+    }
+*/
+    /**
      * Tests if <code>VersionHistory.orderBefore(String, String)</code> throws
      * an {@link javax.jcr.UnsupportedRepositoryOperationException}
      */
@@ -780,6 +988,25 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.restore(String, boolean)</code> and
+     * <code>VersionHistory.restore(Version, boolean)</code> throw an {@link
+     * UnsupportedRepositoryOperationException} and <code>VersionHistory.restore(Version,
+     * String, boolean)</code> throws a {@link ConstraintViolationException}.
+     */
+    public void testRestoreJcr2() throws Exception {
+        try {
+            versionManager.restore(vHistory.getPath(), "abc", true);
+            fail("VersionHistory.restore(String,boolean) did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+        try {
+            versionManager.restore(vHistory.getPath(), version, true);
+            fail("VersionHistory.restore(Version,boolean) did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>VersionHistory.restoreByLabel(String, boolean)</code>
      * throws an {@link javax.jcr.UnsupportedRepositoryOperationException}
      */
@@ -792,6 +1019,18 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.restoreByLabel(String, boolean)</code>
+     * throws an {@link javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testRestoreByLabelJcr2() throws Exception {
+        try {
+            versionManager.restoreByLabel(vHistory.getPath(), "abc", true);
+            fail("VersionHistory.restoreByLabel(String,boolean) did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <ul> <li><code>VersionHistory.setProperty(String,
      * String[])</code></li> <li><code>VersionHistory.setProperty(String,
      * String[], int)</code></li> <li><code>VersionHistory.setProperty(String,
@@ -819,37 +1058,37 @@
 
         try {
             vHistory.setProperty(propertyName1, s);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.setProperty(String,String[]) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             vHistory.setProperty(propertyName1, s, PropertyType.STRING);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.setProperty(String,String[],int) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             vHistory.setProperty(propertyName1, vArray);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Value[]) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             vHistory.setProperty(propertyName1, vArray, PropertyType.STRING);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Value[],int]) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             vHistory.setProperty(propertyName1, true);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.setProperty(String,boolean) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             vHistory.setProperty(propertyName1, 123);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.setProperty(String,double) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
@@ -857,39 +1096,39 @@
             byte[] bytes = {73, 26, 32, -36, 40, -43, -124};
             InputStream inpStream = new ByteArrayInputStream(bytes);
             vHistory.setProperty(propertyName1, inpStream);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.setProperty(String,InputStream) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             vHistory.setProperty(propertyName1, "abc");
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.setProperty(String,String) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             Calendar c = new GregorianCalendar(1945, 1, 6, 16, 20, 0);
             vHistory.setProperty(propertyName1, c);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Calendar) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             vHistory.setProperty(propertyName1, testRootNode);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Node) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             Value v = superuser.getValueFactory().createValue("abc");
             vHistory.setProperty(propertyName1, v);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Value) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             vHistory.setProperty(propertyName1, -2147483650L);
-            vHistory.save();
+            vHistory.getSession().save();
             fail("VersionHistory should be read-only: VersionHistory.setProperty(String,long) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
@@ -908,6 +1147,18 @@
     }
 
     /**
+     * Tests if <code>VersionHistory.unlock()</code> throws a {@link
+     * javax.jcr.lock.LockException}
+     */
+    public void testUnlockJcr2() throws Exception {
+        try {
+            vHistory.getSession().getWorkspace().getLockManager().unlock(vHistory.getPath());
+            fail("VersionHistory should not be lockable: VersionHistory.unlock() did not throw a LockException");
+        } catch (LockException success) {
+        }
+    }
+
+    /**
      * Tests if <code>VersionHistory.update(String)</code> throws an
      * {@link javax.jcr.nodetype.ConstraintViolationException}
      */

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionLabelTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionLabelTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionLabelTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionLabelTest.java Fri May 22 14:38:51 2009
@@ -24,6 +24,7 @@
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
+import javax.jcr.version.VersionManager;
 
 /**
  * <code>VersionLabelTest</code> covers methods related to version label such as
@@ -61,7 +62,7 @@
 
         jcrVersionLabels = superuser.getNamespacePrefix(NS_JCR_URI) + ":versionLabels";
 
-        vHistory = versionableNode.getVersionHistory();
+        vHistory = versionableNode.getSession().getWorkspace().getVersionManager().getVersionHistory(versionableNode.getPath());
         rootVersion = vHistory.getRootVersion();
 
         if (vHistory.hasVersionLabel(versionLabel)) {
@@ -141,6 +142,24 @@
     }
 
     /**
+     * Test if the a label added with VersionHistory.addVersionLabel(String,
+     * String, boolean) corresponds to adding a reference property to the
+     * jcr:versionLabels node of this history node, with the label as name of
+     * the property, and the reference targeting the version.
+     *
+     * @see VersionHistory#addVersionLabel(String, String, boolean)
+     */
+    public void testAddVersionCheckVersionLabelsNodeJcr2() throws RepositoryException {
+        vHistory.addVersionLabel(rootVersion.getName(), versionLabel, false);
+
+        // get jcr:versionLabels node
+        vHistory = versionableNode.getSession().getWorkspace().getVersionManager().getVersionHistory(versionableNode.getPath());
+        Node versionLabelNode = vHistory.getNode(jcrVersionLabels);
+
+        assertTrue("The version label that has been successfully added must be present in the node '" + jcrVersionLabels + "'.", versionLabelNode.getProperty(versionLabel).getString().equals(rootVersion.getUUID()));
+    }
+
+    /**
      * Test if VersionHistory.hasVersionLabel(String) returns true, if the label
      * has beed successfully added before.
      *
@@ -198,6 +217,27 @@
     }
 
     /**
+     * Test if VersionHistory.addVersionLabel(versionName, label, moveLabel)
+     * throws VersionException the label already exists and if moveLabel is false)
+     *
+     * @throws RepositoryException
+     */
+    public void testAddDuplicateVersionLabelJcr2() throws RepositoryException {
+        vHistory.addVersionLabel(rootVersion.getName(), versionLabel, false);
+        try {
+            VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
+            String path = versionableNode.getPath();
+            versionManager.checkout(path);
+            Version v = versionManager.checkin(path);
+            vHistory.addVersionLabel(v.getName(), versionLabel, false);
+
+            fail("Adding a version label that already exist in the version history must throw a VersionException.");
+        } catch (VersionException e) {
+            //success
+        }
+    }
+
+    /**
      * Test if the 'moveLabel' flag moves an existing version label.
      *
      * @throws RepositoryException
@@ -220,6 +260,30 @@
     }
 
     /**
+     * Test if the 'moveLabel' flag moves an existing version label.
+     *
+     * @throws RepositoryException
+     * @see VersionHistory#addVersionLabel(String, String, boolean)  with boolan flag equals true.
+     */
+    public void testMoveLabelJcr2() throws RepositoryException {
+        vHistory.addVersionLabel(rootVersion.getName(), versionLabel, false);
+        try {
+            VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
+            String path = versionableNode.getPath();
+            versionManager.checkout(path);
+            Version v = versionManager.checkin(path);
+            vHistory.addVersionLabel(v.getName(), versionLabel, true);
+
+            if (!vHistory.hasVersionLabel(v, versionLabel)) {
+                fail("If 'moveLabel' is true, an existing version label must be moved to the indicated version.");
+            }
+
+        } catch (VersionException e) {
+            fail("If 'moveLabel' is true, an existing version label must be moved to the indicated version.");
+        }
+    }
+
+    /**
      * Test the removal of an version label that does not exist (must throw VersionException).
      *
      * @throws RepositoryException
@@ -295,6 +359,38 @@
     }
 
     /**
+     * Test VersionHistory.getVersionLabels() returns all labels present on the version history.
+     *
+     * @throws RepositoryException
+     * @see javax.jcr.version.VersionHistory#getVersionLabels()
+     */
+    public void testGetVersionLabelsJcr2() throws RepositoryException {
+
+        HashSet testLabels = new HashSet(Arrays.asList(vHistory.getVersionLabels()));
+
+        VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
+        String path = versionableNode.getPath();
+        versionManager.checkout(path);
+        Version v = versionManager.checkin(path);
+
+        vHistory.addVersionLabel(v.getName(), versionLabel, false);
+        testLabels.add(versionLabel);
+        vHistory.addVersionLabel(rootVersion.getName(), versionLabel2, false);
+        testLabels.add(versionLabel2);
+
+        String[] labels = vHistory.getVersionLabels();
+        for (int i = 0; i < labels.length; i++) {
+            String l = labels[i];
+            if (!testLabels.contains(l)) {
+                fail("VersionHistory.getVersionLabels() must only return labels, that have been added to the history.");
+            }
+            testLabels.remove(l);
+        }
+
+        assertTrue("VersionHistory.getVersionLabels() must return all labels, that have been added to the history.", testLabels.isEmpty());
+    }
+
+    /**
      * Test VersionHistory.getVersionLabels(Version) only returns all labels present
      * for the specified version.
      *
@@ -326,6 +422,39 @@
     }
 
     /**
+     * Test VersionHistory.getVersionLabels(Version) only returns all labels present
+     * for the specified version.
+     *
+     * @throws RepositoryException
+     * @see VersionHistory#getVersionLabels(javax.jcr.version.Version)
+     */
+    public void testGetVersionLabelsForVersionJcr2() throws RepositoryException {
+
+        HashSet testLabels = new HashSet(Arrays.asList(vHistory.getVersionLabels(rootVersion)));
+
+        vHistory.addVersionLabel(rootVersion.getName(), versionLabel, false);
+        testLabels.add(versionLabel);
+
+        // add a version label to another version (not added to the testLabel set)
+        VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
+        String path = versionableNode.getPath();
+        versionManager.checkout(path);
+        Version v = versionManager.checkin(path);
+        vHistory.addVersionLabel(v.getName(), versionLabel2, false);
+
+        String[] labels = vHistory.getVersionLabels(rootVersion);
+        for (int i = 0; i < labels.length; i++) {
+            String l = labels[i];
+            if (!testLabels.contains(l)) {
+                fail("VersionHistory.getVersionLabels(Version) must only return labels, that have been added for this version.");
+            }
+            testLabels.remove(l);
+        }
+
+        assertTrue("VersionHistory.getVersionLabels(Version)  must return all labels, that have been added for this version.", testLabels.isEmpty());
+    }
+
+    /**
      * Test calling Node.restoreByLabel(String, boolean) on a non-versionable node.
      *
      * @throws javax.jcr.RepositoryException
@@ -341,6 +470,21 @@
     }
 
     /**
+     * Test calling Node.restoreByLabel(String, boolean) on a non-versionable node.
+     *
+     * @throws javax.jcr.RepositoryException
+     * @see javax.jcr.Node#restoreByLabel(String, boolean)
+     */
+    public void testRestoreByLabelNonVersionableNodeJcr2() throws RepositoryException {
+        try {
+            nonVersionableNode.getSession().getWorkspace().getVersionManager().restoreByLabel(nonVersionableNode.getPath(), versionLabel, true);
+            fail("Node.restoreByLabel(String, boolean) on a non versionable node must throw UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException e) {
+            //success
+        }
+    }
+
+    /**
      * Test if versionHistory.getVersionLabels(Version) throws a VersionException if the
      * specified version is not in this version history.
      */

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/VersionTest.java Fri May 22 14:38:51 2009
@@ -19,6 +19,7 @@
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
 import javax.jcr.ItemVisitor;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -29,6 +30,7 @@
 import javax.jcr.Value;
 import javax.jcr.PropertyType;
 import javax.jcr.lock.LockException;
+import javax.jcr.lock.LockManager;
 
 import java.util.GregorianCalendar;
 import java.util.Calendar;
@@ -48,6 +50,7 @@
  */
 public class VersionTest extends AbstractVersionTest {
 
+    private VersionManager versionManager;
     private Version version;
     private Version version2;
 
@@ -73,15 +76,17 @@
     protected void setUp() throws Exception {
         super.setUp();
 
+        versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
+
         // create two versions
-        version = versionableNode.checkin();
-        versionableNode.checkout();
-        version2 = versionableNode.checkin();
+        version = versionManager.checkin(versionableNode.getPath());
+        versionManager.checkout(versionableNode.getPath());
+        version2 = versionManager.checkin(versionableNode.getPath());
     }
 
     protected void tearDown() throws Exception {
         // check the node out, so that it can be removed
-        versionableNode.checkout();
+        versionManager.checkout(versionableNode.getPath());
         version = null;
         version2 = null;
         super.tearDown();
@@ -116,13 +121,13 @@
     public void testAddNode() throws Exception {
         try {
             version.addNode(nodeName4);
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.addNode(String) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             version.addNode(nodeName4, ntBase);
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.addNode(String,String) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
@@ -149,6 +154,18 @@
     }
 
     /**
+     * Tests if <code>Version.cancelMerge(Version)</code> throws an {@link
+     * javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testCancelMergeJcr2() throws Exception {
+        try {
+            versionManager.cancelMerge(version.getPath(), version2);
+            fail("Version.cancelMerge(Version) did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>Version.checkin()</code> throws an {@link
      * javax.jcr.UnsupportedRepositoryOperationException}
      */
@@ -161,6 +178,18 @@
     }
 
     /**
+     * Tests if <code>Version.checkin()</code> throws an {@link
+     * javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testCheckinJcr2() throws Exception {
+        try {
+            versionManager.checkin(version.getPath());
+            fail("Version.checkin() did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>Version.checkout()</code> throws an {@link
      * javax.jcr.UnsupportedRepositoryOperationException}
      */
@@ -173,6 +202,18 @@
     }
 
     /**
+     * Tests if <code>Version.checkout()</code> throws an {@link
+     * javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testCheckoutJcr2() throws Exception {
+        try {
+            versionManager.checkout(version.getPath());
+            fail("Version.checkout() did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>Version.doneMerge(Version)</code> throws an {@link
      * javax.jcr.UnsupportedRepositoryOperationException}
      */
@@ -185,6 +226,18 @@
     }
 
     /**
+     * Tests if <code>Version.doneMerge(Version)</code> throws an {@link
+     * javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testDoneMergeJcr2() throws Exception {
+        try {
+            versionManager.doneMerge(version.getPath(), version2);
+            fail("Version should not be versionable: Version.doneMerge(Version) did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>Version.getAncestor(int)</code> returns the right
      * ancestor
      */
@@ -205,6 +258,18 @@
     }
 
     /**
+     * Tests if <code>Version.getBaseVersion()</code> throws an {@link
+     * javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testGetBaseVersionJcr2() throws Exception {
+        try {
+            versionManager.getBaseVersion(version.getPath());
+            fail("Version.getBaseVersion() did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>Version.getCorrespondingNodePath(String)</code> returns
      * the right path
      */
@@ -239,6 +304,18 @@
     }
 
     /**
+     * Tests if <code>Version.getLock()</code> throws a {@link
+     * javax.jcr.lock.LockException}
+     */
+    public void testGetLockJcr2() throws Exception {
+        try {
+            version.getSession().getWorkspace().getLockManager().getLock(version.getPath());
+            fail("Version should not be lockable: Version.getLock() did not throw a LockException");
+        } catch (LockException success) {
+        }
+    }
+
+    /**
      * Tests if <code>Version.getMixinNodeTypes()</code> does not return null.
      */
     public void testGetMixinNodeTypes() throws Exception {
@@ -356,6 +433,18 @@
     }
 
     /**
+     * Tests if <code>Version.getVersionHistory()</code> throws an {@link
+     * javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testGetVersionHistoryJcr2() throws Exception {
+        try {
+            versionManager.getVersionHistory(version.getPath());
+            fail("Version.getVersionHistory() did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>Version.getUUID()</code> returns the right UUID
      */
     public void testGetUUID() throws Exception {
@@ -401,6 +490,13 @@
     }
 
     /**
+     * Tests if <code>Version.holdsLock()</code> returns <code>false</code>
+     */
+    public void testHoldsLockJcr2() throws Exception {
+        assertFalse("Version.holdsLock() did not return false", version.getSession().getWorkspace().getLockManager().holdsLock(version.getPath()));
+    }
+
+    /**
      * Tests if <code>Version.isCheckedOut()</code> returns <code>true</code>
      */
     public void testIsCheckedOut() throws Exception {
@@ -408,6 +504,13 @@
     }
 
     /**
+     * Tests if <code>Version.isCheckedOut()</code> returns <code>true</code>
+     */
+    public void testIsCheckedOutJcr2() throws Exception {
+        assertTrue("Version.isCheckedOut() did not return true", versionManager.isCheckedOut(version.getPath()));
+    }
+
+    /**
      * Tests if <code>Version.isLocked()</code> returns <code>false</code>
      */
     public void testIsLocked() throws Exception {
@@ -415,6 +518,13 @@
     }
 
     /**
+     * Tests if <code>Version.isLocked()</code> returns <code>false</code>
+     */
+    public void testIsLockedJcr2() throws Exception {
+        assertFalse("Version.isLocked() did not return false", version.getSession().getWorkspace().getLockManager().isLocked(version.getPath()));
+    }
+
+    /**
      * Tests if <code>Version.isModified()</code> returns <code>false</code>
      */
     public void testIsModified() throws Exception {
@@ -452,6 +562,14 @@
     }
 
     /**
+     * Tests if <code>Version.isSame()</code> returns the right
+     * <code>boolean</code> value
+     */
+    public void testIsSameJcr2() throws Exception {
+        assertTrue("Version.isSame(Item) did not return true", version2.isSame(versionManager.getBaseVersion(versionableNode.getPath())));
+    }
+
+    /**
      * Tests if <code>Version.lock(boolean, boolean)</code> throws a {@link
      * LockException}
      */
@@ -479,6 +597,35 @@
     }
 
     /**
+     * Tests if <code>Version.lock(boolean, boolean)</code> throws a {@link
+     * LockException}
+     */
+    public void testLockJcr2() throws Exception {
+        LockManager lockManager = version.getSession().getWorkspace().getLockManager();
+        String path = version.getPath();
+        try {
+            lockManager.lock(path, true, true, 60, "");
+            fail("Version should not be lockable: Version.lock(true,true) did not throw a LockException");
+        } catch (LockException success) {
+        }
+        try {
+            lockManager.lock(path, true, false, 60, "");
+            fail("Version should not be lockable: Version.lock(true,false) did not throw a LockException");
+        } catch (LockException success) {
+        }
+        try {
+            lockManager.lock(path, false, true, 60, "");
+            fail("Version should not be lockable: Version.lock(false,true) did not throw a LockException");
+        } catch (LockException success) {
+        }
+        try {
+            lockManager.lock(path, false, false, 60, "");
+            fail("Version should not be lockable: Version.lock(false,false) did not throw a LockException");
+        } catch (LockException success) {
+        }
+    }
+
+    /**
      * Tests if <code>Version.merge(String)</code> throws an
      * {@link javax.jcr.nodetype.ConstraintViolationException}
      */
@@ -496,6 +643,25 @@
     }
 
     /**
+     * Tests if <code>Version.merge(String)</code> throws an
+     * {@link javax.jcr.nodetype.ConstraintViolationException}
+     */
+/*
+    TODO: check why this fails
+    public void testMergeJcr2() throws Exception {
+        try {
+            versionManager.merge(version.getPath(), workspaceName, true);
+            fail("Version.merge(String, true) did not throw an ConstraintViolationException");
+        } catch (ConstraintViolationException success) {
+        }
+        try {
+            versionManager.merge(version.getPath(),workspaceName, false);
+            fail("Version.merge(String, false) did not throw an ConstraintViolationException");
+        } catch (ConstraintViolationException success) {
+        }
+    }
+*/
+    /**
      * Tests if <code>Version.orderBefore(String, String)</code> throws an
      * {@link javax.jcr.UnsupportedRepositoryOperationException}
      */
@@ -525,7 +691,7 @@
     public void testRemove() throws Exception {
         try {
             version.remove();
-            versionableNode.getVersionHistory().save();
+            versionableNode.getSession().save();
             fail("Version should be read-only: Version.remove() did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
@@ -569,6 +735,26 @@
     }
 
     /**
+     * Tests if <code>Version.restore(String, boolean)</code> and
+     * <code>Version.restore(Version, boolean)</code> throw an
+     * {@link UnsupportedRepositoryOperationException} and
+     * <code>Version.restore(Version, String, boolean)</code> throws a
+     * {@link ConstraintViolationException}.
+     */
+    public void testRestoreJcr2() throws Exception {
+        try {
+            versionManager.restore(version.getPath(), "abc", true);
+            fail("Version.restore(String,boolean) did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+        try {
+            versionManager.restore(version.getPath(), version2, true);
+            fail("Version.restore(Version,boolean) did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if <code>Version.restoreByLabel(String, boolean)</code> throws an
      * {@link javax.jcr.UnsupportedRepositoryOperationException}
      */
@@ -581,6 +767,18 @@
     }
 
     /**
+     * Tests if <code>Version.restoreByLabel(String, boolean)</code> throws an
+     * {@link javax.jcr.UnsupportedRepositoryOperationException}
+     */
+    public void testRestoreByLabelJcr2() throws Exception {
+        try {
+            versionManager.restoreByLabel(version.getPath(), "abc", true);
+            fail("Version.restoreByLabel(String,boolean) did not throw an UnsupportedRepositoryOperationException");
+        } catch (UnsupportedRepositoryOperationException success) {
+        }
+    }
+
+    /**
      * Tests if
      * <ul> <li><code>Version.setProperty(String, String[])</code></li>
      * <li><code>Version.setProperty(String, String[], int)</code></li>
@@ -610,37 +808,37 @@
 
         try {
             version.setProperty(propertyName1, s);
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.setProperty(String,String[]) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             version.setProperty(propertyName1, s, PropertyType.STRING);
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.setProperty(String,String[],int) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             version.setProperty(propertyName1, vArray);
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.setProperty(String,Value[]) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             version.setProperty(propertyName1, vArray, PropertyType.STRING);
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.setProperty(String,Value[],int]) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             version.setProperty(propertyName1, true);
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.setProperty(String,boolean) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             version.setProperty(propertyName1, 123);
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.setProperty(String,double) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
@@ -648,39 +846,39 @@
             byte[] bytes = {73, 26, 32, -36, 40, -43, -124};
             InputStream inpStream = new ByteArrayInputStream(bytes);
             version.setProperty(propertyName1, inpStream);
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.setProperty(String,InputStream) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             version.setProperty(propertyName1, "abc");
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.setProperty(String,String) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             Calendar c = new GregorianCalendar(1945, 1, 6, 16, 20, 0);
             version.setProperty(propertyName1, c);
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.setProperty(String,Calendar) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             version.setProperty(propertyName1, testRootNode);
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.setProperty(String,Node) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             Value v = superuser.getValueFactory().createValue("abc");
             version.setProperty(propertyName1, v);
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.setProperty(String,Value) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
         try {
             version.setProperty(propertyName1, -2147483650L);
-            version.save();
+            version.getSession().save();
             fail("Version should be read-only: Version.setProperty(String,long) did not throw a ConstraintViolationException");
         } catch (ConstraintViolationException success) {
         }
@@ -699,6 +897,18 @@
     }
 
     /**
+     * Tests if <code>Version.unlock()</code> throws a {@link
+     * javax.jcr.lock.LockException}
+     */
+    public void testUnlockJcr2() throws Exception {
+        try {
+            version.getSession().getWorkspace().getLockManager().unlock(version.getPath());
+            fail("Version should not be lockable: Version.unlock() did not throw a LockException");
+        } catch (LockException success) {
+        }
+    }
+
+    /**
      * Tests if <code>VersionHistory.update(String)</code> throws an
      * {@link javax.jcr.nodetype.ConstraintViolationException}
      */

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/WorkspaceRestoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/WorkspaceRestoreTest.java?rev=777548&r1=777547&r2=777548&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/WorkspaceRestoreTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/WorkspaceRestoreTest.java Fri May 22 14:38:51 2009
@@ -22,6 +22,7 @@
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionException;
 import javax.jcr.version.OnParentVersionAction;
+import javax.jcr.version.VersionManager;
 import javax.jcr.Session;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -57,11 +58,13 @@
     protected void setUp() throws Exception {
         super.setUp();
 
-        version = versionableNode.checkin();
-        versionableNode.checkout();
-        version2 = versionableNode.checkin();
-        versionableNode.checkout();
-        rootVersion = versionableNode.getVersionHistory().getRootVersion();
+        VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
+        String path = versionableNode.getPath();
+        version = versionManager.checkin(path);
+        versionManager.checkout(path);
+        version2 = versionManager.checkin(path);
+        versionManager.checkout(path);
+        rootVersion = versionManager.getVersionHistory(path).getRootVersion();
 
         // build a second versionable node below the testroot
         try {
@@ -102,11 +105,11 @@
             // and check versionable nodes out.
             wTestRoot = (Node) wSuperuser.getItem(testRootNode.getPath());
 
-            wVersionableNode = wSuperuser.getNodeByUUID(versionableNode.getUUID());
-            wVersionableNode.checkout();
+            wVersionableNode = wSuperuser.getNodeByIdentifier(versionableNode.getIdentifier());
+            wVersionableNode.getSession().getWorkspace().getVersionManager().checkout(wVersionableNode.getPath());
 
-            wVersionableNode2 = wSuperuser.getNodeByUUID(versionableNode2.getUUID());
-            wVersionableNode2.checkout();
+            wVersionableNode2 = wSuperuser.getNodeByIdentifier(versionableNode2.getIdentifier());
+            wVersionableNode2.getSession().getWorkspace().getVersionManager().checkout(wVersionableNode2.getPath());
 
         } catch (RepositoryException e) {
             fail("Failed to setup test environment in workspace: " + e.toString());
@@ -121,9 +124,11 @@
         }
 
         // create a version of the versionable child node
-        wVersionableChildNode.checkout();
-        wChildVersion = wVersionableChildNode.checkin();
-        wVersionableChildNode.checkout();
+        VersionManager wVersionManager = wVersionableChildNode.getSession().getWorkspace().getVersionManager();
+        String wPath = wVersionableChildNode.getPath();
+        wVersionManager.checkout(wPath);
+        wChildVersion = wVersionManager.checkin(wPath);
+        wVersionManager.checkout(wPath);
     }
 
 
@@ -174,6 +179,27 @@
     }
 
     /**
+     * Test if InvalidItemStateException is thrown if the session affected by
+     * VersionManager.restore(Version[], boolean) has pending changes.
+     */
+    public void testWorkspaceRestoreWithPendingChangesJcr2() throws RepositoryException {
+        versionableNode.getSession().getWorkspace().getVersionManager().checkout(versionableNode.getPath());
+        try {
+            // modify node without calling save()
+            versionableNode.setProperty(propertyName1, propertyValue);
+
+            // create version in second workspace
+            Version v = wVersionableNode.getSession().getWorkspace().getVersionManager().checkin(wVersionableNode.getPath());
+            // try to restore that version
+            superuser.getWorkspace().getVersionManager().restore(new Version[]{v}, false);
+
+            fail("InvalidItemStateException must be thrown on attempt to call Workspace.restore(Version[], boolean) in a session having any unsaved changes pending.");
+        } catch (InvalidItemStateException e) {
+            // success
+        }
+    }
+
+    /**
      * Test if VersionException is thrown if the specified version array does
      * not contain a version that has a corresponding node in this workspace.
      */
@@ -187,6 +213,19 @@
     }
 
     /**
+     * Test if VersionException is thrown if the specified version array does
+     * not contain a version that has a corresponding node in this workspace.
+     */
+    public void testWorkspaceRestoreHasCorrespondingNodeJcr2() throws RepositoryException {
+        try {
+            superuser.getWorkspace().getVersionManager().restore(new Version[]{wChildVersion}, false);
+            fail("Workspace.restore(Version[], boolean) must throw VersionException if non of the specified versions has a corresponding node in the workspace.");
+        } catch (VersionException e) {
+            // success
+        }
+    }
+
+    /**
      * Test if Workspace.restore(Version[], boolean) succeeds if the following two
      * preconditions are fulfilled:<ul>
      * <li>For every version V in S that corresponds to a missing node in the workspace,
@@ -206,6 +245,25 @@
     }
 
     /**
+     * Test if VersionManager.restore(Version[], boolean) succeeds if the following two
+     * preconditions are fulfilled:<ul>
+     * <li>For every version V in S that corresponds to a missing node in the workspace,
+     * there must also be a parent of V in S.</li>
+     * <li>S must contain at least one version that corresponds to an existing
+     * node in the workspace.</li>
+     * </ul>
+     */
+    public void testWorkspaceRestoreWithParentJcr2() throws RepositoryException {
+
+        try {
+            Version parentV = wVersionableNode.getSession().getWorkspace().getVersionManager().checkin(wVersionableNode.getPath());
+            superuser.getWorkspace().getVersionManager().restore(new Version[]{parentV, wChildVersion}, false);
+        } catch (RepositoryException e) {
+            fail("Workspace.restore(Version[], boolean) with a version that has no corresponding node must succeed if a version of a parent with correspondance is present in the version array.");
+        }
+    }
+
+    /**
      * Test if the removeExisting-flag removes an existing node in case of uuid conflict.
      */
     public void testWorkspaceRestoreWithRemoveExisting() throws NotExecutableException, RepositoryException {
@@ -227,6 +285,27 @@
     }
 
     /**
+     * Test if the removeExisting-flag removes an existing node in case of uuid conflict.
+     */
+    public void testWorkspaceRestoreWithRemoveExistingJcr2() throws NotExecutableException, RepositoryException {
+        // create version for parentNode of childNode
+        superuser.getWorkspace().clone(workspaceName, wVersionableChildNode.getPath(), wVersionableChildNode.getPath(), false);
+        Version parentV = versionableNode.getSession().getWorkspace().getVersionManager().checkin(versionableNode.getPath());
+
+        // move child node in order to produce the uuid conflict
+        String newChildPath = wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName();
+        wSuperuser.move(wVersionableChildNode.getPath(), newChildPath);
+        wSuperuser.save();
+
+        // restore the parent with removeExisting == true >> moved child node
+        // must be removed.
+        wSuperuser.getWorkspace().getVersionManager().restore(new Version[]{parentV}, true);
+        if (wSuperuser.itemExists(newChildPath)) {
+            fail("Workspace.restore(Version[], boolean) with the boolean flag set to true, must remove the existing node in case of Uuid conflict.");
+        }
+    }
+
+    /**
      * Tests if restoring the <code>Version</code> of an existing node throws an
      * <code>ItemExistsException</code> if removeExisting is set to FALSE.
      */
@@ -250,6 +329,32 @@
         }
     }
 
+    /**
+     * Tests if restoring the <code>Version</code> of an existing node throws an
+     * <code>ItemExistsException</code> if removeExisting is set to FALSE.
+     */
+    public void testWorkspaceRestoreWithUUIDConflictJcr2() throws RepositoryException, NotExecutableException {
+        try {
+            // Verify that nodes used for the test are indeed versionable
+            NodeDefinition nd = wVersionableNode.getDefinition();
+            if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) {
+                throw new NotExecutableException("Nodes must be versionable in order to run this test.");
+            }
+
+            VersionManager versionManager = wVersionableNode.getSession().getWorkspace().getVersionManager();
+            String path = wVersionableNode.getPath();
+            Version v = versionManager.checkin(path);
+            versionManager.checkout(path);
+            wSuperuser.move(wVersionableChildNode.getPath(), wVersionableNode2.getPath() + "/" + wVersionableChildNode.getName());
+            wSuperuser.save();
+            wSuperuser.getWorkspace().getVersionManager().restore(new Version[]{v}, false);
+
+            fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false.");
+        } catch (ItemExistsException e) {
+            // success
+        }
+    }
+
 
     /**
      * Test if workspace-restoring a node works on checked-in node.
@@ -262,6 +367,18 @@
     }
 
     /**
+     * Test if workspace-restoring a node works on checked-in node.
+     */
+    public void testWorkspaceRestoreOnCheckedInNodeJcr2() throws RepositoryException {
+        VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
+        String path = versionableNode.getPath();
+        if (versionManager.isCheckedOut(path)) {
+            versionManager.checkin(path);
+        }
+        superuser.getWorkspace().getVersionManager().restore(new Version[]{version}, true);
+    }
+
+    /**
      * Test if workspace-restoring a node works on checked-out node.
      */
     public void testWorkspaceRestoreOnCheckedOutNode() throws RepositoryException {
@@ -271,4 +388,15 @@
         superuser.getWorkspace().restore(new Version[]{version}, true);
     }
 
+    /**
+     * Test if workspace-restoring a node works on checked-out node.
+     */
+    public void testWorkspaceRestoreOnCheckedOutNodeJcr2() throws RepositoryException {
+        VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
+        String path = versionableNode.getPath();
+        if (!versionManager.isCheckedOut(path)) {
+            versionManager.checkout(path);
+        }
+        superuser.getWorkspace().getVersionManager().restore(new Version[]{version}, true);
+    }
 }