2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modifications Copyright (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.flow.controller.node;
28 import static org.junit.Assert.assertEquals;
29 import static org.mockito.Matchers.anyObject;
30 import static org.mockito.Matchers.eq;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
34 import java.util.HashMap;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
42 public class FlowControlNodeTest {
44 private FlowControlDBService dbService;
45 private SvcLogicContext ctx;
46 private FlowControlNode flowControlNode;
47 private FlowSequenceGenerator flowSequenceGenerator;
48 private Map<String, String> inParams;
51 public void setUp() throws Exception {
52 ctx = new SvcLogicContext();
53 ctx.setAttribute("response.status", "success");
54 dbService = mock(FlowControlDBService.class);
55 flowSequenceGenerator = mock(FlowSequenceGenerator.class);
56 flowControlNode = new FlowControlNode(dbService, flowSequenceGenerator);
57 inParams = new HashMap<>();
58 inParams.put("responsePrefix", "response");
62 public void testProcessFlow() throws Exception {
63 String transactionJson = "{\"transaction-id\": \"1\","
64 + " \"action\": \"HealthCheck\", \"action-level\": \"vnf\","
65 + " \"executionModule\": \"APPC\", \"executionRPC\": \"healthcheck\", \"executionType\": \"node\","
66 + "\"precheck\":{\"precheck-operator\":\"any\",\"precheck-options\": ["
67 + "{\"pre-transaction-id\":\"1\",\"param-name\":\"executionType\",\"param-value\":\"node\"}]} }";
68 when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
69 .thenReturn("{\"transactions\" :[" + transactionJson + "] }");
70 flowControlNode.processFlow(inParams, ctx);
71 assertEquals("response.", ctx.getAttribute("response-prefix"));
75 public void testProcessFlowWithoutPrecheck() throws Exception {
76 String transactionJson = "{\"transaction-id\": \"1\","
77 + " \"action\": \"HealthCheck\", \"action-level\": \"vnf\","
78 + " \"executionModule\": \"APPC\", \"executionRPC\": \"healthcheck\", \"executionType\": \"node\","
79 + "\"precheck\":{\"precheck-operator\":\"any\",\"precheck-options\": ["
80 + "{\"pre-transaction-id\":\"1\",\"param-name\":\"executionType\",\"param-value\":\"node1\"}]} }";
81 when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
82 .thenReturn("{\"transactions\" :[" + transactionJson + "] }");
83 flowControlNode.processFlow(inParams, ctx);
84 assertEquals("response.", ctx.getAttribute("response-prefix"));
87 @Test(expected = SvcLogicException.class)
88 public void testProcessFlowWithFailure() throws Exception {
89 when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
90 .thenReturn("{\"transactions\" :[] }");
91 ctx.setAttribute("response.status", "fail");
92 flowControlNode.processFlow(inParams, ctx);
95 @Test(expected = SvcLogicException.class)
96 public void testProcessFlowWithNoExecutionType() throws Exception {
97 String transactionJson = "{\"transaction-id\": \"1\","
98 + " \"action\": \"HealthCheck\", \"action-level\": \"vnf\","
99 + " \"executionModule\": \"APPC\", \"executionRPC\": \"healthcheck\", \"executionType\": \"other\","
100 + "\"precheck\":{\"precheck-operator\":\"any\",\"precheck-options\": ["
101 + "{\"pre-transaction-id\":\"1\",\"param-name\":\"executionType\",\"param-value\":\"other\"}]} }";
102 when(flowSequenceGenerator.getFlowSequence(eq(inParams), eq(ctx), anyObject()))
103 .thenReturn("{\"transactions\" :[" + transactionJson + "] }");
104 ctx.setAttribute("response.status", "fail");
105 flowControlNode.processFlow(inParams, ctx);