[dna-commits] DNA SVN: r524 - 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 Sep 17 11:20:24 EDT 2008


Author: jverhaeg at redhat.com
Date: 2008-09-17 11:20:24 -0400 (Wed, 17 Sep 2008)
New Revision: 524

Added:
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java
Modified:
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
Log:
DNA-178: Determined we also need a minimal implementation of PropertyDefintion to determine whether a property has multiple values.

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java	2008-09-17 15:08:00 UTC (rev 523)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java	2008-09-17 15:20:24 UTC (rev 524)
@@ -34,7 +34,6 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
-import javax.jcr.nodetype.PropertyDefinition;
 import net.jcip.annotations.NotThreadSafe;
 import org.jboss.dna.common.util.ArgCheck;
 import org.jboss.dna.spi.ExecutionContext;
@@ -100,16 +99,6 @@
     /**
      * {@inheritDoc}
      * 
-     * @throws UnsupportedOperationException always
-     * @see javax.jcr.Property#getDefinition()
-     */
-    public PropertyDefinition getDefinition() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * {@inheritDoc}
-     * 
      * @see javax.jcr.Item#getDepth()
      */
     public int getDepth() throws RepositoryException {

Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java	                        (rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java	2008-09-17 15:20:24 UTC (rev 524)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
+
+/**
+ * @author jverhaeg
+ */
+abstract class AbstractJcrPropertyDefinition implements PropertyDefinition {
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @throws UnsupportedOperationException always
+     * @see javax.jcr.nodetype.PropertyDefinition#getDefaultValues()
+     */
+    public final Value[] getDefaultValues() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @throws UnsupportedOperationException always
+     * @see javax.jcr.nodetype.PropertyDefinition#getRequiredType()
+     */
+    public final int getRequiredType() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @throws UnsupportedOperationException always
+     * @see javax.jcr.nodetype.PropertyDefinition#getValueConstraints()
+     */
+    public final String[] getValueConstraints() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @throws UnsupportedOperationException always
+     * @see javax.jcr.nodetype.ItemDefinition#getDeclaringNodeType()
+     */
+    public final NodeType getDeclaringNodeType() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @throws UnsupportedOperationException always
+     * @see javax.jcr.nodetype.ItemDefinition#getName()
+     */
+    public final String getName() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @throws UnsupportedOperationException always
+     * @see javax.jcr.nodetype.ItemDefinition#getOnParentVersion()
+     */
+    public final int getOnParentVersion() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @throws UnsupportedOperationException always
+     * @see javax.jcr.nodetype.ItemDefinition#isAutoCreated()
+     */
+    public final boolean isAutoCreated() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @throws UnsupportedOperationException always
+     * @see javax.jcr.nodetype.ItemDefinition#isMandatory()
+     */
+    public final boolean isMandatory() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @throws UnsupportedOperationException always
+     * @see javax.jcr.nodetype.ItemDefinition#isProtected()
+     */
+    public final boolean isProtected() {
+        throw new UnsupportedOperationException();
+    }
+}


Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrPropertyDefinition.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java	2008-09-17 15:08:00 UTC (rev 523)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java	2008-09-17 15:20:24 UTC (rev 524)
@@ -30,6 +30,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
 import net.jcip.annotations.NotThreadSafe;
 import org.jboss.dna.spi.ExecutionContext;
 import org.jboss.dna.spi.graph.Name;
@@ -82,6 +83,20 @@
     /**
      * {@inheritDoc}
      * 
+     * @see javax.jcr.Property#getDefinition()
+     */
+    public PropertyDefinition getDefinition() {
+        return new AbstractJcrPropertyDefinition() {
+
+            public boolean isMultiple() {
+                return true;
+            }
+        };
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
      * @throws ValueFormatException always
      * @see javax.jcr.Property#getDouble()
      */

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java	2008-09-17 15:08:00 UTC (rev 523)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java	2008-09-17 15:20:24 UTC (rev 524)
@@ -27,6 +27,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
 import org.jboss.dna.spi.ExecutionContext;
 import org.jboss.dna.spi.graph.Name;
 import org.jboss.dna.spi.graph.ValueFactories;
@@ -69,6 +70,20 @@
     /**
      * {@inheritDoc}
      * 
+     * @see javax.jcr.Property#getDefinition()
+     */
+    public PropertyDefinition getDefinition() {
+        return new AbstractJcrPropertyDefinition() {
+
+            public boolean isMultiple() {
+                return false;
+            }
+        };
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
      * @see javax.jcr.Property#getDouble()
      */
     public double getDouble() throws RepositoryException {

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java	2008-09-17 15:08:00 UTC (rev 523)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java	2008-09-17 15:20:24 UTC (rev 524)
@@ -33,6 +33,7 @@
 import javax.jcr.Property;
 import javax.jcr.Session;
 import javax.jcr.Value;
+import javax.jcr.nodetype.PropertyDefinition;
 import org.jboss.dna.common.util.StringUtil;
 import org.jboss.dna.spi.ExecutionContext;
 import org.jboss.dna.spi.graph.Name;
@@ -270,6 +271,15 @@
         /**
          * {@inheritDoc}
          * 
+         * @see javax.jcr.Property#getDefinition()
+         */
+        public PropertyDefinition getDefinition() {
+            return null;
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
          * @see javax.jcr.Property#getDouble()
          */
         public double getDouble() {

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java	2008-09-17 15:08:00 UTC (rev 523)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java	2008-09-17 15:20:24 UTC (rev 524)
@@ -34,6 +34,7 @@
 import javax.jcr.PropertyType;
 import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
 import org.jboss.dna.spi.ExecutionContext;
 import org.jboss.dna.spi.connector.BasicExecutionContext;
 import org.jboss.dna.spi.graph.Name;
@@ -49,6 +50,7 @@
  */
 public class JcrMultiValuePropertyTest {
 
+    private Property prop;
     @Mock
     private Node node;
     private ExecutionContext executionContext = new BasicExecutionContext();
@@ -58,6 +60,7 @@
     @Before
     public void before() {
         MockitoAnnotations.initMocks(this);
+        prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(true));
     }
 
     @Test( expected = AssertionError.class )
@@ -67,10 +70,9 @@
 
     @Test
     public void shouldProvideAppropriateType() throws Exception {
-        Property prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(true));
         assertThat(prop.getType(), is(PropertyType.BOOLEAN));
         Calendar cal = Calendar.getInstance();
-        prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(cal));
+        Property prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(cal));
         assertThat(prop.getType(), is(PropertyType.DATE));
         prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(cal.getTime()));
         assertThat(prop.getType(), is(PropertyType.DATE));
@@ -102,7 +104,7 @@
 
     @Test( expected = ValueFormatException.class )
     public void shouldNotProvideBoolean() throws Exception {
-        new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(true)).getBoolean();
+        prop.getBoolean();
     }
 
     @Test( expected = ValueFormatException.class )
@@ -115,6 +117,63 @@
         new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(Calendar.getInstance().getTime())).getDate();
     }
 
+    @Test
+    public void shouldProvidePropertyDefinition() throws Exception {
+        assertThat(prop.getDefinition(), notNullValue());
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionDeclaringNodeType() throws Exception {
+        prop.getDefinition().getDeclaringNodeType();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionDefaultValues() throws Exception {
+        prop.getDefinition().getDefaultValues();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionName() throws Exception {
+        prop.getDefinition().getName();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionGetOnParentVersion() throws Exception {
+        prop.getDefinition().getOnParentVersion();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionGetRequiredType() throws Exception {
+        prop.getDefinition().getRequiredType();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionGetValueConstraints() throws Exception {
+        prop.getDefinition().getValueConstraints();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionIsAutoCreated() throws Exception {
+        prop.getDefinition().isAutoCreated();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionIsMandatory() throws Exception {
+        prop.getDefinition().isMandatory();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionIsProtected() throws Exception {
+        prop.getDefinition().isProtected();
+    }
+
+    @Test
+    public void shouldIndicateHasMultipleValues() throws Exception {
+        PropertyDefinition def = prop.getDefinition();
+        assertThat(def, notNullValue());
+        assertThat(def.isMultiple(), is(true));
+    }
+
     @Test( expected = ValueFormatException.class )
     public void shouldNotProvideDoubleForDouble() throws Exception {
         new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(1.0)).getDouble();
@@ -147,12 +206,11 @@
 
     @Test( expected = ValueFormatException.class )
     public void shouldNotProvideValue() throws Exception {
-        new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(true)).getValue();
+        prop.getValue();
     }
 
     @Test
     public void shouldProvideValues() throws Exception {
-        Property prop = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(true));
         Value[] vals = prop.getValues();
         assertThat(vals, notNullValue());
         assertThat(vals.length, is(1));
@@ -161,14 +219,18 @@
 
     @Test( expected = ValueFormatException.class )
     public void shouldNotProvideLength() throws Exception {
-        new JcrMultiValueProperty(node, executionContext, name, Arrays.asList("value")).getLength();
+        prop.getLength();
     }
 
     @Test
     public void shouldProvideLengths() throws Exception {
-        long[] lengths = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList("value")).getLengths();
+        long[] lengths = prop.getLengths();
         assertThat(lengths, notNullValue());
         assertThat(lengths.length, is(1));
+        assertThat(lengths[0], is(4L));
+        lengths = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList("value")).getLengths();
+        assertThat(lengths, notNullValue());
+        assertThat(lengths.length, is(1));
         assertThat(lengths[0], is(5L));
         Object obj = new Object();
         lengths = new JcrMultiValueProperty(node, executionContext, name, Arrays.asList(obj)).getLengths();

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java	2008-09-17 15:08:00 UTC (rev 523)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java	2008-09-17 15:20:24 UTC (rev 524)
@@ -33,6 +33,7 @@
 import javax.jcr.PropertyType;
 import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
+import javax.jcr.nodetype.PropertyDefinition;
 import org.jboss.dna.spi.ExecutionContext;
 import org.jboss.dna.spi.connector.BasicExecutionContext;
 import org.jboss.dna.spi.graph.Name;
@@ -48,6 +49,7 @@
  */
 public class JcrPropertyTest {
 
+    private Property prop;
     @Mock
     private Node node;
     private ExecutionContext executionContext = new BasicExecutionContext();
@@ -57,6 +59,7 @@
     @Before
     public void before() {
         MockitoAnnotations.initMocks(this);
+        prop = new JcrProperty(node, executionContext, name, true);
     }
 
     @Test( expected = AssertionError.class )
@@ -66,7 +69,6 @@
 
     @Test
     public void shouldProvideBoolean() throws Exception {
-        Property prop = new JcrProperty(node, executionContext, name, true);
         assertThat(prop.getBoolean(), is(true));
         assertThat(prop.getType(), is(PropertyType.BOOLEAN));
     }
@@ -83,6 +85,63 @@
     }
 
     @Test
+    public void shouldProvidePropertyDefinition() throws Exception {
+        assertThat(prop.getDefinition(), notNullValue());
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionDeclaringNodeType() throws Exception {
+        prop.getDefinition().getDeclaringNodeType();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionDefaultValues() throws Exception {
+        prop.getDefinition().getDefaultValues();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionName() throws Exception {
+        prop.getDefinition().getName();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionGetOnParentVersion() throws Exception {
+        prop.getDefinition().getOnParentVersion();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionGetRequiredType() throws Exception {
+        prop.getDefinition().getRequiredType();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionGetValueConstraints() throws Exception {
+        prop.getDefinition().getValueConstraints();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionIsAutoCreated() throws Exception {
+        prop.getDefinition().isAutoCreated();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionIsMandatory() throws Exception {
+        prop.getDefinition().isMandatory();
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotAllowPropertyDefinitionIsProtected() throws Exception {
+        prop.getDefinition().isProtected();
+    }
+
+    @Test
+    public void shouldIndicateHasSingleValue() throws Exception {
+        PropertyDefinition def = prop.getDefinition();
+        assertThat(def, notNullValue());
+        assertThat(def.isMultiple(), is(false));
+    }
+
+    @Test
     public void shouldProvideDouble() throws Exception {
         Property prop = new JcrProperty(node, executionContext, name, 1.0);
         assertThat(prop.getDouble(), is(1.0));
@@ -155,7 +214,6 @@
 
     @Test
     public void shouldProvideValue() throws Exception {
-        Property prop = new JcrProperty(node, executionContext, name, true);
         Value val = prop.getValue();
         assertThat(val, notNullValue());
         assertThat(val.getBoolean(), is(true));
@@ -163,11 +221,12 @@
 
     @Test( expected = ValueFormatException.class )
     public void shouldNotProvideValues() throws Exception {
-        new JcrProperty(node, executionContext, name, true).getValues();
+        prop.getValues();
     }
 
     @Test
     public void shouldProvideLength() throws Exception {
+        assertThat(prop.getLength(), is(4L));
         assertThat(new JcrProperty(node, executionContext, name, "value").getLength(), is(5L));
         Object obj = new Object();
         assertThat(new JcrProperty(node, executionContext, name, obj).getLength(), is((long)obj.toString().length()));
@@ -175,6 +234,6 @@
 
     @Test( expected = ValueFormatException.class )
     public void shouldNotProvideLengths() throws Exception {
-        new JcrProperty(node, executionContext, name, "value").getLengths();
+        prop.getLengths();
     }
 }




More information about the dna-commits mailing list