summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-flow-controller/provider/src/test
diff options
context:
space:
mode:
authorkurczews <krzysztof.kurczewski@nokia.com>2018-03-05 15:39:47 +0100
committerTakamune Cho <tc012c@att.com>2018-03-22 19:34:50 +0000
commit04d834a8258742f4c4acc4fb59224f255e953d75 (patch)
tree55d7aee54ed1665cd5f4bb0e370bb2a3c94c1cb6 /appc-config/appc-flow-controller/provider/src/test
parentbcc0324b5862a1d1bc46a4d5f8564431e8b3862e (diff)
Split sequence generation to classess
* Delegate original logic to separate clasess * Introduce InputParamsCollector * Introduce CapabilitiesDataExtractor * Add coverage for changes Change-Id: Ibb35dfb67306f789950c3b77362c5d79a3b6da63 Issue-ID: APPC-440 Signed-off-by: kurczews <krzysztof.kurczewski@nokia.com>
Diffstat (limited to 'appc-config/appc-flow-controller/provider/src/test')
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractorTest.java68
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowControlNodeTest.java54
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowGeneratorTest.java19
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowSequenceGeneratorTest.java208
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InputParamsCollectorTest.java130
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/JsonValidatorTest.java19
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/PropertiesLoaderTest.java19
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/ResourceUriExtractorTest.java19
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TestRestServiceNode.java5
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java14
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/executor/node/FlowControlNodeTest.java149
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/resources/appc-flow-controller.properties3
12 files changed, 499 insertions, 208 deletions
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractorTest.java
new file mode 100644
index 000000000..c373840ab
--- /dev/null
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractorTest.java
@@ -0,0 +1,68 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.appc.flow.controller.node;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
+import org.onap.appc.flow.controller.interfaceData.Capabilities;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+
+public class CapabilitiesDataExtractorTest {
+
+ private CapabilitiesDataExtractor capabilitiesDataExtractor;
+ private FlowControlDBService dbService;
+ private SvcLogicContext ctx;
+
+ @Before
+ public void setUp() {
+ dbService = mock(FlowControlDBService.class);
+ ctx = mock(SvcLogicContext.class);
+ capabilitiesDataExtractor = new CapabilitiesDataExtractor(dbService);
+ }
+
+ @Test
+ public void should_handle_capabilities_full_config() throws Exception {
+
+ String jsonPayload = "{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1', 'vf-module-2'],'vnfc':['vnfc-1', 'vnfc-2'],'vm':['vm-1', 'vm-2']}";
+ when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'","\""));
+
+ Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx);
+
+ Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[vf-module-1, vf-module-2], vm=[vm-1, vm-2], vnfc=[vnfc-1, vnfc-2]]", capabilitiesData.toString());
+ }
+
+ @Test
+ public void should_handle_capabilities_config_with_missing_params() throws Exception {
+
+ // CASE: vm is empty, vnfc is absent
+ String jsonPayload = "{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1'],'vm':[]}";
+ when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'","\""));
+
+ Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx);
+
+ Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[vf-module-1], vm=[], vnfc=[]]", capabilitiesData.toString());
+ }
+
+} \ No newline at end of file
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowControlNodeTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowControlNodeTest.java
index d171f5f8b..b3c47925a 100644
--- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowControlNodeTest.java
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowControlNodeTest.java
@@ -36,67 +36,23 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
-import org.onap.appc.flow.controller.interfaceData.Capabilities;
import org.onap.appc.flow.controller.interfaceData.DependencyInfo;
import org.onap.appc.flow.controller.interfaceData.Vnfcs;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
public class FlowControlNodeTest {
- private SvcLogicContext ctx;
private FlowControlDBService dbService;
+ private SvcLogicContext ctx;
+ private FlowControlNode flowControlNode;
+ private FlowSequenceGenerator flowSequenceGenerator;
@Before
public void setUp() {
ctx = mock(SvcLogicContext.class);
dbService = mock(FlowControlDBService.class);
- }
-
- @Test
- public void should_handle_capabilities_full_config() throws Exception {
-
- String jsonPayload = "{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1', 'vf-module-2'],'vnfc':['vnfc-1', 'vnfc-2'],'vm':['vm-1', 'vm-2']}";
- when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'","\""));
-
- FlowControlNode flowControlNode = new FlowControlNode(null, dbService);
- Capabilities capabilitiesData = flowControlNode.getCapabilitiesData(ctx);
-
- Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[vf-module-1, vf-module-2], vm=[vm-1, vm-2], vnfc=[vnfc-1, vnfc-2]]", capabilitiesData.toString());
- }
-
- @Test
- public void should_handle_capabilities_config_with_missing_params() throws Exception {
-
- // vm is empty, vnfc is absent
- String jsonPayload = "{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1'],'vm':[]}";
- when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'","\""));
-
- FlowControlNode flowControlNode = new FlowControlNode(null, dbService);
- Capabilities capabilitiesData = flowControlNode.getCapabilitiesData(ctx);
-
- Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[vf-module-1], vm=[], vnfc=[]]", capabilitiesData.toString());
- }
-
- @Test
- public void should_handle_dependency_config() throws Exception {
-
- Vnfcs vnfcs = new Vnfcs();
- vnfcs.setVnfcType("some-type");
- vnfcs.setResilience("some-resilence");
- vnfcs.setMandatory("some-mandatory");
- Map<String, List<Vnfcs>> input = new HashMap<>();
- List<Vnfcs> list = new ArrayList<>();
- list.add(vnfcs);
- list.add(vnfcs);
- input.put("vnfcs", list);
-
- String jsonPayload = new ObjectMapper().writeValueAsString(input);
-
- when(dbService.getDependencyInfo(ctx)).thenReturn(jsonPayload);
-
- FlowControlNode flowControlNode = new FlowControlNode(null, dbService);
- DependencyInfo dependencyInfo = flowControlNode.getDependencyInfo(ctx);
+ flowSequenceGenerator = mock(FlowSequenceGenerator.class);
- Assert.assertEquals("DependencyInfo [vnfcs=[Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilence, parents=[]], Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilence, parents=[]]]]", dependencyInfo.toString());
+ flowControlNode = new FlowControlNode(dbService, flowSequenceGenerator);
}
}
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowGeneratorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowGeneratorTest.java
index 5981fc0b6..1d4fb6951 100644
--- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowGeneratorTest.java
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowGeneratorTest.java
@@ -1,3 +1,22 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
package org.onap.appc.flow.controller.node;
import static org.mockito.Mockito.mock;
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowSequenceGeneratorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowSequenceGeneratorTest.java
new file mode 100644
index 000000000..533de5840
--- /dev/null
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowSequenceGeneratorTest.java
@@ -0,0 +1,208 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.appc.flow.controller.node;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.onap.appc.flow.controller.node.FlowSequenceGenerator.MODULE;
+import static org.onap.appc.flow.controller.node.InputParamsCollector.SDNC_CONFIG_DIR_VAR;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.DESINGTIME;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.EXTERNAL;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.FLOW_SEQUENCE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.GENERATION_NODE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.RUNTIME;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.SEQUENCE_TYPE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC_TYPE;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_ID;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_TYPE;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.appc.flow.controller.data.Transaction;
+import org.onap.appc.flow.controller.data.Transactions;
+import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
+import org.onap.appc.flow.controller.executorImpl.GraphExecutor;
+import org.onap.appc.flow.controller.executorImpl.RestExecutor;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+
+public class FlowSequenceGeneratorTest {
+
+ private FlowControlDBService dbService;
+ private Map<String, String> inParams;
+ private SvcLogicContext localCtx;
+ private SvcLogicContext ctx;
+ private FlowGenerator flowGenerator;
+ private GraphExecutor graphExecutor;
+ private FlowSequenceGenerator flowSequenceGenerator;
+ private RestExecutor restExecutor;
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Before
+ public void setUp() {
+ inParams = new HashMap<>();
+ ctx = mock(SvcLogicContext.class);
+ localCtx = mock(SvcLogicContext.class);
+ dbService = mock(FlowControlDBService.class);
+ flowGenerator = mock(FlowGenerator.class);
+ graphExecutor = mock(GraphExecutor.class);
+ restExecutor = mock(RestExecutor.class);
+
+ EnvVariables envVariables = mock(EnvVariables.class);
+
+ when(envVariables.getenv(SDNC_CONFIG_DIR_VAR)).thenReturn("./src/test/resources");
+
+ flowSequenceGenerator = new FlowSequenceGenerator(
+ dbService,
+ flowGenerator,
+ graphExecutor,
+ restExecutor,
+ envVariables
+ );
+ }
+
+ @Test
+ public void sequence_type_is_null() throws Exception {
+
+ Transaction transaction = new Transaction();
+ transaction.setExecutionType("mock-flow-generator");
+ ArrayList<Transaction> transactionList = new ArrayList<>();
+ transactionList.add(transaction);
+ Transactions transactions = new Transactions();
+ transactions.setTransactions(transactionList);
+
+ when(flowGenerator.createSingleStepModel(inParams, ctx)).thenReturn(transactions);
+
+ String seq = flowSequenceGenerator.getFlowSequence(inParams, ctx, localCtx);
+
+ Assert.assertEquals("{\"transactions\":[{\"executionType\":\"mock-flow-generator\",\"uId\":null,\"statusCode\":null,\"pswd\":null,\"executionEndPoint\":null,\"executionModule\":null,\"executionRPC\":null,\"status\":\"PENDING\",\"transaction-id\":0,\"action\":null,\"action-level\":null,\"action-identifier\":null,\"parameters\":null,\"state\":null,\"precheck\":null,\"payload\":null,\"responses\":null}]}", seq);
+ }
+
+ @Test
+ public void sequence_type_is_not_null_generator_and_generator_node_exists() throws Exception {
+
+ when(localCtx.getAttribute(SEQUENCE_TYPE)).thenReturn("some-seq-type");
+ when(localCtx.getAttribute(GENERATION_NODE)).thenReturn("some-gen-node");
+
+ when(graphExecutor.hasGraph(MODULE, "some-gen-node", null,"sync")).thenReturn(true);
+
+ Properties properties = new Properties();
+ properties.setProperty(FLOW_SEQUENCE, "flow-sequence");
+ when(graphExecutor.executeGraph(MODULE, "some-gen-node", null, "sync", null)).thenReturn(properties);
+
+ String seq = flowSequenceGenerator.getFlowSequence(inParams, ctx, localCtx);
+
+ Assert.assertEquals("flow-sequence", seq);
+ }
+
+ @Test
+ public void sequence_type_is_not_null_generator_exists_but_generator_node_not_exists() throws Exception {
+
+ when(localCtx.getAttribute(SEQUENCE_TYPE)).thenReturn("some-seq-type");
+ when(localCtx.getAttribute(GENERATION_NODE)).thenReturn("some-gen-node");
+
+ when(graphExecutor.hasGraph(MODULE, "some-gen-node", null,"sync")).thenReturn(false);
+
+ expectedException.expectMessage("Can not find Custom defined Flow Generator for some-gen-node");
+ flowSequenceGenerator.getFlowSequence(inParams, ctx, localCtx);
+ }
+
+ @Test
+ public void sequence_type_is_design_time() throws Exception {
+
+ when(localCtx.getAttribute(SEQUENCE_TYPE)).thenReturn(DESINGTIME);
+ when(dbService.getDesignTimeFlowModel(localCtx)).thenReturn("flow-sequence");
+
+ String flowSequence = flowSequenceGenerator.getFlowSequence(inParams, ctx, localCtx);
+ verify(localCtx).setAttribute(VNFC_TYPE, ctx.getAttribute(VNFC_TYPE));
+
+ Assert.assertEquals("flow-sequence", flowSequence);
+ }
+
+ @Test
+ public void sequence_type_is_design_time_but_got_null() throws Exception {
+
+ when(localCtx.getAttribute(SEQUENCE_TYPE)).thenReturn(DESINGTIME);
+ when(ctx.getAttribute(VNF_TYPE)).thenReturn("some-vnf-type");
+ when(dbService.getDesignTimeFlowModel(localCtx)).thenReturn(null);
+
+ expectedException.expectMessage("Flow Sequence is not found User Designed VNF some-vnf-type");
+ flowSequenceGenerator.getFlowSequence(inParams, ctx, localCtx);
+ verify(localCtx).setAttribute(VNFC_TYPE, ctx.getAttribute(VNFC_TYPE));
+ }
+
+ @Test
+ public void sequence_type_is_runtime() throws Exception {
+ when(localCtx.getAttribute(SEQUENCE_TYPE)).thenReturn(RUNTIME);
+ when(ctx.getAttribute(VNF_TYPE)).thenReturn("some-vnf-type");
+ when(ctx.getAttribute(VNF_ID)).thenReturn("some-vnf-id");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("restResponse", "{'output':{'dummy-json-object':'some-param'}}".replaceAll("'", "\""));
+ when(restExecutor.execute(any(Transaction.class), eq(localCtx))).thenReturn(map);
+
+ String flowSequence = flowSequenceGenerator.getFlowSequence(inParams, ctx, localCtx);
+
+ Assert.assertEquals("{'dummy-json-object':'some-param'}".replaceAll("'", "\""), flowSequence);
+ }
+
+ @Test
+ public void sequence_type_is_runtime_but_got_null() throws Exception {
+ when(localCtx.getAttribute(SEQUENCE_TYPE)).thenReturn(RUNTIME);
+ when(ctx.getAttribute(VNF_TYPE)).thenReturn("some-vnf-type");
+ when(ctx.getAttribute(VNF_ID)).thenReturn("some-vnf-id");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("restResponse", "{}".replaceAll("'", "\""));
+ when(restExecutor.execute(any(Transaction.class), eq(localCtx))).thenReturn(map);
+
+ expectedException.expectMessage("Failed to get the Flow Sequence runtime for VNF type some-vnf-type");
+ flowSequenceGenerator.getFlowSequence(inParams, ctx, localCtx);
+ }
+
+ @Test
+ public void sequence_type_is_external() throws Exception {
+ when(localCtx.getAttribute(SEQUENCE_TYPE)).thenReturn(EXTERNAL);
+ when(ctx.getAttribute(VNF_TYPE)).thenReturn("some-vnf-type");
+
+ expectedException.expectMessage("Flow Sequence not found for some-vnf-type");
+ flowSequenceGenerator.getFlowSequence(inParams, ctx, localCtx);
+ }
+
+ @Test
+ public void unknown_sequence() throws Exception {
+ when(localCtx.getAttribute(SEQUENCE_TYPE)).thenReturn("some-unknown-type");
+
+ expectedException.expectMessage("No information found for sequence Owner Design-Time Vs Run-Time");
+ flowSequenceGenerator.getFlowSequence(inParams, ctx, localCtx);
+ }
+
+} \ No newline at end of file
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InputParamsCollectorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InputParamsCollectorTest.java
new file mode 100644
index 000000000..dbf821e99
--- /dev/null
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InputParamsCollectorTest.java
@@ -0,0 +1,130 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.appc.flow.controller.node;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.onap.appc.flow.controller.node.InputParamsCollector.SDNC_CONFIG_DIR_VAR;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.ACTION_LEVEL;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.PAYLOAD;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REQUEST_ACTION;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC_NAME;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_ID;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VSERVER_ID;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.appc.flow.controller.data.Transaction;
+import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
+import org.onap.appc.flow.controller.interfaceData.DependencyInfo;
+import org.onap.appc.flow.controller.interfaceData.Vnfcs;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+
+public class InputParamsCollectorTest {
+
+ private SvcLogicContext ctx;
+ private FlowControlDBService dbService;
+ private EnvVariables envVariables;
+ private InputParamsCollector inputParamsCollector;
+
+ @Before
+ public void setUp() {
+
+ ctx = mock(SvcLogicContext.class);
+ dbService = mock(FlowControlDBService.class);
+ envVariables = mock(EnvVariables.class);
+
+ when(envVariables.getenv(SDNC_CONFIG_DIR_VAR)).thenReturn("./src/test/resources");
+
+ inputParamsCollector = new InputParamsCollector(envVariables, dbService);
+ }
+
+ @Test
+ public void should_collect_input_params() throws Exception {
+
+ when(ctx.getAttribute(VNF_ID)).thenReturn("some-vnf-id");
+ when(ctx.getAttribute(REQUEST_ACTION)).thenReturn("some-request-action");
+ when(ctx.getAttribute(ACTION_LEVEL)).thenReturn("some-action-level");
+ when(ctx.getAttribute(PAYLOAD)).thenReturn("some-payload");
+ when(ctx.getAttribute(VSERVER_ID)).thenReturn("some-vserver-id");
+ when(ctx.getAttribute(VNFC_NAME)).thenReturn("some-vnfc-name");
+
+ when(dbService.getCapabilitiesData(ctx)).thenReturn(
+ "{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1', 'vf-module-2'],'vnfc':['vnfc-1', 'vnfc-2'],'vm':['vm-1', 'vm-2']}"
+ .replaceAll("'", "\""));
+ when(dbService.getDependencyInfo(ctx)).thenReturn(dependencyInfoPayload());
+
+ Transaction transaction = inputParamsCollector.collectInputParams(ctx);
+
+ Assert.assertEquals(
+ "{\"input\":{\"request-info\":{\"action\":\"some-request-action\",\"payload\":\"some-payload\",\"action-level\":\"some-action-level\",\"action-identifier\":{\"vnf-id\":\"some-vnf-id\",\"vserver-id\":\"some-vserver-id\",\"vnfc-name\":\"some-vnfc-name\"}},\"inventory-info\":{\"vnf-info\":{\"vnf-id\":\"some-vnf-id\",\"vm\":[]}},\"dependency-info\":{\"vnfcs\":[{\"vnfc-type\":\"some-type\",\"mandatory\":\"some-mandatory\",\"resilience\":\"some-resilience\",\"parents\":[]},{\"vnfc-type\":\"some-type\",\"mandatory\":\"some-mandatory\",\"resilience\":\"some-resilience\",\"parents\":[]}]},\"capabilities\":{\"vnf\":[\"vnf-1\",\"vnf-2\"],\"vm\":[\"vm-1\",\"vm-2\"],\"vnfc\":[\"vnfc-1\",\"vnfc-2\"],\"vf-module\":[\"vf-module-1\",\"vf-module-2\"]}}}",
+ transaction.getPayload());
+ Assert.assertEquals("POST", transaction.getExecutionRPC());
+ Assert.assertEquals("seq-generator-uid", transaction.getuId());
+ Assert.assertEquals("some-pswd", transaction.getPswd());
+ Assert.assertEquals("exec-endpoint", transaction.getExecutionEndPoint());
+ }
+
+ @Test
+ public void should_handle_dependency_config() throws Exception {
+
+ Vnfcs vnfcs = new Vnfcs();
+ vnfcs.setVnfcType("some-type");
+ vnfcs.setResilience("some-resilience");
+ vnfcs.setMandatory("some-mandatory");
+ Map<String, List<Vnfcs>> input = new HashMap<>();
+ List<Vnfcs> list = new ArrayList<>();
+ list.add(vnfcs);
+ list.add(vnfcs);
+ input.put("vnfcs", list);
+
+ String jsonPayload = new ObjectMapper().writeValueAsString(input);
+
+ when(dbService.getDependencyInfo(ctx)).thenReturn(jsonPayload);
+
+ DependencyInfo dependencyInfo = inputParamsCollector.getDependencyInfo(ctx);
+
+ Assert.assertEquals(
+ "DependencyInfo [vnfcs=[Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilience, parents=[]], Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilience, parents=[]]]]",
+ dependencyInfo.toString());
+ }
+
+ private String dependencyInfoPayload() throws JsonProcessingException {
+ Vnfcs vnfcs = new Vnfcs();
+ vnfcs.setVnfcType("some-type");
+ vnfcs.setResilience("some-resilience");
+ vnfcs.setMandatory("some-mandatory");
+ Map<String, List<Vnfcs>> input = new HashMap<>();
+ List<Vnfcs> list = new ArrayList<>();
+ list.add(vnfcs);
+ list.add(vnfcs);
+ input.put("vnfcs", list);
+
+ return new ObjectMapper().writeValueAsString(input);
+ }
+
+} \ No newline at end of file
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/JsonValidatorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/JsonValidatorTest.java
index fd6f92018..e1a412d45 100644
--- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/JsonValidatorTest.java
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/JsonValidatorTest.java
@@ -1,3 +1,22 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
package org.onap.appc.flow.controller.node;
import com.fasterxml.jackson.databind.JsonNode;
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/PropertiesLoaderTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/PropertiesLoaderTest.java
index 66bf802c3..10bd94018 100644
--- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/PropertiesLoaderTest.java
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/PropertiesLoaderTest.java
@@ -1,3 +1,22 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
package org.onap.appc.flow.controller.node;
import java.io.FileNotFoundException;
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/ResourceUriExtractorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/ResourceUriExtractorTest.java
index 28a202c2d..e3f108e4a 100644
--- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/ResourceUriExtractorTest.java
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/ResourceUriExtractorTest.java
@@ -1,3 +1,22 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
package org.onap.appc.flow.controller.node;
import static org.mockito.Mockito.mock;
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TestRestServiceNode.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TestRestServiceNode.java
index 20a1fd3f9..fdf665a8e 100644
--- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TestRestServiceNode.java
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TestRestServiceNode.java
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+import static org.onap.appc.flow.controller.node.InputParamsCollector.SDNC_CONFIG_DIR_VAR;
import static org.onap.appc.flow.controller.node.RestServiceNode.REST_RESPONSE;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PARAM_RESPONSE_PREFIX;
@@ -47,7 +48,6 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException;
public class TestRestServiceNode {
private static final String RESOURCE_URI = "resource-uri";
- private static final String MOCK_ENV = "src/test/resources";
private static final String REST_BODY_RESPONSE = "{ 'state' : 'TEST' }";
private RestServiceNode restServiceNode;
@@ -87,7 +87,8 @@ public class TestRestServiceNode {
when(restExecutorMock.execute(eq(transaction), any(SvcLogicContext.class)))
.thenReturn(restResponseMap);
- EnvVariables envVariables = new EnvVariables(envKey -> MOCK_ENV);
+ EnvVariables envVariables = mock(EnvVariables.class);
+ when(envVariables.getenv(SDNC_CONFIG_DIR_VAR)).thenReturn("src/test/resources");
restServiceNode = new RestServiceNode(transactionHandlerMock, restExecutorMock, uriExtractorMock, envVariables);
}
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java
index 637a9ea6e..158e0c93b 100644
--- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java
@@ -1,24 +1,22 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+ * Copyright (C) 2018 Nokia. All rights reserved.
+ * =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- * * ============LICENSE_END=========================================================
+ * ============LICENSE_END=========================================================
*/
-
package org.onap.appc.flow.controller.node;
import static org.mockito.Mockito.mock;
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/executor/node/FlowControlNodeTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/executor/node/FlowControlNodeTest.java
deleted file mode 100644
index ba6f0c7ce..000000000
--- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/executor/node/FlowControlNodeTest.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Copyright (C) 2017 Amdocs
- * =============================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.flow.executor.node;
-
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.onap.appc.flow.controller.data.Transaction;
-import org.onap.appc.flow.controller.data.Transactions;
-import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
-import org.onap.appc.flow.controller.node.FlowControlNode;
-import org.onap.appc.flow.controller.utils.FlowControllerConstants;
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.reflect.Whitebox;
-
-public class FlowControlNodeTest {
- @Mock
- FlowControlDBService dbservice = FlowControlDBService.initialise();
- @Mock
- FlowControlNode f = new FlowControlNode();
-
- Properties props = new Properties();
- private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR";
- @Before
- public void setUp() throws Exception
-
- {
- FlowControlDBService dbservice = FlowControlDBService.initialise();
- }
- @Ignore("Test is taking 60 seconds")
- @Test(expected=Exception.class)
- public final void testProcessFlow() throws Exception {
- SvcLogicContext ctx = new SvcLogicContext();
-
- ctx.setAttribute("request-id","test");
- ctx.setAttribute("vnf-type","test");
- ctx.setAttribute("action-level","HealthCheck");
- ctx.setAttribute("request-action","HealthCheck");
- ctx.setAttribute("response-prefix","response-prefix");
-
- Map<String, String> inParams = new HashMap<String, String>();
- inParams.put("responsePrefix", "responsePrefix");
-
-
- Whitebox.invokeMethod(f, "processFlow",inParams, ctx);
- /*Properties props = new Properties();
- PowerMockito.spy(FlowControlNode.class);
- Transactions trans =null;
- HashMap<Integer, Transaction> transactionMap = null;
- String artifact_content="{‘PlaybookName’:’service_start’,‘EnvParameters’:{‘vnf_instance’:’$vnf_instance’},’Timeout’:600}";
- String capabilitiesData = "SUCCESS";
- System.out.println("End Test when");*/
-
-
- }
- @Ignore("Test is taking 60 seconds")
- @Test(expected=Exception.class)
- public void testprocessFlowSequence() throws Exception
- {
- Map<String, String> inparams = new HashMap<String,String>();
- SvcLogicContext ctx = new SvcLogicContext();
- ctx.setAttribute( " SEQUENCE-TYPE","test");
- ctx.setAttribute("flow-sequence", "1");
- ctx.setAttribute( "DesignTime","test");
- ctx.setAttribute( "vnf-type","test" );
-
- Whitebox.invokeMethod(f, "processFlowSequence",inparams, ctx, ctx);
-
- }
- @Test
- public void testexeuteAllTransaction() throws Exception
- {
- Map<Integer, Transaction> transactionMap = new HashMap<Integer,Transaction>();
- SvcLogicContext ctx = new SvcLogicContext();
- Whitebox.invokeMethod(f, "executeAllTransaction",transactionMap, ctx);
-
- }
- @Test
- public void testexeutepreProcessor() throws Exception
- {
- Map<Integer, Transaction> transactionMap = new HashMap<Integer,Transaction>();
- Transaction transaction = new Transaction();
- Whitebox.invokeMethod(f, "preProcessor",transactionMap, transaction);
-
- }
- @Test(expected=Exception.class)
- public void testcollectInputParams() throws Exception
- {
- SvcLogicContext ctx = new SvcLogicContext();
-
- Transaction transaction = new Transaction();
- Whitebox.invokeMethod(f, "collectInputParams",ctx, transaction);
-
- }
- @Ignore("Test is taking 60 seconds")
- @Test(expected=Exception.class)
- public void testgetDependencyInfo() throws Exception
- {
- SvcLogicContext ctx = new SvcLogicContext();
- Whitebox.invokeMethod(f, "getDependencyInfo",ctx);
-
- }
- public void testgetCapabilitesDatass() throws Exception
- {
- SvcLogicContext ctx = new SvcLogicContext();
- Whitebox.invokeMethod(f, "getDependencyInfo",ctx);
-
- }
-
-
-}
diff --git a/appc-config/appc-flow-controller/provider/src/test/resources/appc-flow-controller.properties b/appc-config/appc-flow-controller/provider/src/test/resources/appc-flow-controller.properties
index 0bbe7f207..e09a85e15 100644
--- a/appc-config/appc-flow-controller/provider/src/test/resources/appc-flow-controller.properties
+++ b/appc-config/appc-flow-controller/provider/src/test/resources/appc-flow-controller.properties
@@ -23,3 +23,6 @@
healthcheck.mock=false
healthcheck.default-rest-user=User
healthcheck.default-rest-pass=@#asd723%^
+seq_generator.uid=seq-generator-uid
+seq_generator.pwd=some-pswd
+seq_generator_url=exec-endpoint