You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2017/04/24 06:23:23 UTC

svn commit: r1792428 - in /felix/trunk/osgi-r7/configurator: ./ src/main/java/org/apache/felix/configurator/impl/ src/main/java/org/apache/felix/configurator/impl/json/ src/test/java/org/apache/felix/configurator/impl/ src/test/java/org/apache/felix/co...

Author: cziegeler
Date: Mon Apr 24 06:23:22 2017
New Revision: 1792428

URL: http://svn.apache.org/viewvc?rev=1792428&view=rev
Log:
Use javax.json (instead of osgi serializer) and update bundle tracking

Modified:
    felix/trunk/osgi-r7/configurator/pom.xml
    felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/Configurator.java
    felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java
    felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java
    felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/json/JSONUtilTest.java

Modified: felix/trunk/osgi-r7/configurator/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configurator/pom.xml?rev=1792428&r1=1792427&r2=1792428&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configurator/pom.xml (original)
+++ felix/trunk/osgi-r7/configurator/pom.xml Mon Apr 24 06:23:22 2017
@@ -69,7 +69,7 @@
                         <Provide-Capability>
                             osgi.implementation;osgi.implementation="osgi.configurator";version:Version="1.0"
                         </Provide-Capability>
-                        <Embed-Dependency>org.apache.felix.serializer,org.apache.felix.converter</Embed-Dependency>
+                        <Embed-Dependency>geronimo-json_1.0_spec,johnzon-core,org.apache.felix.converter</Embed-Dependency>
                     </instructions>
                 </configuration>
             </plugin>
@@ -105,9 +105,15 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.serializer</artifactId>
-            <version>0.1-SNAPSHOT</version>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-json_1.0_spec</artifactId>
+            <version>1.0-alpha-1</version>
+            <scope>provided</scope> 
+        </dependency>
+        <dependency>
+            <groupId>org.apache.johnzon</groupId>
+            <artifactId>johnzon-core</artifactId>
+            <version>1.0.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/Configurator.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/Configurator.java?rev=1792428&r1=1792427&r2=1792428&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/Configurator.java (original)
+++ felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/Configurator.java Mon Apr 24 06:23:22 2017
@@ -82,14 +82,16 @@ public class Configurator {
         this.state = State.createOrReadState(bundleContext);
         this.state.changeEnvironments(this.activeEnvironments);
         this.tracker = new org.osgi.util.tracker.BundleTracker<>(this.bundleContext,
-                Bundle.ACTIVE|Bundle.STARTING|Bundle.UNINSTALLED,
+                Bundle.ACTIVE|Bundle.STARTING|Bundle.STOPPING|Bundle.RESOLVED|Bundle.INSTALLED,
 
                 new BundleTrackerCustomizer<Bundle>() {
 
             @Override
             public Bundle addingBundle(final Bundle bundle, final BundleEvent event) {
+                final int state = bundle.getState();
                 if ( active &&
-                    (event.getType() == Bundle.ACTIVE || event.getType() == Bundle.STARTING) ) {
+                    (state == Bundle.ACTIVE || state == Bundle.STARTING) ) {
+                    SystemLogger.debug("Adding bundle " + getBundleIdentity(bundle) + " : " + getBundleState(state));
                     queue.enqueue(new Runnable() {
 
                         @Override
@@ -109,7 +111,9 @@ public class Configurator {
 
             @Override
             public void removedBundle(final Bundle bundle, final BundleEvent event, final Bundle object) {
-                if ( active && event.getType() == Bundle.UNINSTALLED ) {
+                final int state = bundle.getState();
+                if ( active && state == Bundle.UNINSTALLED ) {
+                    SystemLogger.debug("Removing bundle " + getBundleIdentity(bundle) + " : " + getBundleState(state));
                     queue.enqueue(new Runnable() {
 
                         @Override
@@ -118,7 +122,7 @@ public class Configurator {
                                 processRemoveBundle(bundle.getBundleId());
                                 process();
                             } catch ( final IllegalStateException ise) {
-                                SystemLogger.error("Error processing bundle " + bundle.getBundleId() + " - " + bundle.getSymbolicName(), ise);
+                                SystemLogger.error("Error processing bundle " + getBundleIdentity(bundle), ise);
                             }
                         }
                     });
@@ -128,6 +132,26 @@ public class Configurator {
         });
     }
 
+    private String getBundleIdentity(final Bundle bundle) {
+        if ( bundle.getSymbolicName() == null ) {
+            return bundle.getBundleId() + " (" + bundle.getLocation() + ")";
+        } else {
+            return bundle.getSymbolicName() + ":" + bundle.getVersion() + " (" + bundle.getBundleId() + ")";
+        }
+    }
+
+    private String getBundleState(int state) {
+        switch ( state ) {
+            case Bundle.ACTIVE : return "active";
+            case Bundle.INSTALLED : return "installed";
+            case Bundle.RESOLVED : return "resolved";
+            case Bundle.STARTING : return "starting";
+            case Bundle.STOPPING : return "stopping";
+            case Bundle.UNINSTALLED : return "uninstalled";
+        }
+        return String.valueOf(state);
+    }
+
     /**
      * Shut down the configurator
      */
@@ -263,7 +287,7 @@ public class Configurator {
             }
             state.setLastModified(bundleId, bundleLastModified);
         } catch ( final IllegalStateException ise) {
-            SystemLogger.error("Error processing bundle " + bundle.getBundleId() + " - " + bundle.getSymbolicName(), ise);
+            SystemLogger.error("Error processing bundle " + getBundleIdentity(bundle), ise);
         }
     }
 

Modified: felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java?rev=1792428&r1=1792427&r2=1792428&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java (original)
+++ felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java Mon Apr 24 06:23:22 2017
@@ -30,9 +30,18 @@ import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonNumber;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonString;
+import javax.json.JsonStructure;
+import javax.json.JsonValue;
+import javax.json.JsonValue.ValueType;
+
 import org.apache.felix.configurator.impl.TypeConverter;
 import org.apache.felix.configurator.impl.Util;
 import org.apache.felix.configurator.impl.logger.SystemLogger;
@@ -40,9 +49,7 @@ import org.apache.felix.configurator.imp
 import org.apache.felix.configurator.impl.model.Config;
 import org.apache.felix.configurator.impl.model.ConfigPolicy;
 import org.apache.felix.configurator.impl.model.ConfigurationFile;
-import org.apache.felix.serializer.impl.json.JsonSerializerImpl;
 import org.osgi.framework.Bundle;
-import org.osgi.service.serializer.Serializer;
 import org.osgi.util.converter.TypeReference;
 
 public class JSONUtil {
@@ -131,16 +138,16 @@ public class JSONUtil {
             final long bundleId,
             final String contents) {
         final String identifier = (url == null ? name : url.toString());
-        final Map json = parseJSON(name, contents);
+        final JsonObject json = parseJSON(name, contents);
         final List<?> configs = verifyJSON(name, json);
         if ( configs != null ) {
             final List<Config> configurations = new ArrayList<>();
             for(final Object obj : configs) {
-                if ( ! (obj instanceof Map) ) {
+                if ( ! (obj instanceof JsonObject) ) {
                     SystemLogger.error("Ignoring configuration in '" + identifier + "' (not a configuration) : " + obj);
                 } else {
-                    final Map mainMap = (Map)obj;
-                    final Object pid = mainMap.get(PROP_PID);
+                    final JsonObject mainMap = (JsonObject)obj;
+                    final Object pid = getValue(mainMap, PROP_PID);
                     if ( ! (pid instanceof String) ) {
                         SystemLogger.error("Ignoring configuration in '" + identifier + "' (no service.pid) : " + obj);
                     } else {
@@ -150,12 +157,11 @@ public class JSONUtil {
 
                         final Dictionary<String, Object> properties = new Hashtable<>();
                         boolean valid = true;
-                        for(final Object mapKeyObj : mainMap.keySet()) {
-                            final Object value = mainMap.get(mapKeyObj);
-                            final String mapKey = mapKeyObj.toString();
+                        for(final String mapKey : mainMap.keySet()) {
                             if ( mapKey.equals(PROP_PID) ) {
                                 continue;
                             }
+                            final Object value = getValue(mainMap, mapKey);
 
                             final boolean internalKey = mapKey.startsWith(INTERNAL_PREFIX);
                             String key = mapKey;
@@ -231,7 +237,7 @@ public class JSONUtil {
      * @param contents The contents
      * @return The parsed JSON object or {@code null} on failure,
      */
-    public static Map parseJSON(final String name, String contents) {
+    public static JsonObject parseJSON(final String name, String contents) {
         // minify JSON first (remove comments)
         try (final Reader in = new StringReader(contents);
              final Writer out = new StringWriter()) {
@@ -242,13 +248,55 @@ public class JSONUtil {
             SystemLogger.error("Invalid JSON from " + name);
             return null;
         }
-        final Serializer serializer = new JsonSerializerImpl();
-        try (final Reader reader = new StringReader(contents) ) {
-        	return serializer.deserialize(Map.class).from(reader);
-        } catch ( final IOException ioe) {
+        try (final JsonReader reader = Json.createReader(new StringReader(contents)) ) {
+            final JsonStructure obj = reader.read();
+            if ( obj != null && obj.getValueType() == ValueType.OBJECT ) {
+                return (JsonObject)obj;
+            }
             SystemLogger.error("Invalid JSON from " + name);
+        }
+        return null;
+    }
+
+    /**
+     * Get the value of a JSON property
+     * @param root The JSON Object
+     * @param key The key in the JSON Obejct
+     * @return The value or {@code null}
+     */
+    public static Object getValue(final JsonObject root, final String key) {
+        if ( !root.containsKey(key) ) {
             return null;
         }
+        final JsonValue value = root.get(key);
+        return getValue(value);
+    }
+
+    public static Object getValue(final JsonValue value) {
+        switch ( value.getValueType() ) {
+            // type NULL -> return null
+            case NULL : return null;
+            // type TRUE or FALSE -> return boolean
+            case FALSE : return false;
+            case TRUE : return true;
+            // type String -> return String
+            case STRING : return ((JsonString)value).getString();
+            // type Number -> return long or double
+            case NUMBER : final JsonNumber num = (JsonNumber)value;
+                          if (num.isIntegral()) {
+                               return num.longValue();
+                          }
+                          return num.doubleValue();
+            // type ARRAY -> return list and call this method for each value
+            case ARRAY : final List<Object> array = new ArrayList<>();
+                         for(final JsonValue x : ((JsonArray)value)) {
+                             array.add(getValue(x));
+                         }
+                         return array;
+            // type OBJECT -> return object
+            case OBJECT : return value;
+        }
+        return null;
     }
 
     /**
@@ -257,11 +305,11 @@ public class JSONUtil {
      * @param root The JSON root object.
      * @return JSON array with configurations or {@code null}
      */
-    public static List<?> verifyJSON(final String name, final Map root) {
+    public static List<?> verifyJSON(final String name, final JsonObject root) {
         if ( root == null ) {
             return null;
         }
-        final Object version = root.get(PROP_VERSION);
+        final Object version = getValue(root, PROP_VERSION);
         if ( version != null ) {
 
             final int v = TypeConverter.getConverter().convert(version).defaultValue(-1).to(Integer.class);
@@ -275,7 +323,7 @@ public class JSONUtil {
                 return null;
             }
         }
-        final Object configs =  root.get("configurations");
+        final Object configs = getValue(root, "configurations");
         if ( configs == null ) {
             // short cut, we just return false as we don't have to process this file
             return null;

Modified: felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java?rev=1792428&r1=1792427&r2=1792428&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java (original)
+++ felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java Mon Apr 24 06:23:22 2017
@@ -26,7 +26,8 @@ import static org.junit.Assert.assertTru
 import java.io.IOException;
 import java.lang.reflect.Array;
 import java.util.Collection;
-import java.util.Map;
+
+import javax.json.JsonObject;
 
 import org.apache.felix.configurator.impl.json.JSONUtil;
 import org.apache.felix.configurator.impl.json.JSONUtilTest;
@@ -104,143 +105,143 @@ public class TypeConverterTest {
     @Test public void testSimpleTypeConversions() throws Exception {
         final TypeConverter converter = new TypeConverter(null);
 
-        final Map config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
-        final Map properties = (Map)config.get("config");
+        final JsonObject config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
+        final JsonObject properties = (JsonObject)config.get("config");
 
-        assertTrue(converter.convert(null, properties.get("string"), null) instanceof String);
-        assertTrue(converter.convert(null, properties.get("boolean"), null) instanceof Boolean);
-        assertTrue(converter.convert(null, properties.get("number"), null) instanceof Long);
-        assertTrue(converter.convert(null, properties.get("float"), null) instanceof Double);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "string"), null) instanceof String);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "boolean"), null) instanceof Boolean);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number"), null) instanceof Long);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "float"), null) instanceof Double);
 
         // arrays
-        assertTrue(converter.convert(null, properties.get("string.array"), null).getClass().isArray());
-        assertTrue(Array.get(converter.convert(null, properties.get("string.array"), null), 0) instanceof String);
-        assertTrue(Array.get(converter.convert(null, properties.get("string.array"), null), 1) instanceof String);
-
-        assertTrue(converter.convert(null, properties.get("boolean.array"), null).getClass().isArray());
-        assertTrue(Array.get(converter.convert(null, properties.get("boolean.array"), null), 0) instanceof Boolean);
-        assertTrue(Array.get(converter.convert(null, properties.get("boolean.array"), null), 1) instanceof Boolean);
-
-        assertTrue(converter.convert(null, properties.get("number.array"), null).getClass().isArray());
-        assertTrue(Array.get(converter.convert(null, properties.get("number.array"), null), 0) instanceof Long);
-        assertTrue(Array.get(converter.convert(null, properties.get("number.array"), null), 1) instanceof Long);
-
-        assertTrue(converter.convert(null, properties.get("float.array"), null).getClass().isArray());
-        assertTrue(Array.get(converter.convert(null, properties.get("float.array"), null), 0) instanceof Double);
-        assertTrue(Array.get(converter.convert(null, properties.get("float.array"), null), 1) instanceof Double);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "string.array"), null).getClass().isArray());
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "string.array"), null), 0) instanceof String);
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "string.array"), null), 1) instanceof String);
+
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "boolean.array"), null).getClass().isArray());
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "boolean.array"), null), 0) instanceof Boolean);
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "boolean.array"), null), 1) instanceof Boolean);
+
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number.array"), null).getClass().isArray());
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "number.array"), null), 0) instanceof Long);
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "number.array"), null), 1) instanceof Long);
+
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "float.array"), null).getClass().isArray());
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "float.array"), null), 0) instanceof Double);
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "float.array"), null), 1) instanceof Double);
     }
 
     @Test public void testSimpleTypeConversionsWithTypeHint() throws Exception {
         final TypeConverter converter = new TypeConverter(null);
 
-        final Map config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
-        final Map properties = (Map)config.get("config");
+        final JsonObject config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
+        final JsonObject properties = (JsonObject)config.get("config");
 
-        assertTrue(converter.convert(null, properties.get("string"), "String") instanceof String);
-        assertTrue(converter.convert(null, properties.get("boolean"), "Boolean") instanceof Boolean);
-        assertTrue(converter.convert(null, properties.get("boolean"), "boolean") instanceof Boolean);
-        assertTrue(converter.convert(null, properties.get("number"), "Integer") instanceof Integer);
-        assertTrue(converter.convert(null, properties.get("number"), "int") instanceof Integer);
-        assertTrue(converter.convert(null, properties.get("number"), "Long") instanceof Long);
-        assertTrue(converter.convert(null, properties.get("number"), "long") instanceof Long);
-        assertTrue(converter.convert(null, properties.get("float"), "Double") instanceof Double);
-        assertTrue(converter.convert(null, properties.get("float"), "double") instanceof Double);
-        assertTrue(converter.convert(null, properties.get("float"), "Float") instanceof Float);
-        assertTrue(converter.convert(null, properties.get("float"), "float") instanceof Float);
-        assertTrue(converter.convert(null, properties.get("number"), "Byte") instanceof Byte);
-        assertTrue(converter.convert(null, properties.get("number"), "byte") instanceof Byte);
-        assertTrue(converter.convert(null, properties.get("number"), "Short") instanceof Short);
-        assertTrue(converter.convert(null, properties.get("number"), "short") instanceof Short);
-        assertTrue(converter.convert(null, properties.get("string"), "Character") instanceof Character);
-        assertTrue(converter.convert(null, properties.get("string"), "char") instanceof Character);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "string"), "String") instanceof String);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "boolean"), "Boolean") instanceof Boolean);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "boolean"), "boolean") instanceof Boolean);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number"), "Integer") instanceof Integer);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number"), "int") instanceof Integer);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number"), "Long") instanceof Long);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number"), "long") instanceof Long);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "float"), "Double") instanceof Double);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "float"), "double") instanceof Double);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "float"), "Float") instanceof Float);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "float"), "float") instanceof Float);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number"), "Byte") instanceof Byte);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number"), "byte") instanceof Byte);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number"), "Short") instanceof Short);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number"), "short") instanceof Short);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "string"), "Character") instanceof Character);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "string"), "char") instanceof Character);
 
         // arrays
-        assertTrue(converter.convert(null, properties.get("string.array"), "String[]").getClass().isArray());
-        assertTrue(Array.get(converter.convert(null, properties.get("string.array"), "String[]"), 0) instanceof String);
-        assertTrue(Array.get(converter.convert(null, properties.get("string.array"), "String[]"), 1) instanceof String);
-
-        assertTrue(converter.convert(null, properties.get("boolean.array"), "Boolean[]").getClass().isArray());
-        assertTrue(Array.get(converter.convert(null, properties.get("boolean.array"), "Boolean[]"), 0) instanceof Boolean);
-        assertTrue(Array.get(converter.convert(null, properties.get("boolean.array"), "Boolean[]"), 1) instanceof Boolean);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "string.array"), "String[]").getClass().isArray());
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "string.array"), "String[]"), 0) instanceof String);
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "string.array"), "String[]"), 1) instanceof String);
+
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "boolean.array"), "Boolean[]").getClass().isArray());
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "boolean.array"), "Boolean[]"), 0) instanceof Boolean);
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "boolean.array"), "Boolean[]"), 1) instanceof Boolean);
 
         // the following would throw class cast exceptions
-        boolean[] a0 = (boolean[])converter.convert(null, properties.get("boolean.array"), "boolean[]");
+        boolean[] a0 = (boolean[])converter.convert(null, JSONUtil.getValue(properties, "boolean.array"), "boolean[]");
         assertNotNull(a0);
-        int[] a1 = (int[])converter.convert(null, properties.get("number.array"), "int[]");
+        int[] a1 = (int[])converter.convert(null, JSONUtil.getValue(properties, "number.array"), "int[]");
         assertNotNull(a1);
-        long[] a2 = (long[])converter.convert(null, properties.get("number.array"), "long[]");
+        long[] a2 = (long[])converter.convert(null, JSONUtil.getValue(properties, "number.array"), "long[]");
         assertNotNull(a2);
-        double[] a3 = (double[])converter.convert(null, properties.get("float.array"), "double[]");
+        double[] a3 = (double[])converter.convert(null, JSONUtil.getValue(properties, "float.array"), "double[]");
         assertNotNull(a3);
-        float[] a4 = (float[])converter.convert(null, properties.get("float.array"), "float[]");
+        float[] a4 = (float[])converter.convert(null, JSONUtil.getValue(properties, "float.array"), "float[]");
         assertNotNull(a4);
-        byte[] a5 = (byte[])converter.convert(null, properties.get("number.array"), "byte[]");
+        byte[] a5 = (byte[])converter.convert(null, JSONUtil.getValue(properties, "number.array"), "byte[]");
         assertNotNull(a5);
-        short[] a6 = (short[])converter.convert(null, properties.get("number.array"), "short[]");
+        short[] a6 = (short[])converter.convert(null, JSONUtil.getValue(properties, "number.array"), "short[]");
         assertNotNull(a6);
-        char[] a7 = (char[])converter.convert(null, properties.get("string.array"), "char[]");
+        char[] a7 = (char[])converter.convert(null, JSONUtil.getValue(properties, "string.array"), "char[]");
         assertNotNull(a7);
 
-        assertTrue(converter.convert(null, properties.get("number.array"), "Integer[]").getClass().isArray());
-        assertTrue(Array.get(converter.convert(null, properties.get("number.array"), "Integer[]"), 0) instanceof Integer);
-        assertTrue(Array.get(converter.convert(null, properties.get("number.array"), "Integer[]"), 1) instanceof Integer);
-
-        assertTrue(converter.convert(null, properties.get("number.array"), "Long[]").getClass().isArray());
-        assertTrue(Array.get(converter.convert(null, properties.get("number.array"), "Long[]"), 0) instanceof Long);
-        assertTrue(Array.get(converter.convert(null, properties.get("number.array"), "Long[]"), 1) instanceof Long);
-
-        assertTrue(converter.convert(null, properties.get("number.array"), "Byte[]").getClass().isArray());
-        assertTrue(Array.get(converter.convert(null, properties.get("number.array"), "Byte[]"), 0) instanceof Byte);
-        assertTrue(Array.get(converter.convert(null, properties.get("number.array"), "Byte[]"), 1) instanceof Byte);
-
-        assertTrue(converter.convert(null, properties.get("number.array"), "Short[]").getClass().isArray());
-        assertTrue(Array.get(converter.convert(null, properties.get("number.array"), "Short[]"), 0) instanceof Short);
-        assertTrue(Array.get(converter.convert(null, properties.get("number.array"), "Short[]"), 1) instanceof Short);
-
-        assertTrue(converter.convert(null, properties.get("float.array"), "Float[]").getClass().isArray());
-        assertTrue(Array.get(converter.convert(null, properties.get("float.array"), "Float[]"), 0) instanceof Float);
-        assertTrue(Array.get(converter.convert(null, properties.get("float.array"), "Float[]"), 1) instanceof Float);
-
-        assertTrue(converter.convert(null, properties.get("float.array"), "Double[]").getClass().isArray());
-        assertTrue(Array.get(converter.convert(null, properties.get("float.array"), "Double[]"), 0) instanceof Double);
-        assertTrue(Array.get(converter.convert(null, properties.get("float.array"), "Double[]"), 1) instanceof Double);
-
-        assertTrue(converter.convert(null, properties.get("string.array"), "Character[]").getClass().isArray());
-        assertTrue(Array.get(converter.convert(null, properties.get("string.array"), "Character[]"), 0) instanceof Character);
-        assertTrue(Array.get(converter.convert(null, properties.get("string.array"), "Character[]"), 1) instanceof Character);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Integer[]").getClass().isArray());
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Integer[]"), 0) instanceof Integer);
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Integer[]"), 1) instanceof Integer);
+
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Long[]").getClass().isArray());
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Long[]"), 0) instanceof Long);
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Long[]"), 1) instanceof Long);
+
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Byte[]").getClass().isArray());
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Byte[]"), 0) instanceof Byte);
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Byte[]"), 1) instanceof Byte);
+
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Short[]").getClass().isArray());
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Short[]"), 0) instanceof Short);
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Short[]"), 1) instanceof Short);
+
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "float.array"), "Float[]").getClass().isArray());
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "float.array"), "Float[]"), 0) instanceof Float);
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "float.array"), "Float[]"), 1) instanceof Float);
+
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "float.array"), "Double[]").getClass().isArray());
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "float.array"), "Double[]"), 0) instanceof Double);
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "float.array"), "Double[]"), 1) instanceof Double);
+
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "string.array"), "Character[]").getClass().isArray());
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "string.array"), "Character[]"), 0) instanceof Character);
+        assertTrue(Array.get(converter.convert(null, JSONUtil.getValue(properties, "string.array"), "Character[]"), 1) instanceof Character);
     }
 
     @SuppressWarnings("unchecked")
     @Test public void testCollectionTypeConversion() throws Exception {
         final TypeConverter converter = new TypeConverter(null);
-        final Map config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
-        final Map properties = (Map)config.get("config");
+        final JsonObject config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
+        final JsonObject properties = (JsonObject)config.get("config");
 
-        assertTrue(converter.convert(null, properties.get("string.array"), "Collection<String>") instanceof Collection<?>);
-        assertTrue(((Collection<String>)converter.convert(null, properties.get("string.array"), "Collection<String>")).iterator().next() instanceof String);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "string.array"), "Collection<String>") instanceof Collection<?>);
+        assertTrue(((Collection<String>)converter.convert(null, JSONUtil.getValue(properties, "string.array"), "Collection<String>")).iterator().next() instanceof String);
 
-        assertTrue(converter.convert(null, properties.get("number.array"), "Collection<Integer>") instanceof Collection<?>);
-        assertTrue(((Collection<Integer>)converter.convert(null, properties.get("number.array"), "Collection<Integer>")).iterator().next() instanceof Integer);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Collection<Integer>") instanceof Collection<?>);
+        assertTrue(((Collection<Integer>)converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Collection<Integer>")).iterator().next() instanceof Integer);
 
-        assertTrue(converter.convert(null, properties.get("number.array"), "Collection<Long>") instanceof Collection<?>);
-        assertTrue(((Collection<Long>)converter.convert(null, properties.get("number.array"), "Collection<Long>")).iterator().next() instanceof Long);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Collection<Long>") instanceof Collection<?>);
+        assertTrue(((Collection<Long>)converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Collection<Long>")).iterator().next() instanceof Long);
 
-        assertTrue(converter.convert(null, properties.get("float.array"), "Collection<Float>") instanceof Collection<?>);
-        assertTrue(((Collection<Float>)converter.convert(null, properties.get("float.array"), "Collection<Float>")).iterator().next() instanceof Float);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "float.array"), "Collection<Float>") instanceof Collection<?>);
+        assertTrue(((Collection<Float>)converter.convert(null, JSONUtil.getValue(properties, "float.array"), "Collection<Float>")).iterator().next() instanceof Float);
 
-        assertTrue(converter.convert(null, properties.get("float.array"), "Collection<Double>") instanceof Collection<?>);
-        assertTrue(((Collection<Double>)converter.convert(null, properties.get("float.array"), "Collection<Double>")).iterator().next() instanceof Double);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "float.array"), "Collection<Double>") instanceof Collection<?>);
+        assertTrue(((Collection<Double>)converter.convert(null, JSONUtil.getValue(properties, "float.array"), "Collection<Double>")).iterator().next() instanceof Double);
 
-        assertTrue(converter.convert(null, properties.get("number.array"), "Collection<Short>") instanceof Collection<?>);
-        assertTrue(((Collection<Short>)converter.convert(null, properties.get("number.array"), "Collection<Short>")).iterator().next() instanceof Short);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Collection<Short>") instanceof Collection<?>);
+        assertTrue(((Collection<Short>)converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Collection<Short>")).iterator().next() instanceof Short);
 
-        assertTrue(converter.convert(null, properties.get("number.array"), "Collection<Byte>") instanceof Collection<?>);
-        assertTrue(((Collection<Byte>)converter.convert(null, properties.get("number.array"), "Collection<Byte>")).iterator().next() instanceof Byte);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Collection<Byte>") instanceof Collection<?>);
+        assertTrue(((Collection<Byte>)converter.convert(null, JSONUtil.getValue(properties, "number.array"), "Collection<Byte>")).iterator().next() instanceof Byte);
 
-        assertTrue(converter.convert(null, properties.get("string.array"), "Collection<Character>") instanceof Collection<?>);
-        assertTrue(((Collection<Character>)converter.convert(null, properties.get("string.array"), "Collection<Character>")).iterator().next() instanceof Character);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "string.array"), "Collection<Character>") instanceof Collection<?>);
+        assertTrue(((Collection<Character>)converter.convert(null, JSONUtil.getValue(properties, "string.array"), "Collection<Character>")).iterator().next() instanceof Character);
 
-        assertTrue(converter.convert(null, properties.get("boolean.array"), "Collection<Boolean>") instanceof Collection<?>);
-        assertTrue(((Collection<Boolean>)converter.convert(null, properties.get("boolean.array"), "Collection<Boolean>")).iterator().next() instanceof Boolean);
+        assertTrue(converter.convert(null, JSONUtil.getValue(properties, "boolean.array"), "Collection<Boolean>") instanceof Collection<?>);
+        assertTrue(((Collection<Boolean>)converter.convert(null, JSONUtil.getValue(properties, "boolean.array"), "Collection<Boolean>")).iterator().next() instanceof Boolean);
     }
 }

Modified: felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/json/JSONUtilTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/json/JSONUtilTest.java?rev=1792428&r1=1792427&r2=1792428&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/json/JSONUtilTest.java (original)
+++ felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/json/JSONUtilTest.java Mon Apr 24 06:23:22 2017
@@ -28,7 +28,8 @@ import java.io.StringWriter;
 import java.io.Writer;
 import java.net.URL;
 import java.util.List;
-import java.util.Map;
+
+import javax.json.JsonObject;
 
 import org.apache.felix.configurator.impl.TypeConverter;
 import org.apache.felix.configurator.impl.model.ConfigurationFile;
@@ -61,29 +62,29 @@ public class JSONUtilTest {
 
     @SuppressWarnings("unchecked")
     @Test public void testTypes() throws Exception {
-        final Map config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
-        final Map properties = (Map)config.get("config");
+        final JsonObject config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
+        final JsonObject properties = (JsonObject)config.get("config");
 
-        assertTrue(properties.get("string") instanceof String);
-        assertTrue(properties.get("boolean") instanceof Boolean);
-        assertTrue(properties.get("number") instanceof Long);
-        assertTrue(properties.get("float") instanceof Double);
+        assertTrue(JSONUtil.getValue(properties, "string") instanceof String);
+        assertTrue(JSONUtil.getValue(properties, "boolean") instanceof Boolean);
+        assertTrue(JSONUtil.getValue(properties, "number") instanceof Long);
+        assertTrue(JSONUtil.getValue(properties, "float") instanceof Double);
 
         // arrays
-        assertTrue(properties.get("string.array") instanceof List<?>);
-        assertTrue(((List<Object>)properties.get("string.array")).get(0) instanceof String);
-        assertTrue(((List<Object>)properties.get("string.array")).get(1) instanceof String);
-
-        assertTrue((List<Object>)properties.get("boolean.array") instanceof List<?>);
-        assertTrue(((List<Object>)properties.get("boolean.array")).get(0) instanceof Boolean);
-        assertTrue(((List<Object>)properties.get("boolean.array")).get(1) instanceof Boolean);
-
-        assertTrue((List<Object>)properties.get("number.array") instanceof List<?>);
-        assertTrue(((List<Object>)properties.get("number.array")).get(0) instanceof Long);
-        assertTrue(((List<Object>)properties.get("number.array")).get(1) instanceof Long);
-
-        assertTrue((List<Object>)properties.get("float.array") instanceof List<?>);
-        assertTrue(((List<Object>)properties.get("float.array")).get(0) instanceof Double);
-        assertTrue(((List<Object>)properties.get("float.array")).get(1) instanceof Double);
+        assertTrue(JSONUtil.getValue(properties, "string.array") instanceof List<?>);
+        assertTrue(((List<Object>)JSONUtil.getValue(properties, "string.array")).get(0) instanceof String);
+        assertTrue(((List<Object>)JSONUtil.getValue(properties, "string.array")).get(1) instanceof String);
+
+        assertTrue((List<Object>)JSONUtil.getValue(properties, "boolean.array") instanceof List<?>);
+        assertTrue(((List<Object>)JSONUtil.getValue(properties, "boolean.array")).get(0) instanceof Boolean);
+        assertTrue(((List<Object>)JSONUtil.getValue(properties, "boolean.array")).get(1) instanceof Boolean);
+
+        assertTrue((List<Object>)JSONUtil.getValue(properties, "number.array") instanceof List<?>);
+        assertTrue(((List<Object>)JSONUtil.getValue(properties, "number.array")).get(0) instanceof Long);
+        assertTrue(((List<Object>)JSONUtil.getValue(properties, "number.array")).get(1) instanceof Long);
+
+        assertTrue((List<Object>)JSONUtil.getValue(properties, "float.array") instanceof List<?>);
+        assertTrue(((List<Object>)JSONUtil.getValue(properties, "float.array")).get(0) instanceof Double);
+        assertTrue(((List<Object>)JSONUtil.getValue(properties, "float.array")).get(1) instanceof Double);
     }
 }
\ No newline at end of file