You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:18:28 UTC
[sling-org-apache-sling-testing-jcr-mock] 04/07: SLING-5250
MockProperty getValues does not comply with JCR 2.0 API
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.testing.jcr-mock-1.1.12
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-jcr-mock.git
commit 2c7832b166c8d597e7b400e6bf9ab5854f503eff
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Wed Nov 4 21:17:23 2015 +0000
SLING-5250 MockProperty getValues does not comply with JCR 2.0 API
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/jcr-mock@1712653 13f79535-47bb-0310-9956-ffa450edef68
---
.../java/org/apache/sling/testing/mock/jcr/MockProperty.java | 8 +++++++-
.../java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java | 9 +++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java b/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java
index 3eaa9ce..3e10fda 100644
--- a/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java
+++ b/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java
@@ -53,7 +53,7 @@ class MockProperty extends AbstractItem implements Property {
}
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 implements Property {
@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 implements Property {
@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();
diff --git a/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java b/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java
index 14d59af..81eee32 100644
--- a/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java
@@ -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());
+ }
+
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.