sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1650013 - /sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/JSONObjectTest.java
Date Wed, 07 Jan 2015 08:45:33 GMT
Author: cziegeler
Date: Wed Jan  7 08:45:33 2015
New Revision: 1650013

URL: http://svn.apache.org/r1650013
Log:
SLING-4288 : JSON object provided by org.apache.sling.commons.json 2.0.8 version returns null
when JSON object is having a value of type map and the map is having a list as one of its
element

Modified:
    sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/JSONObjectTest.java

Modified: sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/JSONObjectTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/JSONObjectTest.java?rev=1650013&r1=1650012&r2=1650013&view=diff
==============================================================================
--- sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/JSONObjectTest.java
(original)
+++ sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/JSONObjectTest.java
Wed Jan  7 08:45:33 2015
@@ -16,18 +16,30 @@
  */
 package org.apache.sling.commons.json;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import junit.framework.TestCase;
 
+import org.junit.Test;
+
 /**
  * @since Apr 17, 2009 6:04:00 PM
  */
-public class JSONObjectTest extends TestCase {
+public class JSONObjectTest {
+
     private static final String KEY = "key";
 
     /**
      * See <a href="https://issues.apache.org/jira/browse/SLING-929">SLING-929</a>
      */
-    public void testAppend() throws JSONException {
+    @Test public void testAppend() throws JSONException {
         JSONObject obj = new JSONObject();
         obj.append(KEY, "value1");
         obj.append(KEY, "value2");
@@ -38,7 +50,7 @@ public class JSONObjectTest extends Test
     /**
      * See <a href="https://issues.apache.org/jira/browse/SLING-929">SLING-929</a>
      */
-    public void testFailAppend() throws JSONException {
+    @Test public void testFailAppend() throws JSONException {
         JSONObject obj = new JSONObject();
         obj.put(KEY, "value1");
         try {
@@ -49,7 +61,7 @@ public class JSONObjectTest extends Test
         }
     }
 
-    public void testNull() throws JSONException {
+    @Test public void testNull() throws JSONException {
         JSONObject obj = new JSONObject();
         obj.put(KEY, JSONObject.NULL);
 
@@ -57,10 +69,24 @@ public class JSONObjectTest extends Test
         TestCase.assertTrue(obj.get(KEY).equals(null));
         TestCase.assertEquals("{\"" + KEY + "\":null}", obj.toString());
     }
-    
-    public void testParseLong() throws JSONException {
+
+    @Test public void testParseLong() throws JSONException {
         String jsonStr = "{\"longvalue\":\"13857270119014401\"}";
         JSONObject obj = new JSONObject(jsonStr);
         TestCase.assertEquals(13857270119014401L, obj.getLong("longvalue"));
     }
+
+    @Test public void testSample() throws JSONException {
+          Map<String,Object> map=new HashMap<String,Object>();
+          map.put("abc", "123456");
+          List<String> list = new ArrayList<String>();
+          list.add("Admin");
+          list.add("password");
+          map.put("groups", list);
+          JSONObject response=new JSONObject();
+          response.put("key", map);
+          assertNotNull(response.get("key"));
+          assertEquals("123456", response.getJSONObject("key").get("abc"));
+          assertEquals(list, response.getJSONObject("key").get("groups"));
+    }
 }



Mime
View raw message