summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-02-27 21:07:50 +0000
committerTakamune Cho <takamune.cho@att.com>2019-02-27 22:47:25 +0000
commitde4fcf5171fcc7713b83722906ca4364d253abe8 (patch)
tree0b9538f9a4c11975384d43d03172eec97044fef8
parent924616740bdf5f596bd6f32dac32c1a8e5504650 (diff)
Test coverage in FlowControlNode
Increase line coverage from 72% to 92% Fix for Sonar major issue for branch coverage Issue-ID: APPC-1499 Change-Id: Ie73b6c97fcf50421ca6a73a8273c09ace0faf67f Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/FlowControlNode.java46
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowControlNodeTest.java177
2 files changed, 130 insertions, 93 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 34d40dd55..e298967d0 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
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* =============================================================================
+ * Modifications Copyright (C) 2019 Ericsson
+ * =============================================================================
* 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
@@ -22,11 +24,7 @@
package org.onap.appc.flow.controller.node;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.ACTION_LEVEL;
-import static org.onap.appc.flow.controller.utils.FlowControllerConstants.APPC_FLOW_CONTROLLER;
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.GRAPH;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PARAM_RESPONSE_PREFIX;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.NODE;
@@ -35,42 +33,17 @@ import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_FAILURE;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_MESSAGE;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_SUCCESS;
-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.REQUEST_ID;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.RESPONSE_PREFIX;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST;
-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.SEQ_GENERATOR_PWD;
-import static org.onap.appc.flow.controller.utils.FlowControllerConstants.SEQ_GENERATOR_UID;
-import static org.onap.appc.flow.controller.utils.FlowControllerConstants.SEQ_GENERATOR_URL;
-import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VF_MODULE;
-import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VM;
-import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF;
-import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC;
-import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC_NAME;
-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 static org.onap.appc.flow.controller.utils.FlowControllerConstants.VSERVER_ID;
-
-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;
-import com.fasterxml.jackson.databind.SerializationFeature;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
-import org.json.JSONObject;
import org.onap.appc.flow.controller.ResponseHandlerImpl.DefaultResponseHandler;
import org.onap.appc.flow.controller.data.PrecheckOption;
import org.onap.appc.flow.controller.data.ResponseAction;
@@ -80,18 +53,13 @@ import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
import org.onap.appc.flow.controller.executorImpl.GraphExecutor;
import org.onap.appc.flow.controller.executorImpl.NodeExecutor;
import org.onap.appc.flow.controller.executorImpl.RestExecutor;
-import org.onap.appc.flow.controller.interfaceData.ActionIdentifier;
-import org.onap.appc.flow.controller.interfaceData.Capabilities;
-import org.onap.appc.flow.controller.interfaceData.DependencyInfo;
-import org.onap.appc.flow.controller.interfaceData.Input;
-import org.onap.appc.flow.controller.interfaceData.InventoryInfo;
-import org.onap.appc.flow.controller.interfaceData.RequestInfo;
-import org.onap.appc.flow.controller.interfaceData.Vnfcs;
import org.onap.appc.flow.controller.interfaces.FlowExecutorInterface;
-import org.onap.appc.flow.controller.utils.EncryptionTool;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.databind.ObjectMapper;
public class FlowControlNode implements SvcLogicJavaPlugin {
@@ -221,11 +189,11 @@ public class FlowControlNode implements SvcLogicJavaPlugin {
}
}
- private void sendIntermediateMessage() {
+ protected void sendIntermediateMessage() {
// TODO Auto-generated method stub
}
- private ResponseAction handleResponse(Transaction transaction, SvcLogicContext ctx) {
+ protected ResponseAction handleResponse(Transaction transaction, SvcLogicContext ctx) {
log.info("Handling Response for transaction Id " + transaction.getTransactionId());
DefaultResponseHandler defaultHandler = new DefaultResponseHandler();
return defaultHandler.handlerResponse(transaction, ctx);
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 1c29c9c9c..d89059ddf 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
@@ -35,73 +35,142 @@ import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.appc.flow.controller.data.ResponseAction;
+import org.onap.appc.flow.controller.data.Transaction;
import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
public class FlowControlNodeTest {
- private FlowControlDBService dbService;
- private SvcLogicContext ctx;
- private FlowControlNode flowControlNode;
- private FlowSequenceGenerator flowSequenceGenerator;
- private Map<String, String> inParams;
+ private FlowControlDBService dbService;
+ private SvcLogicContext ctx;
+ private FlowControlNode flowControlNode;
+ private FlowSequenceGenerator flowSequenceGenerator;
+ private Map<String, String> inParams;
- @Before
- public void setUp() throws Exception {
- ctx = new SvcLogicContext();
- ctx.setAttribute("response.status", "success");
- dbService = mock(FlowControlDBService.class);
- flowSequenceGenerator = mock(FlowSequenceGenerator.class);
- flowControlNode = new FlowControlNode(dbService, flowSequenceGenerator);
- inParams = new HashMap<>();
- inParams.put("responsePrefix", "response");
- }
+ @Before
+ public void setUp() throws Exception {
+ ctx = new SvcLogicContext();
+ ctx.setAttribute("response.status", "success");
+ dbService = mock(FlowControlDBService.class);
+ flowSequenceGenerator = mock(FlowSequenceGenerator.class);
+ flowControlNode = new FlowControlNode(dbService, flowSequenceGenerator);
+ inParams = new HashMap<>();
+ inParams.put("responsePrefix", "response");
+ }
- @Test
- public void testProcessFlow() throws Exception {
- String transactionJson = "{\"transaction-id\": \"1\","
- + " \"action\": \"HealthCheck\", \"action-level\": \"vnf\","
- + " \"executionModule\": \"APPC\", \"executionRPC\": \"healthcheck\", \"executionType\": \"node\","
- + "\"precheck\":{\"precheck-operator\":\"any\",\"precheck-options\": ["
- + "{\"pre-transaction-id\":\"1\",\"param-name\":\"executionType\",\"param-value\":\"node\"}]} }";
- when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
+ @Test
+ public void testProcessFlow() throws Exception {
+ String transactionJson = "{\"transaction-id\": \"1\","
+ + " \"action\": \"HealthCheck\", \"action-level\": \"vnf\","
+ + " \"executionModule\": \"APPC\", \"executionRPC\": \"healthcheck\", \"executionType\": \"node\","
+ + "\"precheck\":{\"precheck-operator\":\"any\",\"precheck-options\": ["
+ + "{\"pre-transaction-id\":\"1\",\"param-name\":\"executionType\",\"param-value\":\"node\"}]} }";
+ when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
.thenReturn("{\"transactions\" :[" + transactionJson + "] }");
- flowControlNode.processFlow(inParams, ctx);
- assertEquals("response.", ctx.getAttribute("response-prefix"));
- }
+ flowControlNode.processFlow(inParams, ctx);
+ assertEquals("response.", ctx.getAttribute("response-prefix"));
+ }
- @Test
- public void testProcessFlowWithoutPrecheck() throws Exception {
- String transactionJson = "{\"transaction-id\": \"1\","
- + " \"action\": \"HealthCheck\", \"action-level\": \"vnf\","
- + " \"executionModule\": \"APPC\", \"executionRPC\": \"healthcheck\", \"executionType\": \"node\","
- + "\"precheck\":{\"precheck-operator\":\"any\",\"precheck-options\": ["
- + "{\"pre-transaction-id\":\"1\",\"param-name\":\"executionType\",\"param-value\":\"node1\"}]} }";
- when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
+ @Test
+ public void testProcessFlowWithoutPrecheck() throws Exception {
+ String transactionJson = "{\"transaction-id\": \"1\","
+ + " \"action\": \"HealthCheck\", \"action-level\": \"vnf\","
+ + " \"executionModule\": \"APPC\", \"executionRPC\": \"healthcheck\", \"executionType\": \"node\","
+ + "\"precheck\":{\"precheck-operator\":\"any\",\"precheck-options\": ["
+ + "{\"pre-transaction-id\":\"1\",\"param-name\":\"executionType\",\"param-value\":\"node1\"}]} }";
+ when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
.thenReturn("{\"transactions\" :[" + transactionJson + "] }");
- flowControlNode.processFlow(inParams, ctx);
- assertEquals("response.", ctx.getAttribute("response-prefix"));
- }
+ flowControlNode.processFlow(inParams, ctx);
+ assertEquals("response.", ctx.getAttribute("response-prefix"));
+ }
- @Test(expected = SvcLogicException.class)
- public void testProcessFlowWithFailure() throws Exception {
- when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
+ @Test(expected = SvcLogicException.class)
+ public void testProcessFlowWithFailure() throws Exception {
+ when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
.thenReturn("{\"transactions\" :[] }");
- ctx.setAttribute("response.status", "fail");
- flowControlNode.processFlow(inParams, ctx);
- }
+ ctx.setAttribute("response.status", "fail");
+ flowControlNode.processFlow(inParams, ctx);
+ }
- @Test(expected = SvcLogicException.class)
- public void testProcessFlowWithNoExecutionType() throws Exception {
- String transactionJson = "{\"transaction-id\": \"1\","
- + " \"action\": \"HealthCheck\", \"action-level\": \"vnf\","
- + " \"executionModule\": \"APPC\", \"executionRPC\": \"healthcheck\", \"executionType\": \"other\","
- + "\"precheck\":{\"precheck-operator\":\"any\",\"precheck-options\": ["
- + "{\"pre-transaction-id\":\"1\",\"param-name\":\"executionType\",\"param-value\":\"other\"}]} }";
- when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
+ @Test(expected = SvcLogicException.class)
+ public void testProcessFlowWithNoExecutionType() throws Exception {
+ String transactionJson = "{\"transaction-id\": \"1\","
+ + " \"action\": \"HealthCheck\", \"action-level\": \"vnf\","
+ + " \"executionModule\": \"APPC\", \"executionRPC\": \"healthcheck\", \"executionType\": \"other\","
+ + "\"precheck\":{\"precheck-operator\":\"any\",\"precheck-options\": ["
+ + "{\"pre-transaction-id\":\"1\",\"param-name\":\"executionType\",\"param-value\":\"other\"}]} }";
+ when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
.thenReturn("{\"transactions\" :[" + transactionJson + "] }");
- ctx.setAttribute("response.status", "fail");
- flowControlNode.processFlow(inParams, ctx);
- }
+ ctx.setAttribute("response.status", "fail");
+ flowControlNode.processFlow(inParams, ctx);
+ }
+
+ @Test
+ public void testProcessFlowIntermediateMessage() throws Exception {
+ FlowControlNode mockNode = Mockito.spy(flowControlNode);
+ String transactionJson = "{\"transaction-id\": \"1\","
+ + " \"action\": \"HealthCheck\", \"action-level\": \"vnf\","
+ + " \"executionModule\": \"APPC\", \"executionRPC\": \"healthcheck\", \"executionType\": \"node\","
+ + "\"precheck\":{\"precheck-operator\":\"any\",\"precheck-options\": ["
+ + "{\"pre-transaction-id\":\"1\",\"param-name\":\"executionType\",\"param-value\":\"node\"}]} }";
+ when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
+ .thenReturn("{\"transactions\" :[" + transactionJson + "] }");
+ ResponseAction responseAction = Mockito.mock(ResponseAction.class);
+ when(responseAction.isIntermediateMessage()).thenReturn(true);
+ when(responseAction.getRetry()).thenReturn("1");
+ when(responseAction.getJump()).thenReturn("4");
+ Mockito.doReturn(responseAction).when(mockNode).handleResponse(anyObject(), anyObject());
+ mockNode.processFlow(inParams, ctx);
+ Mockito.verify(mockNode).sendIntermediateMessage();
+ }
+
+ @Test
+ public void testProcessFlowIntermediateMessageIsIgnore() throws Exception {
+ FlowControlNode mockNode = Mockito.spy(flowControlNode);
+ String transactionJson = "{\"transaction-id\": \"1\","
+ + " \"action\": \"HealthCheck\", \"action-level\": \"vnf\","
+ + " \"executionModule\": \"APPC\", \"executionRPC\": \"healthcheck\", \"executionType\": \"node\","
+ + "\"precheck\":{\"precheck-operator\":\"any\",\"precheck-options\": ["
+ + "{\"pre-transaction-id\":\"1\",\"param-name\":\"executionType\",\"param-value\":\"node\"}]} }";
+ when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
+ .thenReturn("{\"transactions\" :[" + transactionJson + "] }");
+ ResponseAction responseAction = Mockito.mock(ResponseAction.class);
+ when(responseAction.isIgnore()).thenReturn(true);
+ Mockito.doReturn(responseAction).when(mockNode).handleResponse(anyObject(), anyObject());
+ mockNode.processFlow(inParams, ctx);
+ assertEquals("response.", ctx.getAttribute("response-prefix"));
+ }
+
+ @Test
+ public void testProcessFlowIntermediateMessageIsStop() throws Exception {
+ FlowControlNode mockNode = Mockito.spy(flowControlNode);
+ String transactionJson = "{\"transaction-id\": \"1\","
+ + " \"action\": \"HealthCheck\", \"action-level\": \"vnf\","
+ + " \"executionModule\": \"APPC\", \"executionRPC\": \"healthcheck\", \"executionType\": \"node\","
+ + "\"precheck\":{\"precheck-operator\":\"any\",\"precheck-options\": ["
+ + "{\"pre-transaction-id\":\"1\",\"param-name\":\"executionType\",\"param-value\":\"node\"}]} }";
+ when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
+ .thenReturn("{\"transactions\" :[" + transactionJson + "] }");
+ ResponseAction responseAction = Mockito.mock(ResponseAction.class);
+ when(responseAction.isStop()).thenReturn(true);
+ Mockito.doReturn(responseAction).when(mockNode).handleResponse(anyObject(), anyObject());
+ mockNode.processFlow(inParams, ctx);
+ assertEquals("response.", ctx.getAttribute("response-prefix"));
+ }
+
+ @Test
+ public void testPreProcessorNullTransactionPrecheckOptions() throws Exception {
+ FlowControlNode mockNode = Mockito.spy(flowControlNode);
+ String transactionJson = "{\"transaction-id\": \"1\","
+ + " \"action\": \"HealthCheck\", \"action-level\": \"vnf\","
+ + " \"executionModule\": \"APPC\", \"executionRPC\": \"healthcheck\", \"executionType\": \"node\","
+ + "\"precheck\":{\"precheck-operator\":\"any\",\"precheck-options\": []} }";
+ when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
+ .thenReturn("{\"transactions\" :[" + transactionJson + "] }");
+ mockNode.processFlow(inParams, ctx);
+ assertEquals("response.", ctx.getAttribute("response-prefix"));
+ }
}