aboutsummaryrefslogtreecommitdiffstats
path: root/appc-outbound/appc-network-inventory-client/provider/src/main
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2018-12-04 18:13:22 +0000
committerTakamune Cho <takamune.cho@att.com>2018-12-06 01:28:09 +0000
commitb267dd31fa51c039b316c31566568046cdbdfb0d (patch)
treeca1f8554b424681ee173cd63d2491a9fdd267bb6 /appc-outbound/appc-network-inventory-client/provider/src/main
parent5b48ccd6a79559967cfcb47addc50c84f9fa7213 (diff)
Unit test fixes for APPC-1267
Removed code smell for <65% branch coverage - now 86%. Test cases now cover success scenarios for all methods. Coverage increased to 97%. Removed classloader code and unnecessary resource files Moved construction of objects to protected methods to facilitate testing. Issue-ID: APPC-1267 Change-Id: I07656a5464410ca5ca3cca55cefd54c03a711385 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-outbound/appc-network-inventory-client/provider/src/main')
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/node/InstarClientNode.java27
-rwxr-xr-xappc-outbound/appc-network-inventory-client/provider/src/main/resources/templates/sampleKeyContents1
2 files changed, 17 insertions, 11 deletions
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/node/InstarClientNode.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/node/InstarClientNode.java
index 797bbd5e7..4087e2ad2 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/node/InstarClientNode.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/node/InstarClientNode.java
@@ -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);
+ }
}
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/resources/templates/sampleKeyContents b/appc-outbound/appc-network-inventory-client/provider/src/main/resources/templates/sampleKeyContents
deleted file mode 100755
index 90e3ec789..000000000
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/resources/templates/sampleKeyContents
+++ /dev/null
@@ -1 +0,0 @@
-{"name":"LOCAL_ACCESS_IP_ADDR","description":"this is the node0 tacplus server IP address","type":"ipv4_address","required":true,"source":"INSTAR","rule-type":"interface-ip-address","default":null,"request-keys":null,"response-keys":[{"unique-key-name":"addressfqdn","unique-key-value":"00000000000000","field-key-name":"ipaddress-v4"}]} \ No newline at end of file