Remove code smells and increase code coverage
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / tasks / RefreshConfigTask.java
index 9a8dc34..4080b37 100644 (file)
@@ -81,9 +81,9 @@ public class RefreshConfigTask {
         stop();
         loadConfigurationFromFile();
         refreshTask = createRefreshTask() //
-            .subscribe(notUsed -> logger.info("Refreshed configuration data"),
+            .subscribe(notUsed -> logger.debug("Refreshed configuration data"),
                 throwable -> logger.error("Configuration refresh terminated due to exception", throwable),
-                () -> logger.error("Configuration refresh terminated"));
+                () -> logger.debug("Configuration refresh completed"));
     }
 
     public void stop() {
@@ -116,8 +116,9 @@ public class RefreshConfigTask {
         return cbsClient.updates(getConfigRequest, initialDelay, refreshPeriod);
     }
 
-    private <R> Mono<R> onErrorResume(Throwable trowable) {
-        logger.error("Could not refresh application configuration {}", trowable.toString());
+    private <R> Mono<R> onErrorResume(Throwable throwable) {
+        String errMsg = throwable.toString();
+        logger.error("Could not refresh application configuration. {}", errMsg);
         return Mono.empty();
     }
 
@@ -125,7 +126,8 @@ public class RefreshConfigTask {
         try {
             ApplicationConfigParser parser = new ApplicationConfigParser();
             parser.parse(jsonObject);
-            this.appConfig.setConfiguration(parser.getRicConfigs());
+            this.appConfig.setConfiguration(parser.getRicConfigs(), parser.getDmaapPublisherConfig(),
+                parser.getDmaapConsumerConfig());
         } catch (ServiceException e) {
             logger.error("Could not parse configuration {}", e.toString(), e);
         }
@@ -135,7 +137,7 @@ public class RefreshConfigTask {
     /**
      * Reads the configuration from file.
      */
-    public void loadConfigurationFromFile() {
+    void loadConfigurationFromFile() {
         String filepath = appConfig.getLocalConfigurationFilePath();
         if (filepath == null) {
             logger.debug("No localconfiguration file used");
@@ -145,22 +147,19 @@ public class RefreshConfigTask {
         ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
 
         try (InputStream inputStream = createInputStream(filepath)) {
-            JsonParser parser = new JsonParser();
-            JsonObject rootObject = getJsonElement(parser, inputStream).getAsJsonObject();
-            if (rootObject == null) {
-                throw new JsonSyntaxException("Root is not a json object");
-            }
+            JsonObject rootObject = getJsonElement(inputStream).getAsJsonObject();
             ApplicationConfigParser appParser = new ApplicationConfigParser();
             appParser.parse(rootObject);
-            appConfig.setConfiguration(appParser.getRicConfigs());
+            appConfig.setConfiguration(appParser.getRicConfigs(), appParser.getDmaapPublisherConfig(),
+                appParser.getDmaapConsumerConfig());
             logger.info("Local configuration file loaded: {}", filepath);
         } catch (JsonSyntaxException | ServiceException | IOException e) {
             logger.trace("Local configuration file not loaded: {}", filepath, e);
         }
     }
 
-    JsonElement getJsonElement(JsonParser parser, InputStream inputStream) {
-        return parser.parse(new InputStreamReader(inputStream));
+    JsonElement getJsonElement(InputStream inputStream) {
+        return JsonParser.parseReader(new InputStreamReader(inputStream));
     }
 
     InputStream createInputStream(@NotNull String filepath) throws IOException {