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:25:09 UTC
[sling-org-apache-sling-testing-sling-mock] 02/14: update unit
tests to test BigDecimal conversion (related to SLING-6416)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.testing.sling-mock-1.9.6
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 4ba9db5c0abe250ef1e8b19ab208176ac0e95a21
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Mon Dec 19 11:52:49 2016 +0000
update unit tests to test BigDecimal conversion (related to SLING-6416)
git-svn-id: https://svn.apache.org/repos/asf/sling/branches/testing/mocks/sling-mock-1.x@1775067 13f79535-47bb-0310-9956-ffa450edef68
---
.../AbstractSlingCrudResourceResolverTest.java | 40 ++++++++++++++++++----
1 file changed, 34 insertions(+), 6 deletions(-)
diff --git a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
index e9f4dbd..f548eb2 100644
--- a/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
@@ -63,7 +64,9 @@ public abstract class AbstractSlingCrudResourceResolverTest {
private static final String STRING_VALUE = "value1";
private static final String[] STRING_ARRAY_VALUE = new String[] { "value1", "value2" };
private static final int INTEGER_VALUE = 25;
+ private static final long LONG_VALUE = 250L;
private static final double DOUBLE_VALUE = 3.555d;
+ private static final BigDecimal BIGDECIMAL_VALUE = new BigDecimal("12345.678");
private static final boolean BOOLEAN_VALUE = true;
private static final Date DATE_VALUE = new Date(10000);
private static final Calendar CALENDAR_VALUE = Calendar.getInstance();
@@ -83,7 +86,9 @@ public abstract class AbstractSlingCrudResourceResolverTest {
props.put("stringProp", STRING_VALUE);
props.put("stringArrayProp", STRING_ARRAY_VALUE);
props.put("integerProp", INTEGER_VALUE);
+ props.put("longProp", LONG_VALUE);
props.put("doubleProp", DOUBLE_VALUE);
+ props.put("bigDecimalProp", BIGDECIMAL_VALUE);
props.put("booleanProp", BOOLEAN_VALUE);
props.put("dateProp", DATE_VALUE);
props.put("calendarProp", CALENDAR_VALUE);
@@ -118,12 +123,35 @@ public abstract class AbstractSlingCrudResourceResolverTest {
ValueMap props = ResourceUtil.getValueMap(resource1);
assertEquals(STRING_VALUE, props.get("stringProp", String.class));
assertArrayEquals(STRING_ARRAY_VALUE, props.get("stringArrayProp", String[].class));
- assertEquals((Integer) INTEGER_VALUE, props.get("integerProp", Integer.class));
+ assertEquals((Integer)INTEGER_VALUE, props.get("integerProp", Integer.class));
+ assertEquals((Long)LONG_VALUE, props.get("longProp", Long.class));
assertEquals(DOUBLE_VALUE, props.get("doubleProp", Double.class), 0.0001);
+ assertEquals(BIGDECIMAL_VALUE, props.get("bigDecimalProp", BigDecimal.class));
assertEquals(BOOLEAN_VALUE, props.get("booleanProp", Boolean.class));
}
@Test
+ public void testSimpleProperties_IntegerLongConversion() throws IOException {
+ Resource resource1 = context.resourceResolver().getResource(getTestRootResource().getPath() + "/node1");
+ ValueMap props = ResourceUtil.getValueMap(resource1);
+
+ assertEquals((Integer)(int)LONG_VALUE, props.get("longProp", Integer.class));
+ assertEquals((Long)(long)INTEGER_VALUE, props.get("integerProp", Long.class));
+ }
+
+ @Test
+ public void testSimpleProperties_DecimalConversion() throws IOException {
+ Resource resource1 = context.resourceResolver().getResource(getTestRootResource().getPath() + "/node1");
+ ValueMap props = ResourceUtil.getValueMap(resource1);
+
+ // TODO: enable this test when resourceresolver-mock implementation supports BigDecimal conversion (SLING-6416)
+ if (getResourceResolverType() != ResourceResolverType.RESOURCERESOLVER_MOCK) {
+ assertEquals(new BigDecimal(DOUBLE_VALUE).doubleValue(), props.get("doubleProp", BigDecimal.class).doubleValue(), 0.0001d);
+ assertEquals(BIGDECIMAL_VALUE.doubleValue() , props.get("bigDecimalProp", Double.class), 0.0001d);
+ }
+ }
+
+ @Test
public void testSimpleProperties_DeepPathAccess() throws IOException {
Resource resource1 = context.resourceResolver().getResource(testRoot.getPath());
assertNotNull(resource1);
@@ -132,8 +160,10 @@ public abstract class AbstractSlingCrudResourceResolverTest {
ValueMap props = ResourceUtil.getValueMap(resource1);
assertEquals(STRING_VALUE, props.get("node1/stringProp", String.class));
assertArrayEquals(STRING_ARRAY_VALUE, props.get("node1/stringArrayProp", String[].class));
- assertEquals((Integer) INTEGER_VALUE, props.get("node1/integerProp", Integer.class));
+ assertEquals((Integer)INTEGER_VALUE, props.get("node1/integerProp", Integer.class));
+ assertEquals((Long)LONG_VALUE, props.get("node1/longProp", Long.class));
assertEquals(DOUBLE_VALUE, props.get("node1/doubleProp", Double.class), 0.0001);
+ assertEquals(BIGDECIMAL_VALUE, props.get("node1/bigDecimalProp", BigDecimal.class));
assertEquals(BOOLEAN_VALUE, props.get("node1/booleanProp", Boolean.class));
assertEquals(STRING_VALUE, props.get("node1/node11/stringProp11", String.class));
}
@@ -142,8 +172,7 @@ public abstract class AbstractSlingCrudResourceResolverTest {
public void testDateProperty() throws IOException {
Resource resource1 = context.resourceResolver().getResource(getTestRootResource().getPath() + "/node1");
ValueMap props = ResourceUtil.getValueMap(resource1);
- // TODO: enable this test when JCR resource implementation supports
- // writing Date objects (SLING-3846)
+ // TODO: enable this test when JCR resource implementation supports writing Date objects (SLING-3846)
if (getResourceResolverType() != ResourceResolverType.JCR_MOCK
&& getResourceResolverType() != ResourceResolverType.JCR_JACKRABBIT
&& getResourceResolverType() != ResourceResolverType.JCR_OAK ) {
@@ -155,8 +184,7 @@ public abstract class AbstractSlingCrudResourceResolverTest {
public void testDatePropertyToCalendar() throws IOException {
Resource resource1 = context.resourceResolver().getResource(getTestRootResource().getPath() + "/node1");
ValueMap props = ResourceUtil.getValueMap(resource1);
- // TODO: enable this test when JCR resource implementation supports
- // writing Date objects (SLING-3846)
+ // TODO: enable this test when JCR resource implementation supports writing Date objects (SLING-3846)
if (getResourceResolverType() != ResourceResolverType.JCR_MOCK
&& getResourceResolverType() != ResourceResolverType.JCR_JACKRABBIT
&& getResourceResolverType() != ResourceResolverType.JCR_OAK ) {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.