jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r797836 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/ jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/vers...
Date Sat, 25 Jul 2009 21:07:47 GMT
Author: tripod
Date: Sat Jul 25 21:07:46 2009
New Revision: 797836

URL: http://svn.apache.org/viewvc?rev=797836&view=rev
Log:
JCR-2140: JSR 283: Configurations and Baselines

Added:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/ConfigurationsTest.java
  (contents, props changed)
      - copied, changed from r797657, jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/ActivitiesTest.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplConfig.java
    jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/AbstractVersionTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/TestAll.java
    jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java?rev=797836&r1=797835&r2=797836&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersionManagerBase.java
Sat Jul 25 21:07:46 2009
@@ -99,11 +99,14 @@
      */
     public InternalBaseline getBaseline(NodeId id) throws RepositoryException {
         // lock handling via getItem()
-        InternalBaseline v = (InternalBaseline) getItem(id);
-        if (v == null) {
+        InternalVersionItem item = getItem(id);
+        if (item == null) {
             log.warn("Versioning item not found: " + id);
+        } else if (!(item instanceof InternalBaseline)) {
+            log.warn("Versioning item is not a baseline: " + id);
+            item = null;
         }
-        return v;
+        return (InternalBaseline) item;
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplConfig.java?rev=797836&r1=797835&r2=797836&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplConfig.java
Sat Jul 25 21:07:46 2009
@@ -102,13 +102,12 @@
         // create new node below parent
         WriteOperation ops = startWriteOperation();
         try {
-            // check if nt:configuration node exists
-            NodeStateEx config = null;
-            if (stateMgr.hasItemState(configId)) {
-                config = parent.getNode(configId);
-            } else {
+            if (!stateMgr.hasItemState(configId)) {
+                // create if nt:configuration node is not exists
                 internalCreateConfiguration(rootId, configId, baseline.getId());
             }
+            NodeStateEx config = parent.getNode(configId);
+
             // create the root node so that the restore works
             InternalFrozenNode fn = rootVersion.getFrozenNode();
             NodeStateEx state = parent.addNode(name, fn.getFrozenPrimaryType(), fn.getFrozenId());

Modified: jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd?rev=797836&r1=797835&r2=797836&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd
Sat Jul 25 21:07:46 2009
@@ -512,9 +512,15 @@
   + * (nt:activity) = nt:activity protected sns ABORT
   + * (rep:Activities) = rep:Activities protected sns ABORT
 
+/**
+ * the intermediate nodes for the configurations storage.
+ * Note: since the versionable node points to the configuration and vice versa,
+ * a configuration could never be removed because no such API exists. therefore
+ * the child node definitions are not protected.
+ */
 [rep:Configurations]
-  + * (nt:configuration) = nt:configuration protected sns ABORT
-  + * (rep:Configurations) = rep:Configurations protected sns ABORT
+  + * (nt:configuration) = nt:configuration sns ABORT
+  + * (rep:Configurations) = rep:Configurations sns ABORT
 
 /**
  * mixin that provides a multi value property for referencing versions.

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/AbstractVersionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/AbstractVersionTest.java?rev=797836&r1=797835&r2=797836&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/AbstractVersionTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/AbstractVersionTest.java
Sat Jul 25 21:07:46 2009
@@ -98,7 +98,9 @@
     protected void tearDown() throws Exception {
         // remove versionable nodes
         try {
-            versionableNode.remove();
+            if (versionableNode != null) {
+                versionableNode.remove();
+            }
             testRootNode.getSession().save();
         } catch (Exception e) {
             log.println("Exception in tearDown: " + e.toString());

Copied: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/ConfigurationsTest.java
(from r797657, jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/ActivitiesTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/ConfigurationsTest.java?p2=jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/ConfigurationsTest.java&p1=jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/ActivitiesTest.java&r1=797657&r2=797836&rev=797836&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/ActivitiesTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/ConfigurationsTest.java
Sat Jul 25 21:07:46 2009
@@ -17,136 +17,254 @@
 package org.apache.jackrabbit.test.api.version;
 
 import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyType;
 import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.nodetype.NodeType;
+import javax.jcr.version.Version;
 import javax.jcr.version.VersionManager;
 
 
 /**
- * <code>ActivitiesTest</code> covers methods related to the Activities
+ * <code>ConfigurationsTest</code> covers methods related to the Configurations
  * feature in Versioning.
  * @test
- * @sources ActivitiesTest.java
- * @executeClass org.apache.jackrabbit.test.api.version.ActivitiesTest
+ * @sources ConfigurationsTest.java
+ * @executeClass org.apache.jackrabbit.test.api.version.ConfigurationsTest
  * @keywords versioning
  * @since JCR 2.0
  */
-public class ActivitiesTest extends AbstractVersionTest {
+public class ConfigurationsTest extends AbstractVersionTest {
 
     private VersionManager vm;
 
-    private static String PREFIX = "/jcr:system/jcr:activities/";
-    
+    private static String PREFIX = "/jcr:system/jcr:configurations/";
+
+    private String ntConfiguration;
+
+    private Node versionableNode2;
+
     protected void setUp() throws Exception {
         super.setUp();
-        checkSupportedOption(Repository.OPTION_ACTIVITIES_SUPPORTED);
+        checkSupportedOption(Repository.OPTION_BASELINES_SUPPORTED);
         vm = superuser.getWorkspace().getVersionManager();
+
+        versionableNode2 = createVersionableNode(testRootNode, nodeName4, versionableNodeType);
+
+        ntConfiguration = superuser.getNamespacePrefix(NS_NT_URI) + ":configuration";
+
     }
 
     protected void tearDown() throws Exception {
+        // remove configuration, otherwise
+        // subsequent tests will fail when cleaning the test root
+        if (versionableNode != null) {
+            removeConfiguration(versionableNode);
+        }
+        removeConfiguration(versionableNode2);
+        versionableNode2.remove();
+        // save is called in super.tearDown()
         super.tearDown();
     }
 
-    public void testCreateRemoveActivity() throws Exception {
-        
-        Node an = null;
-        
-        try {
-            an = vm.createActivity("foobar");
-            assertNotNull(an);
-            
-            NodeType annt = an.getPrimaryNodeType();
-            assertTrue("create node must be subtype of nt:activity", annt.isNodeType("nt:activity"));
-        }
-        finally {
-            if (an != null) {
-                vm.removeActivity(an);
-            }
-        }
-    }
-
-    public void testSetGetActivity() throws Exception {
-        
-        Node an = null;
-        
-        try {
-            an = vm.createActivity("foobar");
-            assertNotNull(an);
-            
-            assertNull(vm.getActivity());
-            
-            Node old = vm.setActivity(an);
-            assertNull(old);
-            assertEquals(an.getPath(), vm.getActivity().getPath());
-            
-            old = vm.setActivity(null);
-            assertEquals(old.getPath(), an.getPath());
-            assertNull(vm.getActivity());
-        }
-        finally {
-            if (an != null) {
-                vm.removeActivity(an);
-            }
-        }
-    }
-
-    public void testActivitiesPath() throws Exception {
-        
-        Node an = null;
-        
-        try {
-            an = vm.createActivity("foobar");
-            assertNotNull(an);
-            
-            NodeType annt = an.getPrimaryNodeType();
-            assertTrue("create node must be subtype of nt:activity", annt.isNodeType("nt:activity"));
-
-            assertTrue("path for activity must be below " + PREFIX + ", but was " + an.getPath(),
an.getPath().startsWith(PREFIX));
-
-            Node activities = superuser.getNode(PREFIX);
-            
-            assertFalse(activities.getPrimaryNodeType().canAddChildNode("foobar"));
-        }
-        finally {
-            if (an != null) {
-                vm.removeActivity(an);
-            }
-        }
-    }
-    
-    public void testActivitiesRelation() throws Exception {
-        
-        Node an = null;
-        
-        try {
-            an = vm.createActivity("foobar");
-            vm.setActivity(an);
-            
-            String path = versionableNode.getPath();
-            
-            if (versionableNode.isCheckedOut()) {
-                vm.checkin(path);
-            }
-            
-            vm.checkout(path);
-            
-            versionableNode = superuser.getNode(path);
-            Property act = versionableNode.getProperty(Property.JCR_ACTIVITY);
-            assertNotNull(act);
-            assertEquals(PropertyType.REFERENCE, act.getType());
-            assertTrue(act.getNode().isSame(an));
-            
-            versionableNode.remove();
-            versionableNode.getSession().save();
-        }
-        finally {
-            if (an != null) {
-                vm.removeActivity(an);
-            }
+    private void removeConfiguration(Node node) throws RepositoryException {
+        if (node.hasProperty("jcr:configuration")) {
+            node.getProperty("jcr:configuration").getNode().remove();
         }
     }
-    
-}
 
+    public void testCreateConfiguration() throws Exception {
+        Node config = vm.createConfiguration(versionableNode.getPath(), null);
+        assertNotNull(config);
+        NodeType nt = config.getPrimaryNodeType();
+        assertTrue("created node must be subtype of nt:configuration", nt.isNodeType(ntConfiguration));
+
+        // check if the configuration points to the versionable
+        assertTrue("jcr:root property of the configuration must reference the versionable
node",
+                config.getProperty("jcr:root").getNode().isSame(versionableNode));
+
+        // check if the versionable points to the configuration
+        assertTrue("jcr:configuration property of the versionable node must reference the
configuration",
+                versionableNode.getProperty("jcr:configuration").getNode().isSame(config));
+
+    }
+
+    public void testCreateConfigurationNotVersionableFails() throws Exception {
+        try {
+            vm.createConfiguration(nonVersionableNode.getPath(), null);
+            fail("Create configuration must fail for non-versionable node");
+        } catch (UnsupportedRepositoryOperationException e) {
+            // ignore
+        }
+    }
+
+    public void testCreateConfigurationTwiceFails() throws Exception {
+        vm.createConfiguration(versionableNode.getPath(), null);
+        try {
+            vm.createConfiguration(versionableNode.getPath(), null);
+            fail("Create configuration must fail if versionable is already a configuration");
+        } catch (UnsupportedRepositoryOperationException e) {
+            // ignore
+        }
+    }
+
+    public void testConfigurationsPath() throws Exception {
+        Node config = vm.createConfiguration(versionableNode.getPath(), null);
+        assertNotNull(config);
+        NodeType nt = config.getPrimaryNodeType();
+        assertTrue("created node must be subtype of nt:configuration", nt.isNodeType(ntConfiguration));
+
+        assertTrue("path for configuration must be below " + PREFIX + ", but was " +
+                config.getPath(), config.getPath().startsWith(PREFIX));
+    }
+
+    public void testCreateConfigExistingPathWithBaselineFails() throws Exception {
+        Node config = vm.createConfiguration(versionableNode.getPath(), null);
+        Version baseline = vm.getBaseVersion(config.getPath());
+        try {
+            vm.createConfiguration(versionableNode2.getPath(), baseline);
+            fail("Create configuration must fail if baseline is specified and path exists");
+        } catch (UnsupportedRepositoryOperationException e) {
+            // ignore
+        }
+    }
+
+    public void testCreateConfigWithNoBaselineVersionFails() throws Exception {
+        try {
+            Version noBaseline = vm.getBaseVersion(versionableNode.getPath());
+            vm.createConfiguration(testRoot + "/nonExistingNode", noBaseline);
+            fail("Create configuration must fail if baseline is not a baseline");
+        } catch (UnsupportedRepositoryOperationException e) {
+            // ignore
+        }
+    }
+
+    public void testCheckinConfigFailsWithUnversionedChild() throws Exception {
+        Node config = vm.createConfiguration(versionableNode.getPath(), null);
+        try {
+            vm.checkin(config.getPath());
+            fail("Checkin configuration must fail one of the recorded versions is not versioned.");
+        } catch (UnsupportedRepositoryOperationException e) {
+            // ignore
+        }
+    }
+
+    public void testCheckinConfig() throws Exception {
+        vm.checkin(versionableNode.getPath());
+        Node config = vm.createConfiguration(versionableNode.getPath(), null);
+        vm.checkin(config.getPath());
+    }
+
+    public void testCreateConfigWithBaseline() throws Exception {
+        // create configuration
+        String path = versionableNode.getPath();
+        Version baseVersion = vm.checkin(path);
+        Node config = vm.createConfiguration(path, null);
+        // record baseline
+        Version baseline = vm.checkin(config.getPath());
+
+        // remove workspace nodes
+        removeConfiguration(versionableNode);
+        versionableNode.remove();
+        versionableNode = null;
+        testRootNode.getSession().save();
+
+        // and try to restore it
+        config = vm.createConfiguration(path, baseline);
+
+        // base version of config must be baseline
+        assertTrue("Baseversion of restored config must be given baseline.",
+                vm.getBaseVersion(config.getPath()).isSame(baseline));
+
+        versionableNode = testRootNode.getSession().getNode(path);
+        Version baseVersion2 = vm.getBaseVersion(versionableNode.getPath());
+
+        assertTrue("restored node must have former base version.", baseVersion.isSame(baseVersion2));
+    }
+
+    public void testCreateConfigWithNonExistentParentFails() throws Exception {
+        // create configuration
+        String path = versionableNode.getPath();
+        vm.checkin(path);
+        Node config = vm.createConfiguration(path, null);
+        // record baseline
+        Version baseline = vm.checkin(config.getPath());
+
+        // remove workspace nodes
+        removeConfiguration(versionableNode);
+        versionableNode.remove();
+        versionableNode = null;
+        testRootNode.getSession().save();
+
+        try {
+            vm.createConfiguration("/non/existent/parent", baseline);
+            fail("Create configuration must fail if parent does not exist.");
+        } catch (RepositoryException e) {
+            // ignore
+        }
+    }
+
+    public void testCreateConfigWithExistentConfigFromBaselineFails() throws Exception {
+        // create configuration
+        String path = versionableNode.getPath();
+        vm.checkin(path);
+        Node config = vm.createConfiguration(path, null);
+        // record baseline
+        Version baseline = vm.checkin(config.getPath());
+
+        try {
+            vm.createConfiguration(testRoot + "/nonExisting", baseline);
+            fail("Create configuration must fail if config recorded in baseline already exists.");
+        } catch (RepositoryException e) {
+            // ignore
+        }
+    }
+
+    public void testRestoreBaseline() throws Exception {
+        // create configuration
+        String path = versionableNode.getPath();
+        Version bv1 = vm.checkpoint(path);
+        Node config = vm.createConfiguration(path, null);
+        // record baseline 1 (should contain bv1)
+        Version bl1 = vm.checkpoint(config.getPath());
+        // create bv2
+        Version bv2 = vm.checkpoint(path);
+        // record baseline 2 (should contain bv2)
+        Version bl2 = vm.checkpoint(config.getPath());
+
+        // restore bl1
+        vm.restore(bl1, true);
+        Version bv = vm.getBaseVersion(path);
+        assertTrue("restored node must have former base version V1.0.", bv.isSame(bv1));
+
+        // restore bl2
+        vm.restore(bl2, true);
+        bv = vm.getBaseVersion(path);
+        assertTrue("restored node must have former base version V1.1.", bv.isSame(bv2));
+    }
+
+    public void testRestoreConfig() throws Exception {
+        // create configuration
+        String path = versionableNode.getPath();
+        Version bv1 = vm.checkpoint(path);
+        Node config = vm.createConfiguration(path, null);
+        String configPath = config.getPath();
+
+        // record baseline 1 (should contain bv1)
+        Version bl1 = vm.checkpoint(config.getPath());
+        // create bv2
+        Version bv2 = vm.checkpoint(path);
+        // record baseline 2 (should contain bv2)
+        Version bl2 = vm.checkpoint(config.getPath());
+
+        // restore bl1
+        vm.restore(configPath, bl1.getName(), true);
+        Version bv = vm.getBaseVersion(path);
+        assertTrue("restored node must have former base version V1.0.", bv.isSame(bv1));
+
+        // restore bl2
+        vm.restore(configPath, bl2.getName(), true);
+        bv = vm.getBaseVersion(path);
+        assertTrue("restored node must have former base version V1.1.", bv.isSame(bv2));
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/ConfigurationsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/TestAll.java?rev=797836&r1=797835&r2=797836&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/TestAll.java
Sat Jul 25 21:07:46 2009
@@ -70,6 +70,7 @@
         // JCR 2.0
 
         suite.addTestSuite(ActivitiesTest.class);
+        suite.addTestSuite(ConfigurationsTest.class);
 
         return suite;
     }

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml?rev=797836&r1=797835&r2=797836&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml Sat Jul 25 21:07:46 2009
@@ -72,6 +72,7 @@
                 org.apache.jackrabbit.test.api.ShareableNodeTest
                 org.apache.jackrabbit.test.api.version.simple
                 org.apache.jackrabbit.test.api.version.ActivitiesTest
+                org.apache.jackrabbit.test.api.version.ConfigurationsTest
                 org.apache.jackrabbit.test.api.LifecycleTest
               </value>
             </property>



Mime
View raw message