From 20eaa8a699ea41b7c40bbee7364dd3554af45606 Mon Sep 17 00:00:00 2001 From: kurczews Date: Fri, 2 Mar 2018 14:10:26 +0100 Subject: Improve coverage FlowControlNode #7 * refactor & test capabilities data method Change-Id: I523d07e283a347a4ad16f3babc8a25e0dd5a6acc Issue-ID: APPC-440 Signed-off-by: kurczews --- .../appc/flow/controller/node/FlowControlNode.java | 71 ++++++++-------------- 1 file changed, 24 insertions(+), 47 deletions(-) (limited to 'appc-config/appc-flow-controller/provider/src/main/java') diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowControlNode.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowControlNode.java index 35a99a9ea..16e869040 100644 --- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowControlNode.java +++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowControlNode.java @@ -59,6 +59,7 @@ import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VSERVE import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -468,66 +469,42 @@ public class FlowControlNode implements SvcLogicJavaPlugin { return dependencyInfo; } - private Capabilities getCapabilitiesData(SvcLogicContext ctx) throws Exception { + Capabilities getCapabilitiesData(SvcLogicContext ctx) throws Exception { String fn = "FlowExecutorNode.getCapabilitiesData"; - Capabilities capabilities = new Capabilities(); String capabilitiesData = dbService.getCapabilitiesData(ctx); log.info(fn + "capabilitiesDataInput:" + capabilitiesData); - if (capabilitiesData != null) { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); - JsonNode capabilitiesNode = mapper.readValue(capabilitiesData, JsonNode.class); - log.info("capabilitiesNode:" + capabilitiesNode.toString()); - - JsonNode vnfs = capabilitiesNode.findValue(VNF); - List vnfsList = new ArrayList<>(); - if (vnfs != null) { - for (int i = 0; i < vnfs.size(); i++) { - String vnf = vnfs.get(i).asText(); - vnfsList.add(vnf); - } - } + Capabilities capabilities = new Capabilities(); + if (capabilitiesData == null) { + return capabilities; + } - JsonNode vfModules = capabilitiesNode.findValue(VF_MODULE); - List vfModulesList = new ArrayList<>(); - if (vfModules != null) { - for (int i = 0; i < vfModules.size(); i++) { - String vfModule = vfModules.get(i).asText(); - vfModulesList.add(vfModule); - } - } + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); - JsonNode vnfcs = capabilitiesNode.findValue(VNFC); - List vnfcsList = new ArrayList<>(); - if (vnfcs != null) { - for (int i = 0; i < vnfcs.size(); i++) { - String vnfc1 = vnfcs.get(i).asText(); - vnfcsList.add(vnfc1); - } - } + JsonNode capabilitiesNode = mapper.readTree(capabilitiesData); + log.info("capabilitiesNode:" + capabilitiesNode.toString()); - JsonNode vms = capabilitiesNode.findValue(VM); - List vmList = new ArrayList<>(); - if (vms != null) { - for (int i = 0; i < vms.size(); i++) { - String vm1 = vms.get(i).asText(); - vmList.add(vm1); - } - } + capabilities.getVfModule().addAll(extractParameterList(mapper, capabilitiesNode, VF_MODULE)); + capabilities.getVnfc().addAll(extractParameterList(mapper, capabilitiesNode, VNFC)); + capabilities.getVnf().addAll(extractParameterList(mapper, capabilitiesNode, VNF)); + capabilities.getVm().addAll(extractParameterList(mapper, capabilitiesNode, VM)); - capabilities.getVnfc().addAll(vnfcsList); - capabilities.getVnf().addAll(vnfsList); - capabilities.getVfModule().addAll(vfModulesList); - capabilities.getVm().addAll(vmList); + log.info("Capabilities Output:" + capabilities.toString()); - log.info("Capabilities Output:" + capabilities.toString()); - } return capabilities; } + private List extractParameterList(ObjectMapper mapper, JsonNode root, String parameter) throws IOException { + JsonNode parameterNode = root.get(parameter); + if (parameterNode == null) { + return new ArrayList<>(); + } + return mapper.readValue(parameterNode.toString(), new TypeReference>() {}); + } + private Properties loadProperties() throws Exception { String directory = envVariables.getenv(SDNC_CONFIG_DIR_VAR); if (directory == null) { -- cgit 1.2.3-korg