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 static org.assertj.core.api.Assertions.assertThat;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertTrue;
29 import static org.mockito.ArgumentMatchers.any;
30 import static org.mockito.ArgumentMatchers.anyObject;
31 import static org.mockito.ArgumentMatchers.anyString;
32 import static org.mockito.ArgumentMatchers.isA;
33 import static org.mockito.Mockito.doNothing;
34 import static org.mockito.Mockito.doReturn;
35 import static org.mockito.Mockito.times;
36 import static org.mockito.Mockito.verify;
37 import static org.mockito.Mockito.when;
38 import java.util.ArrayList;
39 import java.util.List;
40 import java.util.Optional;
41 import org.camunda.bpm.engine.delegate.BpmnError;
42 import org.camunda.bpm.engine.delegate.DelegateExecution;
43 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
44 import org.junit.Before;
45 import org.junit.Rule;
46 import org.junit.Test;
47 import org.junit.rules.ExpectedException;
48 import org.mockito.ArgumentCaptor;
49 import org.mockito.InjectMocks;
50 import org.mockito.Mock;
51 import org.mockito.Mockito;
52 import org.mockito.Spy;
53 import org.onap.aai.domain.yang.Configuration;
54 import org.onap.aai.domain.yang.GenericVnf;
55 import org.onap.aai.domain.yang.InstanceGroup;
56 import org.onap.aai.domain.yang.L3Network;
57 import org.onap.aai.domain.yang.ServiceInstance;
58 import org.onap.aai.domain.yang.VfModule;
59 import org.onap.aai.domain.yang.VolumeGroup;
60 import org.onap.so.bpmn.BaseTaskTest;
61 import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner;
62 import org.onap.so.bpmn.core.WorkflowException;
63 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
64 import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
65 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
66 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
67 import org.onap.so.db.catalog.beans.ConfigurationResource;
68 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
69 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
70 import org.onap.so.db.request.beans.InfraActiveRequests;
71 import org.onap.so.serviceinstancebeans.ModelInfo;
72 import org.onap.so.serviceinstancebeans.ModelType;
73 import org.onap.so.serviceinstancebeans.RelatedInstance;
74 import org.onap.so.serviceinstancebeans.RelatedInstanceList;
75 import org.onap.so.serviceinstancebeans.RequestDetails;
76 import org.springframework.core.env.Environment;
78 public class WorkflowActionBBTasksTest extends BaseTaskTest {
80 private static final String SAMPLE_MSO_REQUEST_ID = "00f704ca-c5e5-4f95-a72c-6889db7b0688";
81 private static final String SAMPLE_REQUEST_ACTION = "Delete-Network-Collection";
82 private static final int SAMPLE_SEQUENCE = 0;
83 private static final String EMPTY_STRING = "";
85 protected WorkflowAction workflowAction;
88 protected WorkflowActionBBFailure workflowActionBBFailure;
92 protected WorkflowActionBBTasks workflowActionBBTasks;
95 InfraActiveRequests reqMock;
97 private DelegateExecution execution;
100 protected Environment environment;
103 private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
106 public ExpectedException thrown = ExpectedException.none();
109 private DelegateExecution mockExecution;
112 public void before() throws Exception {
113 execution = new DelegateExecutionFake();
114 ServiceInstance servInstance = new ServiceInstance();
115 servInstance.setServiceInstanceId("TEST");
116 when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance);
117 workflowAction.setBbInputSetupUtils(bbSetupUtils);
118 workflowAction.setBbInputSetup(bbInputSetup);
122 public void selectBBTest() {
123 String vnfCustomizationUUID = "1234567";
124 String modelUuid = "1234567";
125 prepareDelegateExecution();
126 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
128 BuildingBlock buildingBlock =
129 new BuildingBlock().setBpmnFlowName("ConfigAssignVnfBB").setKey(vnfCustomizationUUID);
130 RequestDetails rd = new RequestDetails();
131 ModelInfo mi = new ModelInfo();
132 mi.setModelUuid(modelUuid);
134 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
135 flowsToExecute.add(ebb);
137 List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
138 VnfResourceCustomization vrc = new VnfResourceCustomization();
139 vrc.setSkipPostInstConf(false);
140 vrc.setModelCustomizationUUID(vnfCustomizationUUID);
141 vnfResourceCustomizations.add(vrc);
142 GenericVnf genericVnf = new GenericVnf();
143 genericVnf.setModelCustomizationId(vnfCustomizationUUID);
144 doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
145 doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
146 vnfResourceCustomizations);
148 execution.setVariable("flowsToExecute", flowsToExecute);
149 workflowActionBBTasks.selectBB(execution);
150 boolean success = (boolean) execution.getVariable("completed");
151 int currentSequence = (int) execution.getVariable("gCurrentSequence");
152 assertFalse(success);
153 assertEquals(1, currentSequence);
157 public void select2BBTest() {
158 String vnfCustomizationUUID = "1234567";
159 String modelUuid = "1234567";
161 prepareDelegateExecution();
162 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
163 BuildingBlock buildingBlock =
164 new BuildingBlock().setBpmnFlowName("ConfigDeployVnfBB").setKey(vnfCustomizationUUID);
165 RequestDetails rd = new RequestDetails();
166 ModelInfo mi = new ModelInfo();
167 mi.setModelUuid(modelUuid);
169 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
170 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
172 flowsToExecute.add(ebb);
174 List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
175 VnfResourceCustomization vrc = new VnfResourceCustomization();
177 vrc.setSkipPostInstConf(false);
178 vrc.setModelCustomizationUUID(vnfCustomizationUUID);
179 vnfResourceCustomizations.add(vrc);
180 GenericVnf genericVnf = new GenericVnf();
181 genericVnf.setModelCustomizationId(vnfCustomizationUUID);
183 doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
184 doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
185 vnfResourceCustomizations);
187 flowsToExecute.add(ebb2);
188 execution.setVariable("flowsToExecute", flowsToExecute);
189 workflowActionBBTasks.selectBB(execution);
190 boolean success = (boolean) execution.getVariable("completed");
191 int currentSequence = (int) execution.getVariable("gCurrentSequence");
192 assertFalse(success);
193 assertEquals(1, currentSequence);
197 public void updateRequestStatusToCompleteTest() {
198 String reqId = "reqId123";
199 execution.setVariable("mso-request-id", reqId);
200 execution.setVariable("requestAction", "createInstance");
201 execution.setVariable("resourceName", "Service");
202 execution.setVariable("aLaCarte", true);
203 InfraActiveRequests req = new InfraActiveRequests();
204 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
205 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
206 workflowActionBBTasks.updateRequestStatusToComplete(execution);
207 assertEquals("ALaCarte-Service-createInstance request was executed correctly.",
208 execution.getVariable("finalStatusMessage"));
212 public void rollbackExecutionPathTest() {
213 execution.setVariable("handlingCode", "Rollback");
214 execution.setVariable("isRollback", false);
215 execution.setVariable("requestAction", EMPTY_STRING);
216 execution.setVariable("resourceName", EMPTY_STRING);
217 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
218 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
219 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
220 flowsToExecute.add(ebb1);
222 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
223 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
224 flowsToExecute.add(ebb2);
226 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
227 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
228 flowsToExecute.add(ebb3);
230 execution.setVariable("flowsToExecute", flowsToExecute);
231 execution.setVariable("gCurrentSequence", 3);
232 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
234 workflowActionBBTasks.rollbackExecutionPath(execution);
235 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
236 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeactivateVfModuleBB");
237 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
238 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
239 assertEquals(0, execution.getVariable("gCurrentSequence"));
243 public void rollbackExecutionPathUnfinishedFlowTest() {
244 execution.setVariable("handlingCode", "Rollback");
245 execution.setVariable("isRollback", false);
246 execution.setVariable("requestAction", EMPTY_STRING);
247 execution.setVariable("resourceName", EMPTY_STRING);
248 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
249 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
250 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
251 flowsToExecute.add(ebb1);
253 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
254 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
255 flowsToExecute.add(ebb2);
257 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
258 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
259 flowsToExecute.add(ebb3);
261 execution.setVariable("flowsToExecute", flowsToExecute);
262 execution.setVariable("gCurrentSequence", 2);
263 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
265 workflowActionBBTasks.rollbackExecutionPath(execution);
266 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
267 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
268 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
269 assertEquals(0, execution.getVariable("gCurrentSequence"));
270 assertEquals(0, execution.getVariable("retryCount"));
274 public void rollbackExecutionTest() {
275 execution.setVariable("handlingCode", "Rollback");
276 execution.setVariable("isRollback", false);
277 execution.setVariable("requestAction", EMPTY_STRING);
278 execution.setVariable("resourceName", EMPTY_STRING);
279 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
280 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB");
281 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
282 flowsToExecute.add(ebb1);
284 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateNetworkCollectionBB");
285 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
286 flowsToExecute.add(ebb2);
288 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("AssignNetworkBB");
289 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
290 flowsToExecute.add(ebb3);
292 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("CreateNetworkBB");
293 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
294 flowsToExecute.add(ebb4);
296 execution.setVariable("flowsToExecute", flowsToExecute);
297 execution.setVariable("gCurrentSequence", 3);
298 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
300 workflowActionBBTasks.rollbackExecutionPath(execution);
301 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
302 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "UnassignNetworkBB");
303 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteNetworkCollectionBB");
304 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignServiceInstanceBB");
305 assertEquals(0, execution.getVariable("gCurrentSequence"));
309 public void rollbackExecutionRollbackToAssignedTest() {
310 execution.setVariable("isRollback", false);
311 execution.setVariable("handlingCode", "RollbackToAssigned");
312 execution.setVariable("requestAction", EMPTY_STRING);
313 execution.setVariable("resourceName", EMPTY_STRING);
314 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
316 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
317 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
318 flowsToExecute.add(ebb1);
320 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
321 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
322 flowsToExecute.add(ebb2);
324 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
325 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
326 flowsToExecute.add(ebb3);
328 execution.setVariable("flowsToExecute", flowsToExecute);
329 execution.setVariable("gCurrentSequence", 2);
331 workflowActionBBTasks.rollbackExecutionPath(execution);
332 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
333 assertEquals("DeleteVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
334 assertEquals(0, execution.getVariable("gCurrentSequence"));
335 assertEquals(1, ebbs.size());
339 public void rollbackExecutionPathChangeBBForReplaceVFModuleTest() {
340 execution.setVariable("handlingCode", "Rollback");
341 execution.setVariable("isRollback", false);
342 execution.setVariable("requestAction", "replaceInstance");
343 execution.setVariable("resourceName", "VfModule");
344 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
345 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
346 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
347 flowsToExecute.add(ebb1);
349 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
350 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
351 flowsToExecute.add(ebb2);
353 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
354 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
355 flowsToExecute.add(ebb3);
358 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("ChangeModelVnfBB");
359 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
360 flowsToExecute.add(ebb4);
362 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("ChangeModelServiceInstanceBB");
363 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
364 flowsToExecute.add(ebb5);
366 execution.setVariable("flowsToExecute", flowsToExecute);
367 execution.setVariable("gCurrentSequence", 5);
368 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
370 workflowActionBBTasks.rollbackExecutionPath(execution);
371 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
372 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "ChangeModelVnfBB");
373 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "ChangeModelServiceInstanceBB");
374 assertEquals(0, execution.getVariable("gCurrentSequence"));
378 public void rollbackExecutionRollbackToAssignedWithFabricTest() {
379 execution.setVariable("isRollback", false);
380 execution.setVariable("handlingCode", "RollbackToAssigned");
381 execution.setVariable("requestAction", EMPTY_STRING);
382 execution.setVariable("resourceName", EMPTY_STRING);
383 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
385 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
386 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
387 flowsToExecute.add(ebb1);
389 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
390 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
391 flowsToExecute.add(ebb2);
393 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
394 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
395 flowsToExecute.add(ebb3);
397 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
398 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
399 flowsToExecute.add(ebb4);
401 execution.setVariable("flowsToExecute", flowsToExecute);
402 execution.setVariable("gCurrentSequence", 4);
404 workflowActionBBTasks.rollbackExecutionPath(execution);
405 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
406 assertEquals(0, execution.getVariable("gCurrentSequence"));
407 assertEquals(3, ebbs.size());
408 assertEquals("DeleteFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
409 assertEquals("DeactivateVfModuleBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
410 assertEquals("DeleteVfModuleBB", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
415 public void rollbackExecutionRollbackToCreatedWithFabricTest() {
416 execution.setVariable("isRollback", false);
417 execution.setVariable("handlingCode", "RollbackToCreated");
418 execution.setVariable("requestAction", EMPTY_STRING);
419 execution.setVariable("resourceName", EMPTY_STRING);
420 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
422 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
423 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
424 flowsToExecute.add(ebb1);
426 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
427 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
428 flowsToExecute.add(ebb2);
430 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
431 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
432 flowsToExecute.add(ebb3);
434 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
435 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
436 flowsToExecute.add(ebb4);
438 execution.setVariable("flowsToExecute", flowsToExecute);
439 execution.setVariable("gCurrentSequence", 4);
441 workflowActionBBTasks.rollbackExecutionPath(execution);
442 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
443 assertEquals(0, execution.getVariable("gCurrentSequence"));
444 assertEquals(2, ebbs.size());
445 assertEquals("DeleteFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
446 assertEquals("DeactivateVfModuleBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
451 public void rollbackExecutionRollbackToCreatedNoConfigurationWithFabricTest() {
452 execution.setVariable("isRollback", false);
453 execution.setVariable("handlingCode", "RollbackToCreatedNoConfiguration");
454 execution.setVariable("requestAction", EMPTY_STRING);
455 execution.setVariable("resourceName", EMPTY_STRING);
456 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
458 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
459 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
460 flowsToExecute.add(ebb1);
462 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
463 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
464 flowsToExecute.add(ebb2);
466 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
467 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
468 flowsToExecute.add(ebb3);
470 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
471 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
472 flowsToExecute.add(ebb4);
474 execution.setVariable("flowsToExecute", flowsToExecute);
475 execution.setVariable("gCurrentSequence", 4);
477 workflowActionBBTasks.rollbackExecutionPath(execution);
478 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
479 assertEquals(0, execution.getVariable("gCurrentSequence"));
480 assertEquals(1, ebbs.size());
481 assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
485 public void rollbackExecutionRollbackToCreatedTest() {
486 execution.setVariable("isRollback", false);
487 execution.setVariable("handlingCode", "RollbackToCreated");
488 execution.setVariable("requestAction", EMPTY_STRING);
489 execution.setVariable("resourceName", EMPTY_STRING);
490 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
491 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
492 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
493 flowsToExecute.add(ebb1);
495 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
496 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
497 flowsToExecute.add(ebb2);
499 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
500 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
501 flowsToExecute.add(ebb3);
503 execution.setVariable("flowsToExecute", flowsToExecute);
504 execution.setVariable("gCurrentSequence", 3);
506 workflowActionBBTasks.rollbackExecutionPath(execution);
507 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
508 assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
509 assertEquals(0, execution.getVariable("gCurrentSequence"));
510 assertEquals(1, ebbs.size());
514 public void rollbackExecutionRollbackInPlaceSoftwareUpdateTest() {
515 execution.setVariable("isRollback", false);
516 execution.setVariable("handlingCode", "Rollback");
517 execution.setVariable("requestAction", EMPTY_STRING);
518 execution.setVariable("resourceName", EMPTY_STRING);
519 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
520 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
521 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
522 flowsToExecute.add(ebb1);
524 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
525 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
526 flowsToExecute.add(ebb2);
528 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
529 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
530 flowsToExecute.add(ebb3);
532 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
533 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
534 flowsToExecute.add(ebb4);
536 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
537 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
538 flowsToExecute.add(ebb5);
540 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFLockActivity");
541 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
542 flowsToExecute.add(ebb6);
544 BuildingBlock buildingBlock7 = new BuildingBlock().setBpmnFlowName("VNFUpgradePreCheckActivity");
545 ExecuteBuildingBlock ebb7 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock7);
546 flowsToExecute.add(ebb7);
548 BuildingBlock buildingBlock8 = new BuildingBlock().setBpmnFlowName("VNFQuiesceTrafficActivity");
549 ExecuteBuildingBlock ebb8 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock8);
550 flowsToExecute.add(ebb8);
552 BuildingBlock buildingBlock9 = new BuildingBlock().setBpmnFlowName("VNFStopActivity");
553 ExecuteBuildingBlock ebb9 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock9);
554 flowsToExecute.add(ebb9);
556 BuildingBlock buildingBlock10 = new BuildingBlock().setBpmnFlowName("VNFSnapShotActivity");
557 ExecuteBuildingBlock ebb10 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock10);
558 flowsToExecute.add(ebb10);
560 execution.setVariable("flowsToExecute", flowsToExecute);
561 execution.setVariable("gCurrentSequence", 10);
563 workflowActionBBTasks.rollbackExecutionPath(execution);
564 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
565 assertEquals("VNFStartActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
566 assertEquals("VNFResumeTrafficActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
567 assertEquals("VNFUnlockActivity", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
568 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(3).getBuildingBlock().getBpmnFlowName());
569 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(4).getBuildingBlock().getBpmnFlowName());
570 assertEquals(0, execution.getVariable("gCurrentSequence"));
571 assertEquals(5, ebbs.size());
575 public void rollbackExecutionRollbackConfigModifyTest() {
576 execution.setVariable("isRollback", false);
577 execution.setVariable("handlingCode", "Rollback");
578 execution.setVariable("requestAction", EMPTY_STRING);
579 execution.setVariable("resourceName", EMPTY_STRING);
580 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
581 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
582 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
583 flowsToExecute.add(ebb1);
585 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
586 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
587 flowsToExecute.add(ebb2);
589 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
590 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
591 flowsToExecute.add(ebb3);
593 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
594 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
595 flowsToExecute.add(ebb4);
597 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
598 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
599 flowsToExecute.add(ebb5);
601 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFHealthCheckActivity");
602 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
603 flowsToExecute.add(ebb6);
605 execution.setVariable("flowsToExecute", flowsToExecute);
606 execution.setVariable("gCurrentSequence", 6);
608 workflowActionBBTasks.rollbackExecutionPath(execution);
609 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
610 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
611 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
612 assertEquals(0, execution.getVariable("gCurrentSequence"));
613 assertEquals(2, ebbs.size());
617 public void postProcessingExecuteBBActivateVfModuleNotReplaceInstanceTest() throws CloneNotSupportedException {
618 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
619 workflowResourceIds.setServiceInstanceId("1");
620 workflowResourceIds.setVnfId("1");
622 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
623 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
624 ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
625 ebbActivateVfModule.setResourceId("1");
627 ServiceInstance service = new ServiceInstance();
628 service.setServiceInstanceName("name");
629 service.setModelVersionId("1");
630 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
632 GenericVnf vnf = new GenericVnf();
633 vnf.setVnfName("name");
634 vnf.setModelCustomizationId("1");
635 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
637 VfModule vfModule = new VfModule();
638 vfModule.setVfModuleName("name");
639 vfModule.setModelCustomizationId("1");
640 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
642 List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
643 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
644 vnfc.setModelInvariantId("1");
645 vnfc.setVnfcName("name");
646 vnfc.setModelCustomizationId("2");
648 doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
650 CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
651 ConfigurationResource configuration = new ConfigurationResource();
652 configuration.setToscaNodeType("FabricConfiguration");
653 configuration.setModelUUID("1");
654 vfModuleCustomization.setConfigurationResource(configuration);
656 doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
658 prepareDelegateExecution();
659 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
660 flowsToExecute.add(ebbActivateVfModule);
662 execution.setVariable("requestAction", "createInstance");
663 execution.setVariable("completed", true);
665 ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
666 ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
667 ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
668 workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
669 verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
670 bbCaptor.capture(), listCaptor.capture());
671 assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
672 assertEquals(2, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
674 ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
675 .getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys()
676 .getCvnfcCustomizationUUID());
677 assertEquals("AddFabricConfigurationBB", ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues()
678 .get(0).getVariable("flowsToExecute")).get(1)).getBuildingBlock().getBpmnFlowName());
682 public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasConfigurationTest()
683 throws CloneNotSupportedException {
684 RequestDetails reqDetails = new RequestDetails();
685 RelatedInstanceList[] list = new RelatedInstanceList[2];
686 RelatedInstanceList vnfList = new RelatedInstanceList();
687 RelatedInstanceList serviceList = new RelatedInstanceList();
689 list[1] = serviceList;
690 RelatedInstance vnfInstance = new RelatedInstance();
691 RelatedInstance serviceInstance = new RelatedInstance();
692 ModelInfo vnfModelInfo = new ModelInfo();
693 vnfModelInfo.setModelType(ModelType.vnf);
694 vnfModelInfo.setModelCustomizationId("1");
695 ModelInfo serviceModelInfo = new ModelInfo();
696 serviceModelInfo.setModelType(ModelType.service);
697 serviceModelInfo.setModelVersionId("1");
698 vnfInstance.setModelInfo(vnfModelInfo);
699 serviceInstance.setModelInfo(serviceModelInfo);
700 reqDetails.setRelatedInstanceList(list);
701 vnfList.setRelatedInstance(vnfInstance);
702 serviceList.setRelatedInstance(serviceInstance);
703 ModelInfo vfModuleInfo = new ModelInfo();
704 vfModuleInfo.setModelCustomizationId("1");
705 reqDetails.setModelInfo(vfModuleInfo);
706 BuildingBlock bbAddFabric = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
707 ExecuteBuildingBlock ebbAddFabric = new ExecuteBuildingBlock().setBuildingBlock(bbAddFabric);
708 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
709 workflowResourceIds.setServiceInstanceId("1");
710 workflowResourceIds.setVnfId("1");
711 ebbAddFabric.setWorkflowResourceIds(workflowResourceIds);
712 ebbAddFabric.setResourceId("1");
714 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
715 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
716 ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
717 ebbActivateVfModule.setResourceId("1");
718 ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
719 ebbAddFabric.setConfigurationResourceKeys(configurationResourceKeys);
720 ebbActivateVfModule.setRequestDetails(reqDetails);
722 ServiceInstance service = new ServiceInstance();
723 service.setServiceInstanceName("name");
724 service.setModelVersionId("1");
725 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
727 GenericVnf vnf = new GenericVnf();
728 vnf.setVnfName("name");
729 vnf.setModelCustomizationId("1");
730 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
732 VfModule vfModule = new VfModule();
733 vfModule.setVfModuleName("name");
734 vfModule.setModelCustomizationId("1");
735 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
737 List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
738 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
739 vnfc.setModelInvariantId("1");
740 vnfc.setVnfcName("name");
741 vnfc.setModelCustomizationId("2");
743 doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
745 CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
746 ConfigurationResource configuration = new ConfigurationResource();
747 configuration.setToscaNodeType("FabricConfiguration");
748 configuration.setModelUUID("1");
749 vfModuleCustomization.setConfigurationResource(configuration);
751 doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
753 prepareDelegateExecution();
754 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
755 flowsToExecute.add(ebbActivateVfModule);
757 ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
758 ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
759 ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
761 execution.setVariable("requestAction", "replaceInstance");
762 execution.setVariable("completed", true);
763 workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
764 verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
765 bbCaptor.capture(), listCaptor.capture());
766 assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
767 assertEquals(2, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
769 ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
770 .getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys()
771 .getCvnfcCustomizationUUID());
775 public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasNoConfigurationTest()
776 throws CloneNotSupportedException {
778 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
779 workflowResourceIds.setServiceInstanceId("1");
780 workflowResourceIds.setVnfId("1");
782 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
783 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
784 ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
785 ebbActivateVfModule.setResourceId("1");
787 ServiceInstance service = new ServiceInstance();
788 service.setServiceInstanceName("name");
789 service.setModelVersionId("1");
790 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
792 GenericVnf vnf = new GenericVnf();
793 vnf.setVnfName("name");
794 vnf.setModelCustomizationId("1");
795 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
797 VfModule vfModule = new VfModule();
798 vfModule.setVfModuleName("name");
799 vfModule.setModelCustomizationId("1");
800 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
802 List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
803 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
804 vnfc.setModelInvariantId("1");
805 vnfc.setVnfcName("name");
806 vnfc.setModelCustomizationId("2");
808 doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
810 CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
811 ConfigurationResource configuration = new ConfigurationResource();
812 configuration.setToscaNodeType("FabricConfiguration");
813 configuration.setModelUUID("1");
814 vfModuleCustomization.setConfigurationResource(configuration);
816 doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
818 prepareDelegateExecution();
819 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
820 flowsToExecute.add(ebbActivateVfModule);
822 ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
823 ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
824 ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
826 execution.setVariable("requestAction", "replaceInstance");
827 execution.setVariable("completed", true);
829 workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
830 verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
831 bbCaptor.capture(), listCaptor.capture());
832 assertEquals(true, executionCaptor.getAllValues().get(0).getVariable("completed"));
838 public void getExecuteBBForConfigTest() throws CloneNotSupportedException {
839 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
840 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
842 WorkflowResourceIds resourceIdsActivateVfModule = new WorkflowResourceIds();
843 resourceIdsActivateVfModule.setServiceInstanceId("test-service-inbstance-id");
844 resourceIdsActivateVfModule.setVnfId("test-vnf-id");
845 resourceIdsActivateVfModule.setVfModuleId("test-vf-module-id");
846 resourceIdsActivateVfModule.setConfigurationId("");
848 RequestDetails requestDetails = new RequestDetails();
850 ebbActivateVfModule.setApiVersion("7");
851 ebbActivateVfModule.setaLaCarte(true);
852 ebbActivateVfModule.setRequestAction("createInstance");
853 ebbActivateVfModule.setVnfType("test-vnf-type");
854 ebbActivateVfModule.setRequestId("f6c00ae2-a205-4cbd-b055-02e553efde12");
855 ebbActivateVfModule.setRequestDetails(requestDetails);
856 ebbActivateVfModule.setWorkflowResourceIds(resourceIdsActivateVfModule);
858 ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
859 configurationResourceKeys.setCvnfcCustomizationUUID("07d64cd2-4427-4156-b11d-d14b96b3e4cb");
860 configurationResourceKeys.setVfModuleCustomizationUUID("50b61075-6ebb-4aab-a9fc-bedad9a2aa76");
861 configurationResourceKeys.setVnfResourceCustomizationUUID("a1d0e36e-34a9-431b-b5ba-4bbb72f63c7c");
862 configurationResourceKeys.setVnfcName("rdm54bvbgw5001vm018pim001");
864 ExecuteBuildingBlock ebbAddFabricConfig =
865 workflowActionBBTasks.getExecuteBBForConfig("AddFabricConfigurationBB", ebbActivateVfModule,
866 "cc7e12f9-967c-4362-8d14-e5b2bf0608a4", configurationResourceKeys);
868 assertEquals("7", ebbAddFabricConfig.getApiVersion());
869 assertTrue(ebbAddFabricConfig.isaLaCarte());
870 assertEquals("createInstance", ebbAddFabricConfig.getRequestAction());
871 assertEquals("test-vnf-type", ebbAddFabricConfig.getVnfType());
872 assertEquals("f6c00ae2-a205-4cbd-b055-02e553efde12", ebbAddFabricConfig.getRequestId());
873 assertEquals(requestDetails, ebbAddFabricConfig.getRequestDetails());
874 assertEquals("cc7e12f9-967c-4362-8d14-e5b2bf0608a4",
875 ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId());
876 assertEquals("test-service-inbstance-id", ebbAddFabricConfig.getWorkflowResourceIds().getServiceInstanceId());
877 assertEquals("test-vnf-id", ebbAddFabricConfig.getWorkflowResourceIds().getVnfId());
878 assertEquals("test-vf-module-id", ebbAddFabricConfig.getWorkflowResourceIds().getVfModuleId());
880 assertThat(ebbAddFabricConfig.getConfigurationResourceKeys()).isEqualTo(configurationResourceKeys);
881 assertThat(ebbAddFabricConfig.getWorkflowResourceIds())
882 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds());
883 assertThat(ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId())
884 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds().getConfigurationId());
888 public void checkRetryStatusTest() {
889 String reqId = "reqId123";
890 execution.setVariable("mso-request-id", reqId);
891 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
892 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
893 execution.setVariable("handlingCode", "Retry");
894 execution.setVariable("retryCount", 1);
895 execution.setVariable("gCurrentSequence", 1);
896 InfraActiveRequests req = new InfraActiveRequests();
897 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
898 workflowActionBBTasks.checkRetryStatus(execution);
899 assertEquals(0, execution.getVariable("gCurrentSequence"));
903 public void checkRetryStatusTestExceededMaxRetries() {
904 String reqId = "reqId123";
905 execution.setVariable("mso-request-id", reqId);
906 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
907 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
908 execution.setVariable("handlingCode", "Retry");
909 execution.setVariable("retryCount", 6);
910 execution.setVariable("gCurrentSequence", 1);
911 InfraActiveRequests req = new InfraActiveRequests();
912 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
914 workflowActionBBTasks.checkRetryStatus(execution);
915 } catch (BpmnError e) {
916 WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException");
917 assertEquals("Exceeded maximum retries. Ending flow with status Abort", exception.getErrorMessage());
922 public void checkRetryStatusNoRetryTest() {
923 String reqId = "reqId123";
924 execution.setVariable("mso-request-id", reqId);
925 execution.setVariable("retryCount", 3);
926 execution.setVariable("handlingCode", "Success");
927 execution.setVariable("gCurrentSequence", 1);
928 InfraActiveRequests req = new InfraActiveRequests();
929 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
930 workflowActionBBTasks.checkRetryStatus(execution);
931 assertEquals(0, execution.getVariable("retryCount"));
935 public void updateInstanceId() {
936 String reqId = "req123";
937 String instanceId = "123123123";
938 execution.setVariable("mso-request-id", reqId);
939 execution.setVariable("resourceId", instanceId);
940 execution.setVariable("resourceType", WorkflowType.SERVICE);
941 doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
942 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
943 workflowActionBBTasks.updateInstanceId(execution);
944 Mockito.verify(reqMock, Mockito.times(1)).setServiceInstanceId(instanceId);
948 public void getConfigurationId() throws Exception {
949 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
950 vnfc.setModelInvariantId("modelInvariantId");
951 vnfc.setVnfcName("testVnfcName");
952 List<Configuration> configurations = new ArrayList<>();
953 org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
954 configuration.setConfigurationId("configurationId");
955 configuration.setModelCustomizationId("modelCustimizationId");
956 configuration.setConfigurationName("testConfigurationName");
957 configurations.add(configuration);
958 doReturn(configurations.get(0).getConfigurationId()).when(workflowActionBBTasks).getConfigurationId(vnfc);
959 assertEquals(workflowActionBBTasks.getConfigurationId(vnfc), "configurationId");
963 public void setServiceInstanceNameTest() {
964 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
965 WorkflowType resourceType = WorkflowType.SERVICE;
966 InfraActiveRequests request = new InfraActiveRequests();
967 ServiceInstance service = new ServiceInstance();
968 service.setServiceInstanceName("serviceInstanceName");
969 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById(resourceId);
971 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
972 assertEquals("serviceInstanceName", request.getServiceInstanceName());
976 public void setVnfNameTest() {
977 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
978 WorkflowType resourceType = WorkflowType.VNF;
979 InfraActiveRequests request = new InfraActiveRequests();
980 GenericVnf vnf = new GenericVnf();
981 vnf.setVnfName("vnfName");
982 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf(resourceId);
984 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
985 assertEquals("vnfName", request.getVnfName());
989 public void setVfModuleNameTest() {
990 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
991 WorkflowType resourceType = WorkflowType.VFMODULE;
992 InfraActiveRequests request = new InfraActiveRequests();
993 request.setVnfId("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e");
994 VfModule vfModule = new VfModule();
995 vfModule.setVfModuleName("vfModuleName");
996 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e", resourceId);
998 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
999 assertEquals("vfModuleName", request.getVfModuleName());
1003 public void setNetworkNameTest() {
1004 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1005 WorkflowType resourceType = WorkflowType.NETWORK;
1006 InfraActiveRequests request = new InfraActiveRequests();
1007 L3Network network = new L3Network();
1008 network.setNetworkName("networkName");
1009 doReturn(network).when(bbSetupUtils).getAAIL3Network(resourceId);
1011 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1012 assertEquals("networkName", request.getNetworkName());
1016 public void setConfigurationNameTest() {
1017 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1018 WorkflowType resourceType = WorkflowType.CONFIGURATION;
1019 InfraActiveRequests request = new InfraActiveRequests();
1020 Configuration configuration = new Configuration();
1021 configuration.setConfigurationName("configurationName");
1022 doReturn(configuration).when(bbSetupUtils).getAAIConfiguration(resourceId);
1024 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1025 assertEquals("configurationName", request.getConfigurationName());
1029 public void setInstanceGroupNameTest() {
1030 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1031 WorkflowType resourceType = WorkflowType.INSTANCE_GROUP;
1032 InfraActiveRequests request = new InfraActiveRequests();
1033 InstanceGroup instanceGroup = new InstanceGroup();
1034 instanceGroup.setInstanceGroupName("instanceGroupName");
1035 doReturn(instanceGroup).when(bbSetupUtils).getAAIInstanceGroup(resourceId);
1037 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1038 assertEquals("instanceGroupName", request.getInstanceGroupName());
1042 public void setVolumeGroupNameTest() {
1043 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1044 WorkflowType resourceType = WorkflowType.VOLUMEGROUP;
1045 InfraActiveRequests request = new InfraActiveRequests();
1046 request.setVnfId("4aa72c90-21eb-4465-8847-997e27af6c3e");
1047 VolumeGroup volumeGroup = new VolumeGroup();
1048 volumeGroup.setVolumeGroupName("volumeGroupName");
1049 Optional<VolumeGroup> returnVolumeGroup = Optional.of(volumeGroup);
1051 doReturn(returnVolumeGroup).when(bbSetupUtils).getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
1052 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1054 assertEquals("volumeGroupName", request.getVolumeGroupName());
1057 private void prepareDelegateExecution() {
1058 execution.setVariable("mso-request-id", SAMPLE_MSO_REQUEST_ID);
1059 execution.setVariable("requestAction", SAMPLE_REQUEST_ACTION);
1060 execution.setVariable("gCurrentSequence", SAMPLE_SEQUENCE);
1061 execution.setVariable("homing", false);
1062 execution.setVariable("calledHoming", false);