You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2005/04/19 13:28:28 UTC

svn commit: r161873 - in incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core/version/VersionManagerImpl.java test/org/apache/jackrabbit/test/api/version/RemoveVersionTest.java

Author: mreutegg
Date: Tue Apr 19 04:28:27 2005
New Revision: 161873

URL: http://svn.apache.org/viewcvs?view=rev&rev=161873
Log:
- Minor fixes in jackrabbit that caused versioning test cases to fail.
- Added test case for ReferentialIntegrityException

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/RemoveVersionTest.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?view=diff&r1=161872&r2=161873
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java Tue Apr 19 04:28:27 2005
@@ -35,9 +35,9 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.PropertyIterator;
 import javax.jcr.NodeIterator;
-import javax.jcr.Session;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
+import javax.jcr.version.VersionException;
 import java.util.Iterator;
 import java.util.List;
 import java.util.ArrayList;
@@ -260,12 +260,21 @@
 
     /**
      * Removes the specified version from the history
-     * @param history
-     * @param name
+     *
+     * @param history the version history from where to remove the version.
+     * @param name the name of the version to remove.
+     * @throws VersionException if the version <code>history</code> does
+     *  not have a version with <code>name</code>.
+     * @throws RepositoryException if any other error occurs.
      */
     public void removeVersion(VersionHistory history, QName name)
             throws RepositoryException {
+        if (!((VersionHistoryImpl) history).hasNode(name)) {
+            throw new VersionException("Version with name " + name.toString()
+                    + " does not exist in this VersionHistory");
+        }
         // generate observation events
+        SessionImpl session = (SessionImpl) history.getSession();
         VersionImpl version = (VersionImpl) ((VersionHistoryImpl) history).getNode(name);
         List events = new ArrayList();
         recursiveRemove(events, (NodeImpl) history, version);
@@ -274,7 +283,7 @@
         vh.removeVersion(name);
 
         virtProvider.invalidateItem(new NodeId(vh.getId()));
-        obsMgr.dispatch(events, (SessionImpl) history.getSession());
+        obsMgr.dispatch(events, session);
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/RemoveVersionTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/RemoveVersionTest.java?view=diff&r1=161872&r2=161873
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/RemoveVersionTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/RemoveVersionTest.java Tue Apr 19 04:28:27 2005
@@ -21,6 +21,8 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Node;
+import javax.jcr.ReferenceValue;
+import javax.jcr.ReferentialIntegrityException;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
@@ -50,19 +52,13 @@
     protected void setUp() throws Exception {
         super.setUp();
 
-        vHistory = versionableNode.getVersionHistory();
-
-        if (vHistory == null) {
-            fail("VersionHistory must be created on persistent creation of a versionable node.");
-        }
-
         Version testV = versionableNode.checkin(); // create 1.0
         versionableNode.checkout();
         versionableNode.checkin(); // create 1.1
         versionableNode.checkout();
         versionableNode.checkin(); // create 1.2
         try {
-            vHistory.removeVersion(testV.getName());
+            versionableNode.getVersionHistory().removeVersion(testV.getName());
         } catch (UnsupportedRepositoryOperationException e) {
             throw new NotExecutableException("Removing version is not supported: " + e.getMessage());
         }
@@ -73,6 +69,8 @@
         versionableNode.checkout();
         version2 = versionableNode.checkin();
 
+        vHistory = versionableNode.getVersionHistory();
+
         // build a second versionable node below the testroot
         try {
             versionableNode2 = createVersionableNode(testRootNode, nodeName2, versionableNodeType);
@@ -84,7 +82,6 @@
     protected void tearDown() throws Exception {
         try {
             versionableNode2.remove();
-            testRootNode.save();
         } finally {
             super.tearDown();
         }
@@ -169,4 +166,30 @@
             // success
         }
     }
-}
\ No newline at end of file
+
+    /**
+     * Checks if {@link javax.jcr.version.VersionHistory#removeVersion(String)}
+     * throws a {@link javax.jcr.ReferentialIntegrityException} if the named
+     * version is still referenced by another node.
+     * @tck.config nodetype name of a node type that supports a reference
+     *  property.
+     * @tck.config nodename2 name of the node created with <code>nodetype</code>.
+     * @tck.config propertyname1 a single value reference property available
+     *  in <code>nodetype</code>.
+     */
+    public void testReferentialIntegrityException() throws RepositoryException {
+        // create reference: n1.p1 -> versionableNode
+        Node n1 = testRootNode.addNode(nodeName2, testNodeType);
+        n1.setProperty(propertyName1, new ReferenceValue(version));
+        testRootNode.save();
+
+        try {
+            vHistory.removeVersion(version.getName());
+            fail("Method removeVersion() must throw a ReferentialIntegrityException " +
+                 "if the version is the target of a REFERENCE property and the current " +
+                 "Session has read access to that REFERENCE property");
+        }
+        catch (ReferentialIntegrityException e) {
+            // success
+        }
+    }}
\ No newline at end of file