Merge "Add tests to increase code coverage"
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / configuration / ApplicationConfigParser.java
index dcfbc64..a76f964 100644 (file)
@@ -70,8 +70,10 @@ public class ApplicationConfigParser {
         Properties dmaapConsumerConfig = new Properties();
 
         JsonObject agentConfigJson = root.getAsJsonObject(CONFIG);
-        List<RicConfig> ricConfigs = parseRics(agentConfigJson);
-        Map<String, ControllerConfig> controllerConfigs = parseControllerConfigs(agentConfigJson);
+
+        if (agentConfigJson == null) {
+            throw new ServiceException("Missing root configuration \"" + CONFIG + "\" in JSON: " + root);
+        }
 
         JsonObject json = agentConfigJson.getAsJsonObject("streams_publishes");
         if (json != null) {
@@ -83,6 +85,8 @@ public class ApplicationConfigParser {
             dmaapConsumerConfig = parseDmaapConfig(json);
         }
 
+        List<RicConfig> ricConfigs = parseRics(agentConfigJson);
+        Map<String, ControllerConfig> controllerConfigs = parseControllerConfigs(agentConfigJson);
         checkConfigurationConsistency(ricConfigs, controllerConfigs);
 
         return ImmutableConfigParserResult.builder() //
@@ -119,9 +123,9 @@ public class ApplicationConfigParser {
             JsonObject ricAsJson = ricElem.getAsJsonObject();
             JsonElement controllerNameElement = ricAsJson.get(CONTROLLER);
             ImmutableRicConfig ricConfig = ImmutableRicConfig.builder() //
-                .name(ricAsJson.get("name").getAsString()) //
-                .baseUrl(ricAsJson.get("baseUrl").getAsString()) //
-                .managedElementIds(parseManagedElementIds(ricAsJson.get("managedElementIds").getAsJsonArray())) //
+                .name(get(ricAsJson, "name").getAsString()) //
+                .baseUrl(get(ricAsJson, "baseUrl").getAsString()) //
+                .managedElementIds(parseManagedElementIds(get(ricAsJson, "managedElementIds").getAsJsonArray())) //
                 .controllerName(controllerNameElement != null ? controllerNameElement.getAsString() : "") //
                 .build();
             result.add(ricConfig);
@@ -137,10 +141,10 @@ public class ApplicationConfigParser {
         for (JsonElement element : getAsJsonArray(config, CONTROLLER)) {
             JsonObject controllerAsJson = element.getAsJsonObject();
             ImmutableControllerConfig controllerConfig = ImmutableControllerConfig.builder() //
-                .name(controllerAsJson.get("name").getAsString()) //
-                .baseUrl(controllerAsJson.get("baseUrl").getAsString()) //
-                .password(controllerAsJson.get("password").getAsString()) //
-                .userName(controllerAsJson.get("userName").getAsString()) // )
+                .name(get(controllerAsJson, "name").getAsString()) //
+                .baseUrl(get(controllerAsJson, "baseUrl").getAsString()) //
+                .password(get(controllerAsJson, "password").getAsString()) //
+                .userName(get(controllerAsJson, "userName").getAsString()) // )
                 .build();
 
             if (result.put(controllerConfig.name(), controllerConfig) != null) {
@@ -164,7 +168,7 @@ public class ApplicationConfigParser {
     private static JsonElement get(JsonObject obj, String memberName) throws ServiceException {
         JsonElement elem = obj.get(memberName);
         if (elem == null) {
-            throw new ServiceException("Could not find member: " + memberName + " in: " + obj);
+            throw new ServiceException("Could not find member: '" + memberName + "' in: " + obj);
         }
         return elem;
     }
@@ -205,8 +209,8 @@ public class ApplicationConfigParser {
             dmaapProps.put("group", path.consumerGroup);
             dmaapProps.put("id", path.consumerId);
             dmaapProps.put("TransportType", ProtocolTypeConstants.HTTPNOAUTH.toString());
-            dmaapProps.put("timeout", 15000);
-            dmaapProps.put("limit", 100);
+            dmaapProps.put("timeout", "15000");
+            dmaapProps.put("limit", "100");
             dmaapProps.put("maxBatchSize", "10");
             dmaapProps.put("maxAgeMs", "10000");
             dmaapProps.put("compress", true);
@@ -215,7 +219,6 @@ public class ApplicationConfigParser {
         } catch (MalformedURLException e) {
             throw new ServiceException("Could not parse the URL", e);
         }
-
     }
 
     private static @NotNull String getAsString(JsonObject obj, String memberName) throws ServiceException {