2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2020 Nokia
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.workflow.tasks;
25 import org.camunda.bpm.engine.delegate.BpmnError;
26 import org.camunda.bpm.engine.delegate.DelegateExecution;
27 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
28 import org.junit.Before;
29 import org.junit.Rule;
30 import org.junit.Test;
31 import org.junit.rules.ExpectedException;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.Mockito;
35 import org.mockito.Spy;
36 import org.onap.aai.domain.yang.Configuration;
37 import org.onap.aai.domain.yang.GenericVnf;
38 import org.onap.aai.domain.yang.InstanceGroup;
39 import org.onap.aai.domain.yang.L3Network;
40 import org.onap.aai.domain.yang.ServiceInstance;
41 import org.onap.aai.domain.yang.VfModule;
42 import org.onap.aai.domain.yang.VolumeGroup;
43 import org.onap.so.bpmn.BaseTaskTest;
44 import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner;
45 import org.onap.so.bpmn.core.WorkflowException;
46 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
47 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
48 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
49 import org.onap.so.db.request.beans.InfraActiveRequests;
50 import org.onap.so.serviceinstancebeans.ModelInfo;
51 import org.onap.so.serviceinstancebeans.RequestDetails;
52 import org.springframework.core.env.Environment;
53 import java.util.ArrayList;
54 import java.util.List;
55 import java.util.Optional;
56 import static org.junit.Assert.assertEquals;
57 import static org.junit.Assert.assertTrue;
58 import static org.mockito.ArgumentMatchers.anyObject;
59 import static org.mockito.ArgumentMatchers.anyString;
60 import static org.mockito.ArgumentMatchers.isA;
61 import static org.mockito.Mockito.doNothing;
62 import static org.mockito.Mockito.doReturn;
63 import static org.mockito.Mockito.when;
65 public class WorkflowActionBBTasksTest extends BaseTaskTest {
67 private static final String SAMPLE_MSO_REQUEST_ID = "00f704ca-c5e5-4f95-a72c-6889db7b0688";
68 private static final String SAMPLE_REQUEST_ACTION = "Delete-Network-Collection";
69 private static final int SAMPLE_SEQUENCE = 0;
70 private static final String EMPTY_STRING = "";
72 protected WorkflowAction workflowAction;
75 protected WorkflowActionBBFailure workflowActionBBFailure;
79 protected WorkflowActionBBTasks workflowActionBBTasks;
82 InfraActiveRequests reqMock;
84 private DelegateExecution execution;
87 protected Environment environment;
90 private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
93 public ExpectedException thrown = ExpectedException.none();
96 public void before() throws Exception {
97 execution = new DelegateExecutionFake();
98 ServiceInstance servInstance = new ServiceInstance();
99 servInstance.setServiceInstanceId("TEST");
100 when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance);
101 workflowAction.setBbInputSetupUtils(bbSetupUtils);
102 workflowAction.setBbInputSetup(bbInputSetup);
106 public void selectBBTest() {
107 String vnfCustomizationUUID = "1234567";
108 String modelUuid = "1234567";
109 prepareDelegateExecution();
110 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
112 BuildingBlock buildingBlock =
113 new BuildingBlock().setBpmnFlowName("ConfigAssignVnfBB").setKey(vnfCustomizationUUID);
114 RequestDetails rd = new RequestDetails();
115 ModelInfo mi = new ModelInfo();
116 mi.setModelUuid(modelUuid);
118 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock();
119 ebb.setBuildingBlock(buildingBlock);
120 ebb.setRequestDetails(rd);
121 flowsToExecute.add(ebb);
123 List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
124 VnfResourceCustomization vrc = new VnfResourceCustomization();
125 vrc.setSkipPostInstConf(false);
126 vrc.setModelCustomizationUUID(vnfCustomizationUUID);
127 vnfResourceCustomizations.add(vrc);
128 GenericVnf genericVnf = new GenericVnf();
129 genericVnf.setModelCustomizationId(vnfCustomizationUUID);
130 doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
131 doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
132 vnfResourceCustomizations);
134 execution.setVariable("flowsToExecute", flowsToExecute);
135 workflowActionBBTasks.selectBB(execution);
136 boolean success = (boolean) execution.getVariable("completed");
137 int currentSequence = (int) execution.getVariable("gCurrentSequence");
139 assertEquals(1, currentSequence);
143 public void select2BBTest() {
144 String vnfCustomizationUUID = "1234567";
145 String modelUuid = "1234567";
147 prepareDelegateExecution();
148 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
149 BuildingBlock buildingBlock =
150 new BuildingBlock().setBpmnFlowName("ConfigDeployVnfBB").setKey(vnfCustomizationUUID);
151 RequestDetails rd = new RequestDetails();
152 ModelInfo mi = new ModelInfo();
153 mi.setModelUuid(modelUuid);
155 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock();
156 ebb.setBuildingBlock(buildingBlock);
157 ebb.setRequestDetails(rd);
158 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
160 flowsToExecute.add(ebb);
162 List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
163 VnfResourceCustomization vrc = new VnfResourceCustomization();
165 vrc.setSkipPostInstConf(false);
166 vrc.setModelCustomizationUUID(vnfCustomizationUUID);
167 vnfResourceCustomizations.add(vrc);
168 GenericVnf genericVnf = new GenericVnf();
169 genericVnf.setModelCustomizationId(vnfCustomizationUUID);
171 doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
172 doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
173 vnfResourceCustomizations);
175 flowsToExecute.add(ebb2);
176 execution.setVariable("flowsToExecute", flowsToExecute);
177 workflowActionBBTasks.selectBB(execution);
178 boolean success = (boolean) execution.getVariable("completed");
179 int currentSequence = (int) execution.getVariable("gCurrentSequence");
180 assertEquals(false, success);
181 assertEquals(1, currentSequence);
185 public void updateRequestStatusToCompleteTest() {
186 String reqId = "reqId123";
187 execution.setVariable("mso-request-id", reqId);
188 execution.setVariable("requestAction", "createInstance");
189 execution.setVariable("resourceName", "Service");
190 execution.setVariable("aLaCarte", true);
191 InfraActiveRequests req = new InfraActiveRequests();
192 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
193 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
194 workflowActionBBTasks.updateRequestStatusToComplete(execution);
195 assertEquals("ALaCarte-Service-createInstance request was executed correctly.",
196 execution.getVariable("finalStatusMessage"));
200 public void rollbackExecutionPathTest() {
201 execution.setVariable("handlingCode", "Rollback");
202 execution.setVariable("isRollback", false);
203 execution.setVariable("requestAction", EMPTY_STRING);
204 execution.setVariable("resourceName", EMPTY_STRING);
205 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
206 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
207 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
208 ebb1.setBuildingBlock(buildingBlock1);
209 flowsToExecute.add(ebb1);
211 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
212 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
213 ebb2.setBuildingBlock(buildingBlock2);
214 flowsToExecute.add(ebb2);
216 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
217 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
218 ebb3.setBuildingBlock(buildingBlock3);
219 flowsToExecute.add(ebb3);
221 execution.setVariable("flowsToExecute", flowsToExecute);
222 execution.setVariable("gCurrentSequence", 3);
223 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
225 workflowActionBBTasks.rollbackExecutionPath(execution);
226 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
227 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeactivateVfModuleBB");
228 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
229 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
230 assertEquals(0, execution.getVariable("gCurrentSequence"));
234 public void rollbackExecutionPathUnfinishedFlowTest() {
235 execution.setVariable("handlingCode", "Rollback");
236 execution.setVariable("isRollback", false);
237 execution.setVariable("requestAction", EMPTY_STRING);
238 execution.setVariable("resourceName", EMPTY_STRING);
239 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
240 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
241 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
242 ebb1.setBuildingBlock(buildingBlock1);
243 flowsToExecute.add(ebb1);
245 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
246 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
247 ebb2.setBuildingBlock(buildingBlock2);
248 flowsToExecute.add(ebb2);
250 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
251 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
252 ebb3.setBuildingBlock(buildingBlock3);
253 flowsToExecute.add(ebb3);
255 execution.setVariable("flowsToExecute", flowsToExecute);
256 execution.setVariable("gCurrentSequence", 2);
257 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
259 workflowActionBBTasks.rollbackExecutionPath(execution);
260 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
261 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
262 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
263 assertEquals(0, execution.getVariable("gCurrentSequence"));
264 assertEquals(0, execution.getVariable("retryCount"));
268 public void rollbackExecutionTest() {
269 execution.setVariable("handlingCode", "Rollback");
270 execution.setVariable("isRollback", false);
271 execution.setVariable("requestAction", EMPTY_STRING);
272 execution.setVariable("resourceName", EMPTY_STRING);
273 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
274 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB");
275 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
276 ebb1.setBuildingBlock(buildingBlock1);
277 flowsToExecute.add(ebb1);
279 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateNetworkCollectionBB");
280 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
281 ebb2.setBuildingBlock(buildingBlock2);
282 flowsToExecute.add(ebb2);
284 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("AssignNetworkBB");
285 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
286 ebb3.setBuildingBlock(buildingBlock3);
287 flowsToExecute.add(ebb3);
289 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("CreateNetworkBB");
290 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock();
291 ebb4.setBuildingBlock(buildingBlock4);
292 flowsToExecute.add(ebb4);
294 execution.setVariable("flowsToExecute", flowsToExecute);
295 execution.setVariable("gCurrentSequence", 3);
296 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
298 workflowActionBBTasks.rollbackExecutionPath(execution);
299 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
300 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "UnassignNetworkBB");
301 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteNetworkCollectionBB");
302 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignServiceInstanceBB");
303 assertEquals(0, execution.getVariable("gCurrentSequence"));
307 public void rollbackExecutionRollbackToAssignedTest() {
308 execution.setVariable("isRollback", false);
309 execution.setVariable("handlingCode", "RollbackToAssigned");
310 execution.setVariable("requestAction", EMPTY_STRING);
311 execution.setVariable("resourceName", EMPTY_STRING);
312 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
314 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
315 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
316 ebb1.setBuildingBlock(buildingBlock1);
317 flowsToExecute.add(ebb1);
319 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
320 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
321 ebb2.setBuildingBlock(buildingBlock2);
322 flowsToExecute.add(ebb2);
324 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
325 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
326 ebb3.setBuildingBlock(buildingBlock3);
327 flowsToExecute.add(ebb3);
329 execution.setVariable("flowsToExecute", flowsToExecute);
330 execution.setVariable("gCurrentSequence", 2);
332 workflowActionBBTasks.rollbackExecutionPath(execution);
333 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
334 assertEquals("DeleteVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
335 assertEquals(0, execution.getVariable("gCurrentSequence"));
336 assertEquals(1, ebbs.size());
340 public void rollbackExecutionPathChangeBBForReplaceVFModuleTest() {
341 execution.setVariable("handlingCode", "Rollback");
342 execution.setVariable("isRollback", false);
343 execution.setVariable("requestAction", "replaceInstance");
344 execution.setVariable("resourceName", "VfModule");
345 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
346 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
347 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
348 ebb1.setBuildingBlock(buildingBlock1);
349 flowsToExecute.add(ebb1);
351 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
352 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
353 ebb2.setBuildingBlock(buildingBlock2);
354 flowsToExecute.add(ebb2);
356 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
357 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
358 ebb3.setBuildingBlock(buildingBlock3);
359 flowsToExecute.add(ebb3);
362 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("ChangeModelVnfBB");
363 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock();
364 ebb4.setBuildingBlock(buildingBlock4);
365 flowsToExecute.add(ebb4);
367 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("ChangeModelServiceInstanceBB");
368 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock();
369 ebb5.setBuildingBlock(buildingBlock5);
370 flowsToExecute.add(ebb5);
372 execution.setVariable("flowsToExecute", flowsToExecute);
373 execution.setVariable("gCurrentSequence", 5);
374 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
376 workflowActionBBTasks.rollbackExecutionPath(execution);
377 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
378 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "ChangeModelVnfBB");
379 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "ChangeModelServiceInstanceBB");
380 assertEquals(0, execution.getVariable("gCurrentSequence"));
384 public void rollbackExecutionRollbackToAssignedWithFabricTest() {
385 execution.setVariable("isRollback", false);
386 execution.setVariable("handlingCode", "RollbackToAssigned");
387 execution.setVariable("requestAction", EMPTY_STRING);
388 execution.setVariable("resourceName", EMPTY_STRING);
389 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
391 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
392 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
393 ebb1.setBuildingBlock(buildingBlock1);
394 flowsToExecute.add(ebb1);
396 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
397 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
398 ebb2.setBuildingBlock(buildingBlock2);
399 flowsToExecute.add(ebb2);
401 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
402 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
403 ebb3.setBuildingBlock(buildingBlock3);
404 flowsToExecute.add(ebb3);
406 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
407 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock();
408 ebb4.setBuildingBlock(buildingBlock4);
409 flowsToExecute.add(ebb4);
411 execution.setVariable("flowsToExecute", flowsToExecute);
412 execution.setVariable("gCurrentSequence", 4);
414 workflowActionBBTasks.rollbackExecutionPath(execution);
415 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
416 assertEquals(0, execution.getVariable("gCurrentSequence"));
417 assertEquals(3, ebbs.size());
418 assertEquals("DeleteFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
419 assertEquals("DeactivateVfModuleBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
420 assertEquals("DeleteVfModuleBB", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
425 public void rollbackExecutionRollbackToCreatedTest() {
426 execution.setVariable("isRollback", false);
427 execution.setVariable("handlingCode", "RollbackToCreated");
428 execution.setVariable("requestAction", EMPTY_STRING);
429 execution.setVariable("resourceName", EMPTY_STRING);
430 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
431 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
432 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
433 ebb1.setBuildingBlock(buildingBlock1);
434 flowsToExecute.add(ebb1);
436 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
437 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
438 ebb2.setBuildingBlock(buildingBlock2);
439 flowsToExecute.add(ebb2);
441 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
442 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
443 ebb3.setBuildingBlock(buildingBlock3);
444 flowsToExecute.add(ebb3);
446 execution.setVariable("flowsToExecute", flowsToExecute);
447 execution.setVariable("gCurrentSequence", 3);
449 workflowActionBBTasks.rollbackExecutionPath(execution);
450 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
451 assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
452 assertEquals(0, execution.getVariable("gCurrentSequence"));
453 assertEquals(1, ebbs.size());
457 public void rollbackExecutionRollbackInPlaceSoftwareUpdateTest() {
458 execution.setVariable("isRollback", false);
459 execution.setVariable("handlingCode", "Rollback");
460 execution.setVariable("requestAction", EMPTY_STRING);
461 execution.setVariable("resourceName", EMPTY_STRING);
462 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
463 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
464 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
465 ebb1.setBuildingBlock(buildingBlock1);
466 flowsToExecute.add(ebb1);
468 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
469 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
470 ebb2.setBuildingBlock(buildingBlock2);
471 flowsToExecute.add(ebb2);
473 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
474 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
475 ebb3.setBuildingBlock(buildingBlock3);
476 flowsToExecute.add(ebb3);
478 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
479 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock();
480 ebb4.setBuildingBlock(buildingBlock4);
481 flowsToExecute.add(ebb4);
483 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
484 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock();
485 ebb5.setBuildingBlock(buildingBlock5);
486 flowsToExecute.add(ebb5);
488 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFLockActivity");
489 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock();
490 ebb6.setBuildingBlock(buildingBlock6);
491 flowsToExecute.add(ebb6);
493 BuildingBlock buildingBlock7 = new BuildingBlock().setBpmnFlowName("VNFUpgradePreCheckActivity");
494 ExecuteBuildingBlock ebb7 = new ExecuteBuildingBlock();
495 ebb7.setBuildingBlock(buildingBlock7);
496 flowsToExecute.add(ebb7);
498 BuildingBlock buildingBlock8 = new BuildingBlock().setBpmnFlowName("VNFQuiesceTrafficActivity");
499 ExecuteBuildingBlock ebb8 = new ExecuteBuildingBlock();
500 ebb8.setBuildingBlock(buildingBlock8);
501 flowsToExecute.add(ebb8);
503 BuildingBlock buildingBlock9 = new BuildingBlock().setBpmnFlowName("VNFStopActivity");
504 ExecuteBuildingBlock ebb9 = new ExecuteBuildingBlock();
505 ebb9.setBuildingBlock(buildingBlock9);
506 flowsToExecute.add(ebb9);
508 BuildingBlock buildingBlock10 = new BuildingBlock().setBpmnFlowName("VNFSnapShotActivity");
509 ExecuteBuildingBlock ebb10 = new ExecuteBuildingBlock();
510 ebb10.setBuildingBlock(buildingBlock10);
511 flowsToExecute.add(ebb10);
513 execution.setVariable("flowsToExecute", flowsToExecute);
514 execution.setVariable("gCurrentSequence", 10);
516 workflowActionBBTasks.rollbackExecutionPath(execution);
517 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
518 assertEquals("VNFStartActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
519 assertEquals("VNFResumeTrafficActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
520 assertEquals("VNFUnlockActivity", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
521 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(3).getBuildingBlock().getBpmnFlowName());
522 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(4).getBuildingBlock().getBpmnFlowName());
523 assertEquals(0, execution.getVariable("gCurrentSequence"));
524 assertEquals(5, ebbs.size());
528 public void rollbackExecutionRollbackConfigModifyTest() {
529 execution.setVariable("isRollback", false);
530 execution.setVariable("handlingCode", "Rollback");
531 execution.setVariable("requestAction", EMPTY_STRING);
532 execution.setVariable("resourceName", EMPTY_STRING);
533 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
534 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
535 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
536 ebb1.setBuildingBlock(buildingBlock1);
537 flowsToExecute.add(ebb1);
539 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
540 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
541 ebb2.setBuildingBlock(buildingBlock2);
542 flowsToExecute.add(ebb2);
544 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
545 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
546 ebb3.setBuildingBlock(buildingBlock3);
547 flowsToExecute.add(ebb3);
549 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
550 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock();
551 ebb4.setBuildingBlock(buildingBlock4);
552 flowsToExecute.add(ebb4);
554 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
555 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock();
556 ebb5.setBuildingBlock(buildingBlock5);
557 flowsToExecute.add(ebb5);
559 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFHealthCheckActivity");
560 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock();
561 ebb6.setBuildingBlock(buildingBlock6);
562 flowsToExecute.add(ebb6);
564 execution.setVariable("flowsToExecute", flowsToExecute);
565 execution.setVariable("gCurrentSequence", 6);
567 workflowActionBBTasks.rollbackExecutionPath(execution);
568 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
569 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
570 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
571 assertEquals(0, execution.getVariable("gCurrentSequence"));
572 assertEquals(2, ebbs.size());
577 public void checkRetryStatusTest() {
578 String reqId = "reqId123";
579 execution.setVariable("mso-request-id", reqId);
580 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
581 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
582 execution.setVariable("handlingCode", "Retry");
583 execution.setVariable("retryCount", 1);
584 execution.setVariable("gCurrentSequence", 1);
585 InfraActiveRequests req = new InfraActiveRequests();
586 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
587 workflowActionBBTasks.checkRetryStatus(execution);
588 assertEquals(0, execution.getVariable("gCurrentSequence"));
592 public void checkRetryStatusTestExceededMaxRetries() {
593 String reqId = "reqId123";
594 execution.setVariable("mso-request-id", reqId);
595 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
596 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
597 execution.setVariable("handlingCode", "Retry");
598 execution.setVariable("retryCount", 6);
599 execution.setVariable("gCurrentSequence", 1);
600 InfraActiveRequests req = new InfraActiveRequests();
601 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
603 workflowActionBBTasks.checkRetryStatus(execution);
604 } catch (BpmnError e) {
605 WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException");
606 assertEquals("Exceeded maximum retries. Ending flow with status Abort", exception.getErrorMessage());
611 public void checkRetryStatusNoRetryTest() {
612 String reqId = "reqId123";
613 execution.setVariable("mso-request-id", reqId);
614 execution.setVariable("retryCount", 3);
615 execution.setVariable("handlingCode", "Success");
616 execution.setVariable("gCurrentSequence", 1);
617 InfraActiveRequests req = new InfraActiveRequests();
618 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
619 workflowActionBBTasks.checkRetryStatus(execution);
620 assertEquals(0, execution.getVariable("retryCount"));
624 public void updateInstanceId() {
625 String reqId = "req123";
626 String instanceId = "123123123";
627 execution.setVariable("mso-request-id", reqId);
628 execution.setVariable("resourceId", instanceId);
629 execution.setVariable("resourceType", WorkflowType.SERVICE);
630 doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
631 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
632 workflowActionBBTasks.updateInstanceId(execution);
633 Mockito.verify(reqMock, Mockito.times(1)).setServiceInstanceId(instanceId);
637 public void getConfigurationId() {
638 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
639 vnfc.setModelInvariantId("modelInvariantId");
640 vnfc.setVnfcName("testVnfcName");
641 List<Configuration> configurations = new ArrayList<>();
642 org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
643 configuration.setConfigurationId("configurationId");
644 configuration.setModelCustomizationId("modelCustimizationId");
645 configuration.setConfigurationName("testConfigurationName");
646 configurations.add(configuration);
647 doReturn(configurations.get(0).getConfigurationId()).when(workflowActionBBTasks).getConfigurationId(vnfc);
648 assertEquals(workflowActionBBTasks.getConfigurationId(vnfc), "configurationId");
652 public void setServiceInstanceNameTest() {
653 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
654 WorkflowType resourceType = WorkflowType.SERVICE;
655 InfraActiveRequests request = new InfraActiveRequests();
656 ServiceInstance service = new ServiceInstance();
657 service.setServiceInstanceName("serviceInstanceName");
658 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById(resourceId);
660 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
661 assertEquals("serviceInstanceName", request.getServiceInstanceName());
665 public void setVnfNameTest() {
666 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
667 WorkflowType resourceType = WorkflowType.VNF;
668 InfraActiveRequests request = new InfraActiveRequests();
669 GenericVnf vnf = new GenericVnf();
670 vnf.setVnfName("vnfName");
671 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf(resourceId);
673 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
674 assertEquals("vnfName", request.getVnfName());
678 public void setVfModuleNameTest() {
679 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
680 WorkflowType resourceType = WorkflowType.VFMODULE;
681 InfraActiveRequests request = new InfraActiveRequests();
682 request.setVnfId("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e");
683 VfModule vfModule = new VfModule();
684 vfModule.setVfModuleName("vfModuleName");
685 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e", resourceId);
687 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
688 assertEquals("vfModuleName", request.getVfModuleName());
692 public void setNetworkNameTest() {
693 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
694 WorkflowType resourceType = WorkflowType.NETWORK;
695 InfraActiveRequests request = new InfraActiveRequests();
696 L3Network network = new L3Network();
697 network.setNetworkName("networkName");
698 doReturn(network).when(bbSetupUtils).getAAIL3Network(resourceId);
700 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
701 assertEquals("networkName", request.getNetworkName());
705 public void setConfigurationNameTest() {
706 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
707 WorkflowType resourceType = WorkflowType.CONFIGURATION;
708 InfraActiveRequests request = new InfraActiveRequests();
709 Configuration configuration = new Configuration();
710 configuration.setConfigurationName("configurationName");
711 doReturn(configuration).when(bbSetupUtils).getAAIConfiguration(resourceId);
713 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
714 assertEquals("configurationName", request.getConfigurationName());
718 public void setInstanceGroupNameTest() {
719 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
720 WorkflowType resourceType = WorkflowType.INSTANCE_GROUP;
721 InfraActiveRequests request = new InfraActiveRequests();
722 InstanceGroup instanceGroup = new InstanceGroup();
723 instanceGroup.setInstanceGroupName("instanceGroupName");
724 doReturn(instanceGroup).when(bbSetupUtils).getAAIInstanceGroup(resourceId);
726 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
727 assertEquals("instanceGroupName", request.getInstanceGroupName());
731 public void setVolumeGroupNameTest() {
732 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
733 WorkflowType resourceType = WorkflowType.VOLUMEGROUP;
734 InfraActiveRequests request = new InfraActiveRequests();
735 request.setVnfId("4aa72c90-21eb-4465-8847-997e27af6c3e");
736 VolumeGroup volumeGroup = new VolumeGroup();
737 volumeGroup.setVolumeGroupName("volumeGroupName");
738 Optional<VolumeGroup> returnVolumeGroup = Optional.of(volumeGroup);
740 doReturn(returnVolumeGroup).when(bbSetupUtils).getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
741 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
743 assertEquals("volumeGroupName", request.getVolumeGroupName());
746 private void prepareDelegateExecution() {
747 execution.setVariable("mso-request-id", SAMPLE_MSO_REQUEST_ID);
748 execution.setVariable("requestAction", SAMPLE_REQUEST_ACTION);
749 execution.setVariable("gCurrentSequence", SAMPLE_SEQUENCE);
750 execution.setVariable("homing", false);
751 execution.setVariable("calledHoming", false);