summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLathishbabu Ganesan <lathishbabu.ganesan@ericsson.com>2019-02-12 10:27:31 -0500
committerTakamune Cho <takamune.cho@att.com>2019-02-13 18:58:03 +0000
commit06d4030453f6d4be66e44d116933ee6b7947816a (patch)
tree3f2d31b98f561ce2af99d2b4036e50d18db1aca1
parent06a4a97fe7f095d5c47b57bd7353208f4aa5e484 (diff)
Added test case for Flow control Node
Increased the test coverage from 0% to 77% Issue-ID: APPC-1414 Change-Id: Ib65618e67af478bf577b103a27ebf0aa34f8bec3 Signed-off-by: Lathishbabu Ganesan <lathishbabu.ganesan@ericsson.com>
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/FlowControlNodeTest.java68
1 files changed, 59 insertions, 9 deletions
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 cc3028517..1c29c9c9c 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
@@ -6,6 +6,8 @@
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
+ * 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
@@ -23,21 +25,19 @@
package org.onap.appc.flow.controller.node;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-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.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;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
public class FlowControlNodeTest {
@@ -45,13 +45,63 @@ public class FlowControlNodeTest {
private SvcLogicContext ctx;
private FlowControlNode flowControlNode;
private FlowSequenceGenerator flowSequenceGenerator;
+ private Map<String, String> inParams;
@Before
- public void setUp() {
- ctx = mock(SvcLogicContext.class);
+ 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()))
+ .thenReturn("{\"transactions\" :[" + transactionJson + "] }");
+ 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()))
+ .thenReturn("{\"transactions\" :[" + transactionJson + "] }");
+ 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()))
+ .thenReturn("{\"transactions\" :[] }");
+ 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()))
+ .thenReturn("{\"transactions\" :[" + transactionJson + "] }");
+ ctx.setAttribute("response.status", "fail");
+ flowControlNode.processFlow(inParams, ctx);
}
}