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 2016/12/19 11:49:27 UTC

svn commit: r1775063 - in /sling/trunk/testing/mocks: sling-mock-oak/pom.xml sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java

Author: sseifert
Date: Mon Dec 19 11:49:26 2016
New Revision: 1775063

URL: http://svn.apache.org/viewvc?rev=1775063&view=rev
Log:
update unit tests to test BigDecimal conversion (related to SLING-6416)

Modified:
    sling/trunk/testing/mocks/sling-mock-oak/pom.xml
    sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java

Modified: sling/trunk/testing/mocks/sling-mock-oak/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock-oak/pom.xml?rev=1775063&r1=1775062&r2=1775063&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock-oak/pom.xml (original)
+++ sling/trunk/testing/mocks/sling-mock-oak/pom.xml Mon Dec 19 11:49:26 2016
@@ -37,6 +37,7 @@
     <properties>
         <oak.version>1.4.1</oak.version>
         <jackrabbit.version>2.12.1</jackrabbit.version>
+        <sling-mock.version>2.2.5-SNAPSHOT</sling-mock.version>
     </properties>
 
     <scm>
@@ -50,14 +51,14 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.sling-mock</artifactId>
-            <version>2.1.2</version>
+            <version>${sling-mock.version}</version>
             <scope>compile</scope>
         </dependency>
     
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.sling-mock</artifactId>
-            <version>2.1.2</version>
+            <version>${sling-mock.version}</version>
             <classifier>tests</classifier>
             <scope>test</scope>
         </dependency>

Modified: sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java?rev=1775063&r1=1775062&r2=1775063&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java (original)
+++ sling/trunk/testing/mocks/sling-mock/src/test/java/org/apache/sling/testing/mock/sling/resource/AbstractSlingCrudResourceResolverTest.java Mon Dec 19 11:49:26 2016
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertTru
 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 AbstractSlingCrudR
     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 AbstractSlingCrudR
         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 AbstractSlingCrudR
         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 AbstractSlingCrudR
         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 AbstractSlingCrudR
     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_OAK ) {
             assertEquals(DATE_VALUE, props.get("dateProp", Date.class));
@@ -154,8 +183,7 @@ public abstract class AbstractSlingCrudR
     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_OAK ) {
             Calendar calendarValue = props.get("dateProp", Calendar.class);