You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2015/01/15 16:45:00 UTC

svn commit: r1652140 - in /sling/trunk/bundles/commons/json: pom.xml src/test/java/org/apache/sling/commons/json/sling/ src/test/java/org/apache/sling/commons/json/sling/JsonObjectCreatorTest.java

Author: bdelacretaz
Date: Thu Jan 15 15:45:00 2015
New Revision: 1652140

URL: http://svn.apache.org/r1652140
Log:
SLING-4258 - add JsonObjectCreatorTest (work in progress, needs more tests)

Added:
    sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/sling/
    sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/sling/JsonObjectCreatorTest.java
Modified:
    sling/trunk/bundles/commons/json/pom.xml

Modified: sling/trunk/bundles/commons/json/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/json/pom.xml?rev=1652140&r1=1652139&r2=1652140&view=diff
==============================================================================
--- sling/trunk/bundles/commons/json/pom.xml (original)
+++ sling/trunk/bundles/commons/json/pom.xml Thu Jan 15 15:45:00 2015
@@ -72,8 +72,14 @@
 		<dependency>
 			<groupId>org.apache.sling</groupId>
 			<artifactId>org.apache.sling.commons.testing</artifactId>
-			<version>2.0.6</version>
+			<version>2.0.16</version>
 			<scope>test</scope>
+			<exclusions>
+			    <exclusion>
+			        <groupId>org.jmock</groupId>
+			        <artifactId>jmock-junit4</artifactId>
+			    </exclusion>
+			</exclusions>
 		</dependency>
 		<dependency>
 			<groupId>junit</groupId>
@@ -83,5 +89,16 @@
 			<groupId>org.slf4j</groupId>
 			<artifactId>slf4j-simple</artifactId>
 		</dependency>
+       <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+            <version>1.9.5</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <scope>test</scope>
+        </dependency>
 	</dependencies>
 </project>

Added: sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/sling/JsonObjectCreatorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/sling/JsonObjectCreatorTest.java?rev=1652140&view=auto
==============================================================================
--- sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/sling/JsonObjectCreatorTest.java (added)
+++ sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/sling/JsonObjectCreatorTest.java Thu Jan 15 15:45:00 2015
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.commons.json.sling;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.wrappers.ValueMapDecorator;
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.JSONObject;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class JsonObjectCreatorTest {
+    
+    @Mock
+    private Resource resource;
+    
+    @Mock
+    private ResourceResolver resourceResolver;  
+    
+    @Before
+    public void setup() {
+        final Map<String, Object> props = new HashMap<String, Object>();
+        props.put("foo",  "bar");
+        final ValueMap values = new ValueMapDecorator(props);
+        
+        when(resource.getResourceResolver()).thenReturn(resourceResolver);
+        when(resource.adaptTo(ValueMap.class)).thenReturn(values);
+        final List<Resource> children = new ArrayList<Resource>();
+        when(resourceResolver.listChildren(any(Resource.class))).thenReturn(children.iterator());
+    }
+    
+    @Test
+    public void testBasicJSON() throws JSONException {
+        final JSONObject j = JsonObjectCreator.create(resource, 1);
+        assertEquals("bar", j.get("foo"));
+    }
+}