You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2015/11/04 22:17:23 UTC

svn commit: r1712653 - in /sling/trunk/testing/mocks/jcr-mock/src: main/java/org/apache/sling/testing/mock/jcr/MockProperty.java test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java

Author: sseifert
Date: Wed Nov  4 21:17:23 2015
New Revision: 1712653

URL: http://svn.apache.org/viewvc?rev=1712653&view=rev
Log:
SLING-5250 MockProperty getValues does not comply with JCR 2.0 API

Modified:
    sling/trunk/testing/mocks/jcr-mock/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java
    sling/trunk/testing/mocks/jcr-mock/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java

Modified: sling/trunk/testing/mocks/jcr-mock/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/jcr-mock/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java?rev=1712653&r1=1712652&r2=1712653&view=diff
==============================================================================
--- sling/trunk/testing/mocks/jcr-mock/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java (original)
+++ sling/trunk/testing/mocks/jcr-mock/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java Wed Nov  4 21:17:23 2015
@@ -53,7 +53,7 @@ class MockProperty extends AbstractItem
     }
 
     private Value internalGetValue() throws RepositoryException {
-        if (this.itemData.getValues().length > 1) {
+        if (this.itemData.isMultiple()) {
             throw new ValueFormatException(this
                     + " is a multi-valued property, so it's values can only be retrieved as an array");
         } else {
@@ -68,6 +68,9 @@ class MockProperty extends AbstractItem
 
     @Override
     public Value[] getValues() throws RepositoryException {
+        if (!this.itemData.isMultiple()) {
+            throw new ValueFormatException("Property is single-valued.");
+        }
         Value[] valuesCopy = new Value[this.itemData.getValues().length];
         for (int i = 0; i < this.itemData.getValues().length; i++) {
             valuesCopy[i] = this.itemData.getValues()[i];
@@ -213,6 +216,9 @@ class MockProperty extends AbstractItem
 
     @Override
     public long[] getLengths() throws RepositoryException {
+        if (!this.itemData.isMultiple()) {
+            throw new ValueFormatException("Property is single-valued.");
+        }
         long[] lengths = new long[this.itemData.getValues().length];
         for (int i = 0; i < this.itemData.getValues().length; i++) {
             lengths[i] = this.itemData.getValues()[i].getString().length();

Modified: sling/trunk/testing/mocks/jcr-mock/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/jcr-mock/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java?rev=1712653&r1=1712652&r2=1712653&view=diff
==============================================================================
--- sling/trunk/testing/mocks/jcr-mock/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java (original)
+++ sling/trunk/testing/mocks/jcr-mock/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java Wed Nov  4 21:17:23 2015
@@ -34,6 +34,7 @@ import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.value.BinaryValue;
@@ -246,4 +247,12 @@ public class MockPropertyTest {
         assertEquals(PropertyType.UNDEFINED, prop1.getType());
     }
     
+    @Test(expected=ValueFormatException.class)
+    public void testSingleValueAsValueArray() throws RepositoryException {
+        this.node1.setProperty("prop1", this.session.getValueFactory().createValue("value1"));
+        Property prop1 = this.node1.getProperty("prop1");
+        assertFalse(prop1.isMultiple());
+        assertEquals("value1", prop1.getValues()[0].getString());
+    }
+    
 }