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.ArgumentCaptor;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mock;
35 import org.mockito.Mockito;
36 import org.mockito.Spy;
37 import org.onap.aai.domain.yang.Configuration;
38 import org.onap.aai.domain.yang.GenericVnf;
39 import org.onap.aai.domain.yang.InstanceGroup;
40 import org.onap.aai.domain.yang.L3Network;
41 import org.onap.aai.domain.yang.ServiceInstance;
42 import org.onap.aai.domain.yang.VfModule;
43 import org.onap.aai.domain.yang.VolumeGroup;
44 import org.onap.so.bpmn.BaseTaskTest;
45 import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner;
46 import org.onap.so.bpmn.core.WorkflowException;
47 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
48 import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
49 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
50 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
51 import org.onap.so.client.namingservice.NamingRequestObject;
52 import org.onap.so.db.catalog.beans.ConfigurationResource;
53 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
54 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
55 import org.onap.so.db.request.beans.InfraActiveRequests;
56 import org.onap.so.serviceinstancebeans.ModelInfo;
57 import org.onap.so.serviceinstancebeans.RequestDetails;
58 import org.springframework.core.env.Environment;
59 import java.util.ArrayList;
60 import java.util.Collections;
61 import java.util.List;
62 import java.util.Optional;
63 import static org.assertj.core.api.Assertions.assertThat;
64 import static org.junit.Assert.assertEquals;
65 import static org.junit.Assert.assertFalse;
66 import static org.junit.Assert.assertTrue;
67 import static org.mockito.ArgumentMatchers.any;
68 import static org.mockito.ArgumentMatchers.anyObject;
69 import static org.mockito.ArgumentMatchers.anyString;
70 import static org.mockito.ArgumentMatchers.isA;
71 import static org.mockito.Mockito.doNothing;
72 import static org.mockito.Mockito.doReturn;
73 import static org.mockito.Mockito.times;
74 import static org.mockito.Mockito.verify;
75 import static org.mockito.Mockito.when;
77 public class WorkflowActionBBTasksTest extends BaseTaskTest {
79 private static final String SAMPLE_MSO_REQUEST_ID = "00f704ca-c5e5-4f95-a72c-6889db7b0688";
80 private static final String SAMPLE_REQUEST_ACTION = "Delete-Network-Collection";
81 private static final int SAMPLE_SEQUENCE = 0;
82 private static final String EMPTY_STRING = "";
84 protected WorkflowAction workflowAction;
87 protected WorkflowActionBBFailure workflowActionBBFailure;
91 protected WorkflowActionBBTasks workflowActionBBTasks;
94 InfraActiveRequests reqMock;
96 private DelegateExecution execution;
99 protected Environment environment;
102 private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
105 public ExpectedException thrown = ExpectedException.none();
108 private DelegateExecution mockExecution;
111 public void before() throws Exception {
112 execution = new DelegateExecutionFake();
113 ServiceInstance servInstance = new ServiceInstance();
114 servInstance.setServiceInstanceId("TEST");
115 when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance);
116 workflowAction.setBbInputSetupUtils(bbSetupUtils);
117 workflowAction.setBbInputSetup(bbInputSetup);
121 public void selectBBTest() {
122 String vnfCustomizationUUID = "1234567";
123 String modelUuid = "1234567";
124 prepareDelegateExecution();
125 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
127 BuildingBlock buildingBlock =
128 new BuildingBlock().setBpmnFlowName("ConfigAssignVnfBB").setKey(vnfCustomizationUUID);
129 RequestDetails rd = new RequestDetails();
130 ModelInfo mi = new ModelInfo();
131 mi.setModelUuid(modelUuid);
133 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
134 flowsToExecute.add(ebb);
136 List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
137 VnfResourceCustomization vrc = new VnfResourceCustomization();
138 vrc.setSkipPostInstConf(false);
139 vrc.setModelCustomizationUUID(vnfCustomizationUUID);
140 vnfResourceCustomizations.add(vrc);
141 GenericVnf genericVnf = new GenericVnf();
142 genericVnf.setModelCustomizationId(vnfCustomizationUUID);
143 doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
144 doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
145 vnfResourceCustomizations);
147 execution.setVariable("flowsToExecute", flowsToExecute);
148 workflowActionBBTasks.selectBB(execution);
149 boolean success = (boolean) execution.getVariable("completed");
150 int currentSequence = (int) execution.getVariable("gCurrentSequence");
152 assertEquals(1, currentSequence);
156 public void select2BBTest() {
157 String vnfCustomizationUUID = "1234567";
158 String modelUuid = "1234567";
160 prepareDelegateExecution();
161 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
162 BuildingBlock buildingBlock =
163 new BuildingBlock().setBpmnFlowName("ConfigDeployVnfBB").setKey(vnfCustomizationUUID);
164 RequestDetails rd = new RequestDetails();
165 ModelInfo mi = new ModelInfo();
166 mi.setModelUuid(modelUuid);
168 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
169 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
171 flowsToExecute.add(ebb);
173 List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
174 VnfResourceCustomization vrc = new VnfResourceCustomization();
176 vrc.setSkipPostInstConf(false);
177 vrc.setModelCustomizationUUID(vnfCustomizationUUID);
178 vnfResourceCustomizations.add(vrc);
179 GenericVnf genericVnf = new GenericVnf();
180 genericVnf.setModelCustomizationId(vnfCustomizationUUID);
182 doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
183 doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
184 vnfResourceCustomizations);
186 flowsToExecute.add(ebb2);
187 execution.setVariable("flowsToExecute", flowsToExecute);
188 workflowActionBBTasks.selectBB(execution);
189 boolean success = (boolean) execution.getVariable("completed");
190 int currentSequence = (int) execution.getVariable("gCurrentSequence");
191 assertFalse(success);
192 assertEquals(1, currentSequence);
196 public void updateRequestStatusToCompleteTest() {
197 String reqId = "reqId123";
198 execution.setVariable("mso-request-id", reqId);
199 execution.setVariable("requestAction", "createInstance");
200 execution.setVariable("resourceName", "Service");
201 execution.setVariable("aLaCarte", true);
202 InfraActiveRequests req = new InfraActiveRequests();
203 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
204 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
205 workflowActionBBTasks.updateRequestStatusToComplete(execution);
206 assertEquals("ALaCarte-Service-createInstance request was executed correctly.",
207 execution.getVariable("finalStatusMessage"));
211 public void rollbackExecutionPathTest() {
212 execution.setVariable("handlingCode", "Rollback");
213 execution.setVariable("isRollback", false);
214 execution.setVariable("requestAction", EMPTY_STRING);
215 execution.setVariable("resourceName", EMPTY_STRING);
216 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
217 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
218 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
219 flowsToExecute.add(ebb1);
221 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
222 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
223 flowsToExecute.add(ebb2);
225 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
226 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
227 flowsToExecute.add(ebb3);
229 execution.setVariable("flowsToExecute", flowsToExecute);
230 execution.setVariable("gCurrentSequence", 3);
231 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
233 workflowActionBBTasks.rollbackExecutionPath(execution);
234 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
235 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeactivateVfModuleBB");
236 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
237 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
238 assertEquals(0, execution.getVariable("gCurrentSequence"));
242 public void rollbackExecutionPathUnfinishedFlowTest() {
243 execution.setVariable("handlingCode", "Rollback");
244 execution.setVariable("isRollback", false);
245 execution.setVariable("requestAction", EMPTY_STRING);
246 execution.setVariable("resourceName", EMPTY_STRING);
247 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
248 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
249 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
250 flowsToExecute.add(ebb1);
252 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
253 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
254 flowsToExecute.add(ebb2);
256 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
257 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
258 flowsToExecute.add(ebb3);
260 execution.setVariable("flowsToExecute", flowsToExecute);
261 execution.setVariable("gCurrentSequence", 2);
262 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
264 workflowActionBBTasks.rollbackExecutionPath(execution);
265 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
266 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
267 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
268 assertEquals(0, execution.getVariable("gCurrentSequence"));
269 assertEquals(0, execution.getVariable("retryCount"));
273 public void rollbackExecutionTest() {
274 execution.setVariable("handlingCode", "Rollback");
275 execution.setVariable("isRollback", false);
276 execution.setVariable("requestAction", EMPTY_STRING);
277 execution.setVariable("resourceName", EMPTY_STRING);
278 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
279 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB");
280 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
281 flowsToExecute.add(ebb1);
283 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateNetworkCollectionBB");
284 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
285 flowsToExecute.add(ebb2);
287 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("AssignNetworkBB");
288 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
289 flowsToExecute.add(ebb3);
291 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("CreateNetworkBB");
292 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
293 flowsToExecute.add(ebb4);
295 execution.setVariable("flowsToExecute", flowsToExecute);
296 execution.setVariable("gCurrentSequence", 3);
297 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
299 workflowActionBBTasks.rollbackExecutionPath(execution);
300 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
301 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "UnassignNetworkBB");
302 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteNetworkCollectionBB");
303 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignServiceInstanceBB");
304 assertEquals(0, execution.getVariable("gCurrentSequence"));
308 public void rollbackExecutionRollbackToAssignedTest() {
309 execution.setVariable("isRollback", false);
310 execution.setVariable("handlingCode", "RollbackToAssigned");
311 execution.setVariable("requestAction", EMPTY_STRING);
312 execution.setVariable("resourceName", EMPTY_STRING);
313 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
315 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
316 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
317 flowsToExecute.add(ebb1);
319 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
320 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
321 flowsToExecute.add(ebb2);
323 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
324 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
325 flowsToExecute.add(ebb3);
327 execution.setVariable("flowsToExecute", flowsToExecute);
328 execution.setVariable("gCurrentSequence", 2);
330 workflowActionBBTasks.rollbackExecutionPath(execution);
331 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
332 assertEquals("DeleteVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
333 assertEquals(0, execution.getVariable("gCurrentSequence"));
334 assertEquals(1, ebbs.size());
338 public void rollbackExecutionPathChangeBBForReplaceVFModuleTest() {
339 execution.setVariable("handlingCode", "Rollback");
340 execution.setVariable("isRollback", false);
341 execution.setVariable("requestAction", "replaceInstance");
342 execution.setVariable("resourceName", "VfModule");
343 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
344 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
345 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
346 flowsToExecute.add(ebb1);
348 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
349 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
350 flowsToExecute.add(ebb2);
352 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
353 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
354 flowsToExecute.add(ebb3);
357 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("ChangeModelVnfBB");
358 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
359 flowsToExecute.add(ebb4);
361 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("ChangeModelServiceInstanceBB");
362 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
363 flowsToExecute.add(ebb5);
365 execution.setVariable("flowsToExecute", flowsToExecute);
366 execution.setVariable("gCurrentSequence", 5);
367 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
369 workflowActionBBTasks.rollbackExecutionPath(execution);
370 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
371 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "ChangeModelVnfBB");
372 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "ChangeModelServiceInstanceBB");
373 assertEquals(0, execution.getVariable("gCurrentSequence"));
377 public void rollbackExecutionRollbackToAssignedWithFabricTest() {
378 execution.setVariable("isRollback", false);
379 execution.setVariable("handlingCode", "RollbackToAssigned");
380 execution.setVariable("requestAction", EMPTY_STRING);
381 execution.setVariable("resourceName", EMPTY_STRING);
382 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
384 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
385 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
386 flowsToExecute.add(ebb1);
388 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
389 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
390 flowsToExecute.add(ebb2);
392 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
393 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
394 flowsToExecute.add(ebb3);
396 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
397 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
398 flowsToExecute.add(ebb4);
400 execution.setVariable("flowsToExecute", flowsToExecute);
401 execution.setVariable("gCurrentSequence", 4);
403 workflowActionBBTasks.rollbackExecutionPath(execution);
404 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
405 assertEquals(0, execution.getVariable("gCurrentSequence"));
406 assertEquals(3, ebbs.size());
407 assertEquals("DeleteFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
408 assertEquals("DeactivateVfModuleBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
409 assertEquals("DeleteVfModuleBB", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
414 public void rollbackExecutionRollbackToCreatedWithFabricTest() {
415 execution.setVariable("isRollback", false);
416 execution.setVariable("handlingCode", "RollbackToCreated");
417 execution.setVariable("requestAction", EMPTY_STRING);
418 execution.setVariable("resourceName", EMPTY_STRING);
419 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
421 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
422 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
423 flowsToExecute.add(ebb1);
425 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
426 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
427 flowsToExecute.add(ebb2);
429 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
430 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
431 flowsToExecute.add(ebb3);
433 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
434 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
435 flowsToExecute.add(ebb4);
437 execution.setVariable("flowsToExecute", flowsToExecute);
438 execution.setVariable("gCurrentSequence", 4);
440 workflowActionBBTasks.rollbackExecutionPath(execution);
441 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
442 assertEquals(0, execution.getVariable("gCurrentSequence"));
443 assertEquals(2, ebbs.size());
444 assertEquals("DeleteFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
445 assertEquals("DeactivateVfModuleBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
450 public void rollbackExecutionRollbackToCreatedNoConfigurationWithFabricTest() {
451 execution.setVariable("isRollback", false);
452 execution.setVariable("handlingCode", "RollbackToCreatedNoConfiguration");
453 execution.setVariable("requestAction", EMPTY_STRING);
454 execution.setVariable("resourceName", EMPTY_STRING);
455 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
457 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
458 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
459 flowsToExecute.add(ebb1);
461 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
462 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
463 flowsToExecute.add(ebb2);
465 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
466 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
467 flowsToExecute.add(ebb3);
469 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
470 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
471 flowsToExecute.add(ebb4);
473 execution.setVariable("flowsToExecute", flowsToExecute);
474 execution.setVariable("gCurrentSequence", 4);
476 workflowActionBBTasks.rollbackExecutionPath(execution);
477 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
478 assertEquals(0, execution.getVariable("gCurrentSequence"));
479 assertEquals(1, ebbs.size());
480 assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
484 public void rollbackExecutionRollbackToCreatedTest() {
485 execution.setVariable("isRollback", false);
486 execution.setVariable("handlingCode", "RollbackToCreated");
487 execution.setVariable("requestAction", EMPTY_STRING);
488 execution.setVariable("resourceName", EMPTY_STRING);
489 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
490 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
491 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
492 flowsToExecute.add(ebb1);
494 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
495 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
496 flowsToExecute.add(ebb2);
498 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
499 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
500 flowsToExecute.add(ebb3);
502 execution.setVariable("flowsToExecute", flowsToExecute);
503 execution.setVariable("gCurrentSequence", 3);
505 workflowActionBBTasks.rollbackExecutionPath(execution);
506 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
507 assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
508 assertEquals(0, execution.getVariable("gCurrentSequence"));
509 assertEquals(1, ebbs.size());
513 public void rollbackExecutionRollbackInPlaceSoftwareUpdateTest() {
514 execution.setVariable("isRollback", false);
515 execution.setVariable("handlingCode", "Rollback");
516 execution.setVariable("requestAction", EMPTY_STRING);
517 execution.setVariable("resourceName", EMPTY_STRING);
518 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
519 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
520 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
521 flowsToExecute.add(ebb1);
523 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
524 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
525 flowsToExecute.add(ebb2);
527 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
528 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
529 flowsToExecute.add(ebb3);
531 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
532 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
533 flowsToExecute.add(ebb4);
535 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
536 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
537 flowsToExecute.add(ebb5);
539 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFLockActivity");
540 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
541 flowsToExecute.add(ebb6);
543 BuildingBlock buildingBlock7 = new BuildingBlock().setBpmnFlowName("VNFUpgradePreCheckActivity");
544 ExecuteBuildingBlock ebb7 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock7);
545 flowsToExecute.add(ebb7);
547 BuildingBlock buildingBlock8 = new BuildingBlock().setBpmnFlowName("VNFQuiesceTrafficActivity");
548 ExecuteBuildingBlock ebb8 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock8);
549 flowsToExecute.add(ebb8);
551 BuildingBlock buildingBlock9 = new BuildingBlock().setBpmnFlowName("VNFStopActivity");
552 ExecuteBuildingBlock ebb9 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock9);
553 flowsToExecute.add(ebb9);
555 BuildingBlock buildingBlock10 = new BuildingBlock().setBpmnFlowName("VNFSnapShotActivity");
556 ExecuteBuildingBlock ebb10 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock10);
557 flowsToExecute.add(ebb10);
559 execution.setVariable("flowsToExecute", flowsToExecute);
560 execution.setVariable("gCurrentSequence", 10);
562 workflowActionBBTasks.rollbackExecutionPath(execution);
563 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
564 assertEquals("VNFStartActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
565 assertEquals("VNFResumeTrafficActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
566 assertEquals("VNFUnlockActivity", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
567 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(3).getBuildingBlock().getBpmnFlowName());
568 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(4).getBuildingBlock().getBpmnFlowName());
569 assertEquals(0, execution.getVariable("gCurrentSequence"));
570 assertEquals(5, ebbs.size());
574 public void rollbackExecutionRollbackConfigModifyTest() {
575 execution.setVariable("isRollback", false);
576 execution.setVariable("handlingCode", "Rollback");
577 execution.setVariable("requestAction", EMPTY_STRING);
578 execution.setVariable("resourceName", EMPTY_STRING);
579 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
580 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
581 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
582 flowsToExecute.add(ebb1);
584 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
585 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
586 flowsToExecute.add(ebb2);
588 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
589 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
590 flowsToExecute.add(ebb3);
592 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
593 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
594 flowsToExecute.add(ebb4);
596 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
597 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
598 flowsToExecute.add(ebb5);
600 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFHealthCheckActivity");
601 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
602 flowsToExecute.add(ebb6);
604 execution.setVariable("flowsToExecute", flowsToExecute);
605 execution.setVariable("gCurrentSequence", 6);
607 workflowActionBBTasks.rollbackExecutionPath(execution);
608 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
609 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
610 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
611 assertEquals(0, execution.getVariable("gCurrentSequence"));
612 assertEquals(2, ebbs.size());
616 public void postProcessingExecuteBBActivateVfModuleNotReplaceInstanceTest() throws CloneNotSupportedException {
617 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
618 workflowResourceIds.setServiceInstanceId("1");
619 workflowResourceIds.setVnfId("1");
621 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
622 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
623 ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
624 ebbActivateVfModule.setResourceId("1");
626 ServiceInstance service = new ServiceInstance();
627 service.setServiceInstanceName("name");
628 service.setModelVersionId("1");
629 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
631 GenericVnf vnf = new GenericVnf();
632 vnf.setVnfName("name");
633 vnf.setModelCustomizationId("1");
634 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
636 VfModule vfModule = new VfModule();
637 vfModule.setVfModuleName("name");
638 vfModule.setModelCustomizationId("1");
639 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
641 List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
642 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
643 vnfc.setModelInvariantId("1");
644 vnfc.setVnfcName("name");
645 vnfc.setModelCustomizationId("2");
647 doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
649 CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
650 ConfigurationResource configuration = new ConfigurationResource();
651 configuration.setToscaNodeType("FabricConfiguration");
652 configuration.setModelUUID("1");
653 vfModuleCustomization.setConfigurationResource(configuration);
655 doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
657 prepareDelegateExecution();
658 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
659 flowsToExecute.add(ebbActivateVfModule);
661 execution.setVariable("requestAction", "createInstance");
662 execution.setVariable("completed", true);
664 ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
665 ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
666 ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
667 workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
668 verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
669 bbCaptor.capture(), listCaptor.capture());
670 assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
671 assertEquals(2, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
673 ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
674 .getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys()
675 .getCvnfcCustomizationUUID());
676 assertEquals("AddFabricConfigurationBB", ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues()
677 .get(0).getVariable("flowsToExecute")).get(1)).getBuildingBlock().getBpmnFlowName());
681 public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasConfigurationTest()
682 throws CloneNotSupportedException {
684 BuildingBlock bbAddFabric = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
685 ExecuteBuildingBlock ebbAddFabric = new ExecuteBuildingBlock().setBuildingBlock(bbAddFabric);
686 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
687 workflowResourceIds.setServiceInstanceId("1");
688 workflowResourceIds.setVnfId("1");
689 ebbAddFabric.setWorkflowResourceIds(workflowResourceIds);
690 ebbAddFabric.setResourceId("1");
692 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
693 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
694 ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
695 ebbActivateVfModule.setResourceId("1");
696 ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
697 ebbAddFabric.setConfigurationResourceKeys(configurationResourceKeys);
699 ServiceInstance service = new ServiceInstance();
700 service.setServiceInstanceName("name");
701 service.setModelVersionId("1");
702 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
704 GenericVnf vnf = new GenericVnf();
705 vnf.setVnfName("name");
706 vnf.setModelCustomizationId("1");
707 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
709 VfModule vfModule = new VfModule();
710 vfModule.setVfModuleName("name");
711 vfModule.setModelCustomizationId("1");
712 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
714 List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
715 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
716 vnfc.setModelInvariantId("1");
717 vnfc.setVnfcName("name");
718 vnfc.setModelCustomizationId("2");
720 doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
722 CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
723 ConfigurationResource configuration = new ConfigurationResource();
724 configuration.setToscaNodeType("FabricConfiguration");
725 configuration.setModelUUID("1");
726 vfModuleCustomization.setConfigurationResource(configuration);
728 doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
730 prepareDelegateExecution();
731 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
732 flowsToExecute.add(ebbActivateVfModule);
733 flowsToExecute.add(ebbAddFabric);
735 ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
736 ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
737 ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
739 execution.setVariable("requestAction", "replaceInstance");
740 execution.setVariable("completed", true);
741 workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
742 verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
743 bbCaptor.capture(), listCaptor.capture());
744 assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
745 assertEquals(2, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
747 ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
748 .getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys()
749 .getCvnfcCustomizationUUID());
753 public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasNoConfigurationTest()
754 throws CloneNotSupportedException {
756 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
757 workflowResourceIds.setServiceInstanceId("1");
758 workflowResourceIds.setVnfId("1");
760 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
761 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
762 ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
763 ebbActivateVfModule.setResourceId("1");
765 ServiceInstance service = new ServiceInstance();
766 service.setServiceInstanceName("name");
767 service.setModelVersionId("1");
768 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
770 GenericVnf vnf = new GenericVnf();
771 vnf.setVnfName("name");
772 vnf.setModelCustomizationId("1");
773 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
775 VfModule vfModule = new VfModule();
776 vfModule.setVfModuleName("name");
777 vfModule.setModelCustomizationId("1");
778 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
780 List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
781 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
782 vnfc.setModelInvariantId("1");
783 vnfc.setVnfcName("name");
784 vnfc.setModelCustomizationId("2");
786 doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
788 CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
789 ConfigurationResource configuration = new ConfigurationResource();
790 configuration.setToscaNodeType("FabricConfiguration");
791 configuration.setModelUUID("1");
792 vfModuleCustomization.setConfigurationResource(configuration);
794 doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
796 prepareDelegateExecution();
797 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
798 flowsToExecute.add(ebbActivateVfModule);
800 ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
801 ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
802 ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
804 execution.setVariable("requestAction", "replaceInstance");
805 execution.setVariable("completed", true);
807 workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
808 verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
809 bbCaptor.capture(), listCaptor.capture());
810 assertEquals(true, executionCaptor.getAllValues().get(0).getVariable("completed"));
816 public void getExecuteBBForConfigTest() throws CloneNotSupportedException {
817 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
818 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
820 WorkflowResourceIds resourceIdsActivateVfModule = new WorkflowResourceIds();
821 resourceIdsActivateVfModule.setServiceInstanceId("test-service-inbstance-id");
822 resourceIdsActivateVfModule.setVnfId("test-vnf-id");
823 resourceIdsActivateVfModule.setVfModuleId("test-vf-module-id");
824 resourceIdsActivateVfModule.setConfigurationId("");
826 RequestDetails requestDetails = new RequestDetails();
828 ebbActivateVfModule.setApiVersion("7");
829 ebbActivateVfModule.setaLaCarte(true);
830 ebbActivateVfModule.setRequestAction("createInstance");
831 ebbActivateVfModule.setVnfType("test-vnf-type");
832 ebbActivateVfModule.setRequestId("f6c00ae2-a205-4cbd-b055-02e553efde12");
833 ebbActivateVfModule.setRequestDetails(requestDetails);
834 ebbActivateVfModule.setWorkflowResourceIds(resourceIdsActivateVfModule);
836 ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
837 configurationResourceKeys.setCvnfcCustomizationUUID("07d64cd2-4427-4156-b11d-d14b96b3e4cb");
838 configurationResourceKeys.setVfModuleCustomizationUUID("50b61075-6ebb-4aab-a9fc-bedad9a2aa76");
839 configurationResourceKeys.setVnfResourceCustomizationUUID("a1d0e36e-34a9-431b-b5ba-4bbb72f63c7c");
840 configurationResourceKeys.setVnfcName("rdm54bvbgw5001vm018pim001");
842 ExecuteBuildingBlock ebbAddFabricConfig =
843 workflowActionBBTasks.getExecuteBBForConfig("AddFabricConfigurationBB", ebbActivateVfModule,
844 "cc7e12f9-967c-4362-8d14-e5b2bf0608a4", configurationResourceKeys);
846 assertEquals("7", ebbAddFabricConfig.getApiVersion());
847 assertTrue(ebbAddFabricConfig.isaLaCarte());
848 assertEquals("createInstance", ebbAddFabricConfig.getRequestAction());
849 assertEquals("test-vnf-type", ebbAddFabricConfig.getVnfType());
850 assertEquals("f6c00ae2-a205-4cbd-b055-02e553efde12", ebbAddFabricConfig.getRequestId());
851 assertEquals(requestDetails, ebbAddFabricConfig.getRequestDetails());
852 assertEquals("cc7e12f9-967c-4362-8d14-e5b2bf0608a4",
853 ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId());
854 assertEquals("test-service-inbstance-id", ebbAddFabricConfig.getWorkflowResourceIds().getServiceInstanceId());
855 assertEquals("test-vnf-id", ebbAddFabricConfig.getWorkflowResourceIds().getVnfId());
856 assertEquals("test-vf-module-id", ebbAddFabricConfig.getWorkflowResourceIds().getVfModuleId());
858 assertThat(ebbAddFabricConfig.getConfigurationResourceKeys()).isEqualTo(configurationResourceKeys);
859 assertThat(ebbAddFabricConfig.getWorkflowResourceIds())
860 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds());
861 assertThat(ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId())
862 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds().getConfigurationId());
866 public void checkRetryStatusTest() {
867 String reqId = "reqId123";
868 execution.setVariable("mso-request-id", reqId);
869 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
870 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
871 execution.setVariable("handlingCode", "Retry");
872 execution.setVariable("retryCount", 1);
873 execution.setVariable("gCurrentSequence", 1);
874 InfraActiveRequests req = new InfraActiveRequests();
875 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
876 workflowActionBBTasks.checkRetryStatus(execution);
877 assertEquals(0, execution.getVariable("gCurrentSequence"));
881 public void checkRetryStatusTestExceededMaxRetries() {
882 String reqId = "reqId123";
883 execution.setVariable("mso-request-id", reqId);
884 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
885 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
886 execution.setVariable("handlingCode", "Retry");
887 execution.setVariable("retryCount", 6);
888 execution.setVariable("gCurrentSequence", 1);
889 InfraActiveRequests req = new InfraActiveRequests();
890 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
892 workflowActionBBTasks.checkRetryStatus(execution);
893 } catch (BpmnError e) {
894 WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException");
895 assertEquals("Exceeded maximum retries. Ending flow with status Abort", exception.getErrorMessage());
900 public void checkRetryStatusNoRetryTest() {
901 String reqId = "reqId123";
902 execution.setVariable("mso-request-id", reqId);
903 execution.setVariable("retryCount", 3);
904 execution.setVariable("handlingCode", "Success");
905 execution.setVariable("gCurrentSequence", 1);
906 InfraActiveRequests req = new InfraActiveRequests();
907 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
908 workflowActionBBTasks.checkRetryStatus(execution);
909 assertEquals(0, execution.getVariable("retryCount"));
913 public void updateInstanceId() {
914 String reqId = "req123";
915 String instanceId = "123123123";
916 execution.setVariable("mso-request-id", reqId);
917 execution.setVariable("resourceId", instanceId);
918 execution.setVariable("resourceType", WorkflowType.SERVICE);
919 doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
920 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
921 workflowActionBBTasks.updateInstanceId(execution);
922 Mockito.verify(reqMock, Mockito.times(1)).setServiceInstanceId(instanceId);
926 public void getConfigurationId() throws Exception {
927 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
928 vnfc.setModelInvariantId("modelInvariantId");
929 vnfc.setVnfcName("testVnfcName");
930 List<Configuration> configurations = new ArrayList<>();
931 org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
932 configuration.setConfigurationId("configurationId");
933 configuration.setModelCustomizationId("modelCustimizationId");
934 configuration.setConfigurationName("testConfigurationName");
935 configurations.add(configuration);
936 doReturn(configurations.get(0).getConfigurationId()).when(workflowActionBBTasks).getConfigurationId(vnfc);
937 assertEquals(workflowActionBBTasks.getConfigurationId(vnfc), "configurationId");
941 public void setServiceInstanceNameTest() {
942 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
943 WorkflowType resourceType = WorkflowType.SERVICE;
944 InfraActiveRequests request = new InfraActiveRequests();
945 ServiceInstance service = new ServiceInstance();
946 service.setServiceInstanceName("serviceInstanceName");
947 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById(resourceId);
949 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
950 assertEquals("serviceInstanceName", request.getServiceInstanceName());
954 public void setVnfNameTest() {
955 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
956 WorkflowType resourceType = WorkflowType.VNF;
957 InfraActiveRequests request = new InfraActiveRequests();
958 GenericVnf vnf = new GenericVnf();
959 vnf.setVnfName("vnfName");
960 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf(resourceId);
962 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
963 assertEquals("vnfName", request.getVnfName());
967 public void setVfModuleNameTest() {
968 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
969 WorkflowType resourceType = WorkflowType.VFMODULE;
970 InfraActiveRequests request = new InfraActiveRequests();
971 request.setVnfId("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e");
972 VfModule vfModule = new VfModule();
973 vfModule.setVfModuleName("vfModuleName");
974 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e", resourceId);
976 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
977 assertEquals("vfModuleName", request.getVfModuleName());
981 public void setNetworkNameTest() {
982 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
983 WorkflowType resourceType = WorkflowType.NETWORK;
984 InfraActiveRequests request = new InfraActiveRequests();
985 L3Network network = new L3Network();
986 network.setNetworkName("networkName");
987 doReturn(network).when(bbSetupUtils).getAAIL3Network(resourceId);
989 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
990 assertEquals("networkName", request.getNetworkName());
994 public void setConfigurationNameTest() {
995 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
996 WorkflowType resourceType = WorkflowType.CONFIGURATION;
997 InfraActiveRequests request = new InfraActiveRequests();
998 Configuration configuration = new Configuration();
999 configuration.setConfigurationName("configurationName");
1000 doReturn(configuration).when(bbSetupUtils).getAAIConfiguration(resourceId);
1002 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1003 assertEquals("configurationName", request.getConfigurationName());
1007 public void setInstanceGroupNameTest() {
1008 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1009 WorkflowType resourceType = WorkflowType.INSTANCE_GROUP;
1010 InfraActiveRequests request = new InfraActiveRequests();
1011 InstanceGroup instanceGroup = new InstanceGroup();
1012 instanceGroup.setInstanceGroupName("instanceGroupName");
1013 doReturn(instanceGroup).when(bbSetupUtils).getAAIInstanceGroup(resourceId);
1015 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1016 assertEquals("instanceGroupName", request.getInstanceGroupName());
1020 public void setVolumeGroupNameTest() {
1021 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1022 WorkflowType resourceType = WorkflowType.VOLUMEGROUP;
1023 InfraActiveRequests request = new InfraActiveRequests();
1024 request.setVnfId("4aa72c90-21eb-4465-8847-997e27af6c3e");
1025 VolumeGroup volumeGroup = new VolumeGroup();
1026 volumeGroup.setVolumeGroupName("volumeGroupName");
1027 Optional<VolumeGroup> returnVolumeGroup = Optional.of(volumeGroup);
1029 doReturn(returnVolumeGroup).when(bbSetupUtils).getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
1030 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1032 assertEquals("volumeGroupName", request.getVolumeGroupName());
1035 private void prepareDelegateExecution() {
1036 execution.setVariable("mso-request-id", SAMPLE_MSO_REQUEST_ID);
1037 execution.setVariable("requestAction", SAMPLE_REQUEST_ACTION);
1038 execution.setVariable("gCurrentSequence", SAMPLE_SEQUENCE);
1039 execution.setVariable("homing", false);
1040 execution.setVariable("calledHoming", false);