jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r523341 - in /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test: AbstractJCRTest.java api/ReferencesTest.java
Date Wed, 28 Mar 2007 14:23:18 GMT
Author: reschke
Date: Wed Mar 28 07:23:17 2007
New Revision: 523341

URL: http://svn.apache.org/viewvc?view=rev&rev=523341
Log:
JCR-817: References tests: fail early with NotExecutableException when the repository doesn't
support reference properties; add convenience method in AbstractJCRTest.java to support value
arrays as well.

Modified:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java?view=diff&rev=523341&r1=523340&r2=523341
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
Wed Mar 28 07:23:17 2007
@@ -541,14 +541,14 @@
      * @throws NotExecutableException when setting the property to the required
      * type is not supported
      */
-    protected void ensureCanSetProperty(Node node, String propertyName, Value val) throws
NotExecutableException, RepositoryException {
+    protected void ensureCanSetProperty(Node node, String propertyName, Value value) throws
NotExecutableException, RepositoryException {
         
-        boolean canSetIt = node.getPrimaryNodeType().canSetProperty(propertyName, val);
+        boolean canSetIt = node.getPrimaryNodeType().canSetProperty(propertyName, value);
         if (! canSetIt) {
             // check mixins
             NodeType mixins[] = node.getMixinNodeTypes();
             for (int i = 0; i < mixins.length && !canSetIt; i++) {
-                canSetIt |= mixins[i].canSetProperty(propertyName, val);
+                canSetIt |= mixins[i].canSetProperty(propertyName, value);
             }
         }
       
@@ -557,6 +557,27 @@
         }
     }
     
+    /**
+     * Checks that the repository can set the property to the required type, otherwise aborts
with
+     * {@link NotExecutableException}.
+     * @throws NotExecutableException when setting the property to the required
+     * type is not supported
+     */
+    protected void ensureCanSetProperty(Node node, String propertyName, Value[] values) throws
NotExecutableException, RepositoryException {
+      
+        boolean canSetIt = node.getPrimaryNodeType().canSetProperty(propertyName, values);
+        if (! canSetIt) {
+            // check mixins
+            NodeType mixins[] = node.getMixinNodeTypes();
+            for (int i = 0; i < mixins.length && !canSetIt; i++) {
+                canSetIt |= mixins[i].canSetProperty(propertyName, values);
+            }
+        }
+      
+        if (! canSetIt) {
+            throw new NotExecutableException("configured property name " + propertyName +
" can not be set on node " + node.getPath());
+        }
+    }
 
     /**
      * Reverts any pending changes made by <code>s</code> and deletes any nodes

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java?view=diff&rev=523341&r1=523340&r2=523341
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java
Wed Mar 28 07:23:17 2007
@@ -17,8 +17,10 @@
 package org.apache.jackrabbit.test.api;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
 
 import javax.jcr.*;
+import javax.jcr.nodetype.ConstraintViolationException;
 
 /**
  * <code>ReferencesTest</code> contains the test cases for the references.
@@ -33,15 +35,31 @@
     /**
      * Tests Node.getReferences()
      */
-    public void testReferences() throws RepositoryException {
+    public void testReferences() throws RepositoryException, NotExecutableException {
         Node n1 = testRootNode.addNode(nodeName1, testNodeType);
-        n1.addMixin(mixReferenceable);
+        try {
+            n1.addMixin(mixReferenceable);
+        }
+        catch (ConstraintViolationException ex) {
+            // may already be present in the node type
+        }
+
         // with some impls. the mixin type has only affect upon save
         testRootNode.save();
 
+        // make sure the node is now referenceable
+        assertTrue("test node should be mix:referenceable", n1.isNodeType(mixReferenceable));
+        
         // create references: n2.p1 -> n1
         Node n2 = testRootNode.addNode(nodeName2, testNodeType);
-        Property p1 = n2.setProperty(propertyName1, new Value[]{superuser.getValueFactory().createValue(n1)});
+        
+        Value[] values = new Value[]{superuser.getValueFactory().createValue(n1)};
+        
+        // abort test if the repository does not allow setting
+        // reference properties on this node
+        ensureCanSetProperty(n2, propertyName1, values);
+        
+        Property p1 = n2.setProperty(propertyName1, values);
         testRootNode.save();
         PropertyIterator iter = n1.getReferences();
         if (iter.hasNext()) {
@@ -97,14 +115,28 @@
     /**
      * Tests Property.getNode();
      */
-    public void testReferenceTarget() throws RepositoryException {
+    public void testReferenceTarget() throws RepositoryException, NotExecutableException
{
         Node n1 = testRootNode.addNode(nodeName1, testNodeType);
-        n1.addMixin(mixReferenceable);
+        try {
+            n1.addMixin(mixReferenceable);
+        }
+        catch (ConstraintViolationException ex) {
+            // may already be present in the node type
+        }
+        
         // with some impls. the mixin type has only affect upon save
         testRootNode.save();
 
+        // make sure the node is now referenceable
+        assertTrue("test node should be mix:referenceable", n1.isNodeType(mixReferenceable));
+
         // create references: n2.p1 -> n1
         Node n2 = testRootNode.addNode(nodeName2, testNodeType);
+
+        // abort test if the repository does not allow setting
+        // reference properties on this node
+        ensureCanSetProperty(n2, propertyName1, n2.getSession().getValueFactory().createValue(n1));
+
         n2.setProperty(propertyName1, n1);
         testRootNode.save();
         assertEquals("Wrong reference target.", n2.getProperty(propertyName1).getNode(),
n1);
@@ -115,16 +147,32 @@
     /**
      * Tests changing a reference property
      */
-    public void testAlterReference() throws RepositoryException {
+    public void testAlterReference() throws RepositoryException, NotExecutableException {
         Node n1 = testRootNode.addNode(nodeName1, testNodeType);
-        n1.addMixin(mixReferenceable);
         Node n2 = testRootNode.addNode(nodeName2, testNodeType);
-        n2.addMixin(mixReferenceable);
+
+        try {
+            n1.addMixin(mixReferenceable);
+            n2.addMixin(mixReferenceable);
+        }
+        catch (ConstraintViolationException ex) {
+            // may already be present in the node type
+        }
+
         // with some impls. the mixin type has only affect upon save
         testRootNode.save();
 
+        // make sure the nodes are now referenceable
+        assertTrue("test node should be mix:referenceable", n1.isNodeType(mixReferenceable));
+        assertTrue("test node should be mix:referenceable", n2.isNodeType(mixReferenceable));
+
         // create references: n3.p1 -> n1
         Node n3 = testRootNode.addNode(nodeName3, testNodeType);
+
+        // abort test if the repository does not allow setting
+        // reference properties on this node
+        ensureCanSetProperty(n3, propertyName1, n3.getSession().getValueFactory().createValue(n1));
+
         n3.setProperty(propertyName1, n1);
         testRootNode.save();
         assertEquals("Wrong reference target.", n3.getProperty(propertyName1).getNode(),
n1);



Mime
View raw message