2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.workflow.tasks;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Matchers.anyObject;
25 import static org.mockito.Matchers.anyString;
26 import static org.mockito.Matchers.isA;
27 import static org.mockito.Mockito.doNothing;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.when;
31 import java.util.ArrayList;
32 import java.util.List;
34 import org.camunda.bpm.engine.delegate.DelegateExecution;
35 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
36 import org.junit.Before;
37 import org.junit.Rule;
38 import org.junit.Test;
39 import org.junit.rules.ExpectedException;
40 import org.mockito.InjectMocks;
41 import org.mockito.Mock;
42 import org.mockito.Spy;
43 import org.onap.so.bpmn.BaseTaskTest;
44 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
45 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
46 import org.onap.so.db.request.beans.InfraActiveRequests;
48 public class WorkflowActionBBTasksTest extends BaseTaskTest {
51 protected WorkflowAction workflowAction;
55 protected WorkflowActionBBTasks workflowActionBBTasks;
57 private DelegateExecution execution;
60 public ExpectedException thrown = ExpectedException.none();
63 public void before() throws Exception {
64 execution = new DelegateExecutionFake();
65 org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.ServiceInstance();
66 servInstance.setServiceInstanceId("TEST");
67 when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance);
68 workflowAction.setBbInputSetupUtils(bbSetupUtils);
69 workflowAction.setBbInputSetup(bbInputSetup);
73 public void selectBBTest() throws Exception{
74 String gAction = "Delete-Network-Collection";
75 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
76 execution.setVariable("requestAction", gAction);
77 execution.setVariable("gCurrentSequence", 0);
78 execution.setVariable("homing", false);
79 execution.setVariable("calledHoming", false);
80 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
81 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock();
82 flowsToExecute.add(ebb);
83 execution.setVariable("flowsToExecute", flowsToExecute);
84 workflowActionBBTasks.selectBB(execution);
85 boolean success = (boolean) execution.getVariable("completed");
86 assertEquals(true,success);
90 public void select2BBTest() throws Exception{
91 String gAction = "Delete-Network-Collection";
92 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
93 execution.setVariable("requestAction", gAction);
94 execution.setVariable("gCurrentSequence", 0);
95 execution.setVariable("homing", false);
96 execution.setVariable("calledHoming", false);
97 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
98 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock();
99 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
100 flowsToExecute.add(ebb);
101 flowsToExecute.add(ebb2);
102 execution.setVariable("flowsToExecute", flowsToExecute);
103 workflowActionBBTasks.selectBB(execution);
104 boolean success = (boolean) execution.getVariable("completed");
105 assertEquals(false,success);
109 public void msoCompleteProcessTest() throws Exception{
110 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
111 execution.setVariable("requestAction", "createInstance");
112 execution.setVariable("resourceId", "123");
113 execution.setVariable("source","MSO");
114 execution.setVariable("resourceName", "Service");
115 execution.setVariable("aLaCarte", true);
116 workflowActionBBTasks.setupCompleteMsoProcess(execution);
117 String response = (String) execution.getVariable("CompleteMsoProcessRequest");
118 assertEquals(response,"<aetgt:MsoCompletionRequest xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\" xmlns:ns=\"http://org.onap/so/request/types/v1\"><request-info xmlns=\"http://org.onap/so/infra/vnf-request/v1\"><request-id>00f704ca-c5e5-4f95-a72c-6889db7b0688</request-id><action>createInstance</action><source>MSO</source></request-info><status-message>ALaCarte-Service-createInstance request was executed correctly.</status-message><serviceInstanceId>123</serviceInstanceId><mso-bpel-name>WorkflowActionBB</mso-bpel-name></aetgt:MsoCompletionRequest>");
122 public void rollbackExecutionPathTest(){
123 execution.setVariable("handlingCode", "Rollback");
124 execution.setVariable("isRollback", false);
125 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
126 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
127 BuildingBlock bb1 = new BuildingBlock();
128 bb1.setBpmnFlowName("AssignVfModuleBB");
129 ebb1.setBuildingBlock(bb1);
130 flowsToExecute.add(ebb1);
131 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
132 BuildingBlock bb2 = new BuildingBlock();
133 bb2.setBpmnFlowName("CreateVfModuleBB");
134 ebb2.setBuildingBlock(bb2);
135 flowsToExecute.add(ebb2);
136 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
137 BuildingBlock bb3 = new BuildingBlock();
138 bb3.setBpmnFlowName("ActivateVfModuleBB");
139 ebb3.setBuildingBlock(bb3);
140 flowsToExecute.add(ebb3);
142 execution.setVariable("flowsToExecute", flowsToExecute);
143 execution.setVariable("gCurrentSequence", 3);
144 doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
146 workflowActionBBTasks.rollbackExecutionPath(execution);
147 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
148 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateVfModuleBB");
149 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB");
150 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"UnassignVfModuleBB");
151 assertEquals(0,execution.getVariable("gCurrentSequence"));
155 public void rollbackExecutionPathUnfinishedFlowTest(){
156 execution.setVariable("handlingCode", "Rollback");
157 execution.setVariable("isRollback", false);
158 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
159 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
160 BuildingBlock bb1 = new BuildingBlock();
161 bb1.setBpmnFlowName("AssignVfModuleBB");
162 ebb1.setBuildingBlock(bb1);
163 flowsToExecute.add(ebb1);
164 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
165 BuildingBlock bb2 = new BuildingBlock();
166 bb2.setBpmnFlowName("CreateVfModuleBB");
167 ebb2.setBuildingBlock(bb2);
168 flowsToExecute.add(ebb2);
169 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
170 BuildingBlock bb3 = new BuildingBlock();
171 bb3.setBpmnFlowName("ActivateVfModuleBB");
172 ebb3.setBuildingBlock(bb3);
173 flowsToExecute.add(ebb3);
175 execution.setVariable("flowsToExecute", flowsToExecute);
176 execution.setVariable("gCurrentSequence", 2);
177 doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
179 workflowActionBBTasks.rollbackExecutionPath(execution);
180 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
181 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB");
182 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"UnassignVfModuleBB");
183 assertEquals(0,execution.getVariable("gCurrentSequence"));
184 assertEquals(0,execution.getVariable("retryCount"));
188 public void rollbackExecutionTest(){
189 execution.setVariable("handlingCode", "Rollback");
190 execution.setVariable("isRollback", false);
191 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
192 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
193 BuildingBlock bb1 = new BuildingBlock();
194 bb1.setBpmnFlowName("AssignServiceInstanceBB");
195 ebb1.setBuildingBlock(bb1);
196 flowsToExecute.add(ebb1);
197 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
198 BuildingBlock bb2 = new BuildingBlock();
199 bb2.setBpmnFlowName("CreateNetworkCollectionBB");
200 ebb2.setBuildingBlock(bb2);
201 flowsToExecute.add(ebb2);
202 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
203 BuildingBlock bb3 = new BuildingBlock();
204 bb3.setBpmnFlowName("AssignNetworkBB");
205 ebb3.setBuildingBlock(bb3);
206 flowsToExecute.add(ebb3);
207 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock();
208 BuildingBlock bb4 = new BuildingBlock();
209 bb4.setBpmnFlowName("CreateNetworkBB");
210 ebb4.setBuildingBlock(bb4);
211 flowsToExecute.add(ebb4);
213 execution.setVariable("flowsToExecute", flowsToExecute);
214 execution.setVariable("gCurrentSequence", 3);
215 doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
217 workflowActionBBTasks.rollbackExecutionPath(execution);
218 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
219 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"UnassignNetworkBB");
220 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkCollectionBB");
221 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"UnassignServiceInstanceBB");
222 assertEquals(0,execution.getVariable("gCurrentSequence"));
226 public void rollbackExecutionRollbackToAssignedTest(){
227 execution.setVariable("isRollback", false);
228 execution.setVariable("handlingCode", "RollbackToAssigned");
229 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
230 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
231 BuildingBlock bb1 = new BuildingBlock();
232 bb1.setBpmnFlowName("AssignServiceInstanceBB");
233 ebb1.setBuildingBlock(bb1);
234 flowsToExecute.add(ebb1);
235 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
236 BuildingBlock bb2 = new BuildingBlock();
237 bb2.setBpmnFlowName("CreateNetworkCollectionBB");
238 ebb2.setBuildingBlock(bb2);
239 flowsToExecute.add(ebb2);
240 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
241 BuildingBlock bb3 = new BuildingBlock();
242 bb3.setBpmnFlowName("AssignNetworkBB");
243 ebb3.setBuildingBlock(bb3);
244 flowsToExecute.add(ebb3);
245 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock();
246 BuildingBlock bb4 = new BuildingBlock();
247 bb4.setBpmnFlowName("CreateNetworkBB");
248 ebb4.setBuildingBlock(bb4);
249 flowsToExecute.add(ebb4);
251 execution.setVariable("flowsToExecute", flowsToExecute);
252 execution.setVariable("gCurrentSequence", 3);
253 doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
255 workflowActionBBTasks.rollbackExecutionPath(execution);
256 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
257 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkCollectionBB");
258 assertEquals(0,execution.getVariable("gCurrentSequence"));
262 public void checkRetryStatusTest(){
263 String reqId = "reqId123";
264 execution.setVariable("mso-request-id", reqId);
265 doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
266 execution.setVariable("handlingCode","Retry");
267 execution.setVariable("retryCount", 1);
268 execution.setVariable("gCurrentSequence",1);
269 InfraActiveRequests req = new InfraActiveRequests();
270 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
271 workflowActionBBTasks.checkRetryStatus(execution);
272 assertEquals(0,execution.getVariable("gCurrentSequence"));
276 public void checkRetryStatusNoRetryTest(){
277 String reqId = "reqId123";
278 execution.setVariable("mso-request-id", reqId);
279 execution.setVariable("retryCount", 3);
280 execution.setVariable("handlingCode","Success");
281 execution.setVariable("gCurrentSequence",1);
282 InfraActiveRequests req = new InfraActiveRequests();
283 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
284 workflowActionBBTasks.checkRetryStatus(execution);
285 assertEquals(0,execution.getVariable("retryCount"));