[dna-commits] DNA SVN: r828 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directory.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Wed Apr 15 10:28:30 EDT 2009


Author: rhauch
Date: 2009-04-15 10:28:30 -0400 (Wed, 15 Apr 2009)
New Revision: 828

Modified:
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
Log:
DNA-355 Wrong Exception Thrown When Creating Reference Value from Non-Referenceable Node

Applied the patch, which corrects JcrSession.getValueFactories.createValue(Node) witto throw a RepositoryException (rather than an UnsupportedRepositoryOperationException) when a non-referenceable node is given as an argument, and which modifies some unit tests as needed.

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java	2009-04-15 14:14:33 UTC (rev 827)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java	2009-04-15 14:28:30 UTC (rev 828)
@@ -462,6 +462,9 @@
             }
 
             public Value createValue( Node value ) throws RepositoryException {
+                if (!value.isNodeType(JcrMixLexicon.REFERENCEABLE.getString(JcrSession.this.namespaces()))) {
+                    throw new RepositoryException();
+                }
                 String uuid = valueFactories.getStringFactory().create(value.getUUID());
                 return new JcrValue(valueFactories, sessionCache, PropertyType.REFERENCE, uuid);
             }

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java	2009-04-15 14:14:33 UTC (rev 827)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java	2009-04-15 14:28:30 UTC (rev 828)
@@ -336,11 +336,20 @@
         assertThat(factory.createValue(0L), notNullValue());
         Node node = Mockito.mock(Node.class);
         stub(node.getUUID()).toReturn(UUID.randomUUID().toString());
+        stub(node.isNodeType("mix:referenceable")).toReturn(true);
         assertThat(factory.createValue(node), notNullValue());
         assertThat(factory.createValue(""), notNullValue());
         assertThat(factory.createValue("", PropertyType.BINARY), notNullValue());
     }
 
+    @Test (expected=RepositoryException.class)
+    public void shouldNotCreateValueForNonReferenceableNode() throws Exception {
+        ValueFactory factory = session.getValueFactory();
+        Node node = Mockito.mock(Node.class);
+        stub(node.getUUID()).toReturn(UUID.randomUUID().toString());
+        factory.createValue(node);
+    }
+
     @Test
     public void shouldNotHavePendingChanges() throws Exception {
         assertThat(session.hasPendingChanges(), is(false));




More information about the dna-commits mailing list