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.doThrow;
29 import static org.mockito.Mockito.when;
31 import java.util.ArrayList;
32 import java.util.List;
34 import org.camunda.bpm.engine.delegate.BpmnError;
35 import org.camunda.bpm.engine.delegate.DelegateExecution;
36 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
37 import org.junit.Before;
38 import org.junit.Rule;
39 import org.junit.Test;
40 import org.junit.rules.ExpectedException;
41 import org.mockito.Mock;
42 import org.onap.so.bpmn.BaseTaskTest;
43 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
44 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
45 import org.onap.so.db.request.beans.InfraActiveRequests;
46 import org.springframework.beans.factory.annotation.Autowired;
48 public class WorkflowActionBBTasksTest extends BaseTaskTest {
51 protected WorkflowAction workflowAction;
54 protected WorkflowActionBBTasks workflowActionBBTasks;
56 private DelegateExecution execution;
59 public ExpectedException thrown = ExpectedException.none();
62 public void before() throws Exception {
63 execution = new DelegateExecutionFake();
64 org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.ServiceInstance();
65 servInstance.setServiceInstanceId("TEST");
66 when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance);
67 workflowAction.setBbInputSetupUtils(bbSetupUtils);
68 workflowAction.setBbInputSetup(bbInputSetup);
72 public void selectBBTest() throws Exception{
73 String gAction = "Delete-Network-Collection";
74 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
75 execution.setVariable("requestAction", gAction);
76 execution.setVariable("gCurrentSequence", 0);
77 execution.setVariable("homing", false);
78 execution.setVariable("calledHoming", false);
79 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
80 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock();
81 flowsToExecute.add(ebb);
82 execution.setVariable("flowsToExecute", flowsToExecute);
83 workflowActionBBTasks.selectBB(execution);
84 boolean success = (boolean) execution.getVariable("completed");
85 assertEquals(true,success);
89 public void getUpdatedRequestTest() throws Exception{
90 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
91 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
92 BuildingBlock bb1 = new BuildingBlock();
93 bb1.setBpmnFlowName("CreateNetworkBB");
94 flowsToExecute.add(ebb1);
95 ebb1.setBuildingBlock(bb1);
96 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
97 BuildingBlock bb2 = new BuildingBlock();
98 bb2.setBpmnFlowName("ActivateNetworkBB");
99 flowsToExecute.add(ebb2);
100 ebb2.setBuildingBlock(bb2);
101 String requestId = "requestId";
102 execution.setVariable("mso-request-id", requestId);
103 execution.setVariable("flowsToExecute", flowsToExecute);
104 int currentSequence = 2;
105 String expectedStatusMessage = "Execution of CreateNetworkBB has completed successfully, next invoking ActivateNetworkBB (Execution Path progress: BBs completed = 1; BBs remaining = 1).";
106 Long expectedLong = new Long(52);
107 InfraActiveRequests mockedRequest = new InfraActiveRequests();
108 when(requestsDbClient.getInfraActiveRequestbyRequestId(requestId)).thenReturn(mockedRequest);
109 InfraActiveRequests actual = workflowActionBBTasks.getUpdatedRequest(execution, currentSequence);
110 assertEquals(expectedStatusMessage, actual.getStatusMessage());
111 assertEquals(expectedLong, actual.getProgress());
115 public void select2BBTest() throws Exception{
116 String gAction = "Delete-Network-Collection";
117 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
118 execution.setVariable("requestAction", gAction);
119 execution.setVariable("gCurrentSequence", 0);
120 execution.setVariable("homing", false);
121 execution.setVariable("calledHoming", false);
122 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
123 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock();
124 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
125 flowsToExecute.add(ebb);
126 flowsToExecute.add(ebb2);
127 execution.setVariable("flowsToExecute", flowsToExecute);
128 workflowActionBBTasks.selectBB(execution);
129 boolean success = (boolean) execution.getVariable("completed");
130 assertEquals(false,success);
134 public void msoCompleteProcessTest() throws Exception{
135 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
136 execution.setVariable("requestAction", "createInstance");
137 execution.setVariable("resourceId", "123");
138 execution.setVariable("source","MSO");
139 execution.setVariable("resourceName", "Service");
140 execution.setVariable("aLaCarte", true);
141 workflowActionBBTasks.setupCompleteMsoProcess(execution);
142 String response = (String) execution.getVariable("CompleteMsoProcessRequest");
143 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>");
147 public void setupFalloutHandlerTest(){
148 execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
149 execution.setVariable("serviceInstanceId", "123");
150 execution.setVariable("WorkflowActionErrorMessage", "Error in WorkFlowAction");
151 execution.setVariable("requestAction", "createInstance");
152 workflowActionBBTasks.setupFalloutHandler(execution);
153 assertEquals(execution.getVariable("falloutRequest"),"<aetgt:FalloutHandlerRequest xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"xmlns:ns=\"http://org.onap/so/request/types/v1\"xmlns:wfsch=\"http://org.onap/so/workflow/schema/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>VID</source></request-info><aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>Error in WorkFlowAction</aetgt:ErrorMessage><aetgt:ErrorCode>7000</aetgt:ErrorCode></aetgt:WorkflowException></aetgt:FalloutHandlerRequest>");
157 public void rollbackExecutionPathTest(){
158 execution.setVariable("isRollback", false);
159 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
160 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
161 BuildingBlock bb1 = new BuildingBlock();
162 bb1.setBpmnFlowName("AssignVfModuleBB");
163 ebb1.setBuildingBlock(bb1);
164 flowsToExecute.add(ebb1);
165 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
166 BuildingBlock bb2 = new BuildingBlock();
167 bb2.setBpmnFlowName("CreateVfModuleBB");
168 ebb2.setBuildingBlock(bb2);
169 flowsToExecute.add(ebb2);
170 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
171 BuildingBlock bb3 = new BuildingBlock();
172 bb3.setBpmnFlowName("ActivateVfModuleBB");
173 ebb3.setBuildingBlock(bb3);
174 flowsToExecute.add(ebb3);
176 execution.setVariable("flowsToExecute", flowsToExecute);
177 execution.setVariable("gCurrentSequence", 3);
179 workflowActionBBTasks.rollbackExecutionPath(execution);
180 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
181 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateVfModuleBB");
182 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB");
183 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"UnassignVfModuleBB");
184 assertEquals(0,execution.getVariable("gCurrentSequence"));
188 public void rollbackExecutionPathUnfinishedFlowTest(){
189 execution.setVariable("isRollback", false);
190 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
191 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
192 BuildingBlock bb1 = new BuildingBlock();
193 bb1.setBpmnFlowName("AssignVfModuleBB");
194 ebb1.setBuildingBlock(bb1);
195 flowsToExecute.add(ebb1);
196 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
197 BuildingBlock bb2 = new BuildingBlock();
198 bb2.setBpmnFlowName("CreateVfModuleBB");
199 ebb2.setBuildingBlock(bb2);
200 flowsToExecute.add(ebb2);
201 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
202 BuildingBlock bb3 = new BuildingBlock();
203 bb3.setBpmnFlowName("ActivateVfModuleBB");
204 ebb3.setBuildingBlock(bb3);
205 flowsToExecute.add(ebb3);
207 execution.setVariable("flowsToExecute", flowsToExecute);
208 execution.setVariable("gCurrentSequence", 2);
210 workflowActionBBTasks.rollbackExecutionPath(execution);
211 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
212 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB");
213 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"UnassignVfModuleBB");
214 assertEquals(0,execution.getVariable("gCurrentSequence"));
218 public void rollbackExecutionTest(){
219 execution.setVariable("isRollback", false);
220 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
221 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
222 BuildingBlock bb1 = new BuildingBlock();
223 bb1.setBpmnFlowName("AssignServiceInstanceBB");
224 ebb1.setBuildingBlock(bb1);
225 flowsToExecute.add(ebb1);
226 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
227 BuildingBlock bb2 = new BuildingBlock();
228 bb2.setBpmnFlowName("CreateNetworkCollectionBB");
229 ebb2.setBuildingBlock(bb2);
230 flowsToExecute.add(ebb2);
231 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
232 BuildingBlock bb3 = new BuildingBlock();
233 bb3.setBpmnFlowName("AssignNetworkBB");
234 ebb3.setBuildingBlock(bb3);
235 flowsToExecute.add(ebb3);
236 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock();
237 BuildingBlock bb4 = new BuildingBlock();
238 bb4.setBpmnFlowName("CreateNetworkBB");
239 ebb4.setBuildingBlock(bb4);
240 flowsToExecute.add(ebb4);
242 execution.setVariable("flowsToExecute", flowsToExecute);
243 execution.setVariable("gCurrentSequence", 3);
245 workflowActionBBTasks.rollbackExecutionPath(execution);
246 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
247 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"UnassignNetworkBB");
248 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkCollectionBB");
249 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"UnassignServiceInstanceBB");
250 assertEquals(0,execution.getVariable("gCurrentSequence"));
254 public void checkRetryStatusTest(){
255 execution.setVariable("handlingCode","Retry");
256 execution.setVariable("retryCount", 1);
257 execution.setVariable("gCurrentSequence",1);
258 workflowActionBBTasks.checkRetryStatus(execution);
259 assertEquals(0,execution.getVariable("gCurrentSequence"));
263 public void checkRetryStatusNoRetryTest(){
264 execution.setVariable("retryCount", 3);
265 execution.setVariable("handlingCode","Success");
266 execution.setVariable("gCurrentSequence",1);
267 workflowActionBBTasks.checkRetryStatus(execution);
268 assertEquals(0,execution.getVariable("retryCount"));