Unit test fixes for APPC-1267
[appc.git] / appc-outbound / appc-network-inventory-client / provider / src / main / java / org / onap / appc / instar / node / InstarClientNode.java
index 797bbd5..4087e2a 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2018 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -46,6 +48,7 @@ public class InstarClientNode implements SvcLogicJavaPlugin {
 
     private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarClientNode.class);
 
+
     public void getInstarInfo(Map<String, String> inParams, SvcLogicContext ctx)
         throws SvcLogicException {
         log.info("Received getInstarInfo call with params : " + inParams);
@@ -57,25 +60,26 @@ public class InstarClientNode implements SvcLogicJavaPlugin {
                 log.info("Processing Key : " + instarKey);
                 log.info("Searching key for  : " + "INSTAR." + instarKey);
                 ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
-                RuleHandlerInterface handler;
                 log.info("Received Context : " + ctx.getAttribute("INSTAR." + instarKey));
                 Parameter params = mapper
                     .readValue(ctx.getAttribute(InstarClientConstant.SOURCE_SYSTEM_INSTAR + "." + instarKey),
                         Parameter.class);
-
+                RuleHandlerInterface handler;
                 log.info("Processing rule Type : " + params.getRuleType());
                 if (params.getRuleType().equals(InstarClientConstant.INTERFACE_IP_ADDRESS)) {
-                    handler = new InterfaceIpAddressImpl(params, ctx);
+                    handler = createHandler(params, ctx);
                 } else {
                     throw new SvcLogicException("No Rule Defined to process :" + params.getRuleType());
                 }
                 handler.processRule();
             }
             log.info("responsePrefix =" + responsePrefix);
+            log.info("instar key values =" + ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
             ctx.setAttribute(responsePrefix + InstarClientConstant.INSTAR_KEY_VALUES,
                 ctx.getAttribute(InstarClientConstant.INSTAR_KEY_VALUES));
             ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS,
                 InstarClientConstant.OUTPUT_STATUS_SUCCESS);
+            log.info(ctx.getAttribute("TEST." + InstarClientConstant.OUTPUT_PARAM_STATUS));
             ctx.setAttribute(InstarClientConstant.INSTAR_KEY_VALUES, null);
         } catch (Exception e) {
             ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS,
@@ -88,12 +92,10 @@ public class InstarClientNode implements SvcLogicJavaPlugin {
 
     private static String[] getKeys(String keyString) {
         log.error("Received Key String as :" + keyString);
-
         String key = keyString
             .replace("[", "")
             .replace("]", "")
             .replace("\"", "");
-
         if (key.contains(",")) {
             return key.split(",");
         } else {
@@ -108,14 +110,12 @@ public class InstarClientNode implements SvcLogicJavaPlugin {
         try {
             HashMap<String, String> input = new HashMap<>();
             input.putAll(inParams);
-            RestClientInterface rcINterface = new InstarRestClientImpl(input);
+            RestClientInterface rcINterface = createRestClientInterface(input);
             String response = rcINterface.sendRequest(inParams.get("operationName"));
-
             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? responsePrefix + "." : "";
             ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS,
                 InstarClientConstant.OUTPUT_STATUS_SUCCESS);
             ctx.setAttribute(responsePrefix + InstarClientConstant.INSTAR_KEY_VALUES, response);
-
         } catch (Exception e) {
             ctx.setAttribute(responsePrefix + InstarClientConstant.OUTPUT_PARAM_STATUS,
                 InstarClientConstant.OUTPUT_STATUS_FAILURE);
@@ -135,12 +135,11 @@ public class InstarClientNode implements SvcLogicJavaPlugin {
                 log.info("Processing Key : " + aaiKey);
                 log.info("Searching key for  : " + "AAI." + aaiKey);
                 ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
-                RuleHandlerInterface handler;
                 log.info("Received Context : " + ctx.getAttribute("AAI." + aaiKey));
                 Parameter params = mapper.readValue(
                     ctx.getAttribute(AaiClientConstant.SOURCE_SYSTEM_AAI + "." + aaiKey), Parameter.class);
                 log.info("Processing rule Type : " + params.getRuleType());
-                handler = new AaiInterfaceRulesHandler(params, ctx);
+                RuleHandlerInterface handler = new AaiInterfaceRulesHandler(params, ctx);
                 handler.processRule();
             }
             log.info("responsePrefix =" + responsePrefix);
@@ -157,4 +156,12 @@ public class InstarClientNode implements SvcLogicJavaPlugin {
             throw new SvcLogicException(e.getMessage());
         }
     }
+
+    protected RuleHandlerInterface createHandler(Parameter params, SvcLogicContext ctx) {
+        return new InterfaceIpAddressImpl(params, ctx);
+    }
+
+    protected RestClientInterface createRestClientInterface(Map<String, String> input) {
+        return new InstarRestClientImpl(input);
+    }
 }