summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-flow-controller/provider/src/main
diff options
context:
space:
mode:
authorkurczews <krzysztof.kurczewski@nokia.com>2018-03-02 14:10:26 +0100
committerTakamune Cho <tc012c@att.com>2018-03-12 15:12:42 +0000
commit20eaa8a699ea41b7c40bbee7364dd3554af45606 (patch)
tree30f0a6600dd27590fcd9b6cab0ee4f51e077b18b /appc-config/appc-flow-controller/provider/src/main
parentbb446bb30604c107be83b5cd10bee6b0a00eb8ad (diff)
Improve coverage FlowControlNode #7
* refactor & test capabilities data method Change-Id: I523d07e283a347a4ad16f3babc8a25e0dd5a6acc Issue-ID: APPC-440 Signed-off-by: kurczews <krzysztof.kurczewski@nokia.com>
Diffstat (limited to 'appc-config/appc-flow-controller/provider/src/main')
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowControlNode.java71
1 files changed, 24 insertions, 47 deletions
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<String> 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<String> 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<String> 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<String> 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 <T> List<T> 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<List<T>>() {});
+ }
+
private Properties loadProperties() throws Exception {
String directory = envVariables.getenv(SDNC_CONFIG_DIR_VAR);
if (directory == null) {