007d696d2ea0d415188a5a07d6a276c52ffa117e
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.workflow.tasks;
24
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.Arrays;
39 import java.util.Collections;
40 import java.util.ArrayList;
41 import java.util.List;
42 import java.util.Optional;
43 import org.camunda.bpm.engine.delegate.BpmnError;
44 import org.camunda.bpm.engine.delegate.DelegateExecution;
45 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
46 import org.junit.Before;
47 import org.junit.Rule;
48 import org.junit.Test;
49 import org.junit.rules.ExpectedException;
50 import org.mockito.ArgumentCaptor;
51 import org.mockito.InjectMocks;
52 import org.mockito.Mock;
53 import org.mockito.Mockito;
54 import org.mockito.Spy;
55 import org.onap.aai.domain.yang.Configuration;
56 import org.onap.aai.domain.yang.GenericVnf;
57 import org.onap.aai.domain.yang.InstanceGroup;
58 import org.onap.aai.domain.yang.L3Network;
59 import org.onap.aai.domain.yang.ServiceInstance;
60 import org.onap.aai.domain.yang.VfModule;
61 import org.onap.aai.domain.yang.VolumeGroup;
62 import org.onap.so.bpmn.BaseTaskTest;
63 import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner;
64 import org.onap.so.bpmn.core.WorkflowException;
65 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
66 import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
67 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
68 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
69 import org.onap.so.db.catalog.beans.BuildingBlockRollback;
70 import org.onap.so.db.catalog.beans.ConfigurationResource;
71 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
72 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
73 import org.onap.so.db.request.beans.InfraActiveRequests;
74 import org.onap.so.serviceinstancebeans.ModelInfo;
75 import org.onap.so.serviceinstancebeans.ModelType;
76 import org.onap.so.serviceinstancebeans.RelatedInstance;
77 import org.onap.so.serviceinstancebeans.RelatedInstanceList;
78 import org.onap.so.serviceinstancebeans.RequestDetails;
79 import org.springframework.core.env.Environment;
80
81 public class WorkflowActionBBTasksTest extends BaseTaskTest {
82
83     private static final String SAMPLE_MSO_REQUEST_ID = "00f704ca-c5e5-4f95-a72c-6889db7b0688";
84     private static final String SAMPLE_REQUEST_ACTION = "Delete-Network-Collection";
85     private static final int SAMPLE_SEQUENCE = 0;
86     private static final String EMPTY_STRING = "";
87     @Mock
88     protected WorkflowAction workflowAction;
89
90     @Mock
91     protected WorkflowActionBBFailure workflowActionBBFailure;
92
93     @InjectMocks
94     @Spy
95     protected WorkflowActionBBTasks workflowActionBBTasks;
96
97     @Mock
98     InfraActiveRequests reqMock;
99
100     private DelegateExecution execution;
101
102     @Mock
103     protected Environment environment;
104
105     @Mock
106     private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
107
108     @Rule
109     public ExpectedException thrown = ExpectedException.none();
110
111     @Mock
112     private DelegateExecution mockExecution;
113
114     @Before
115     public void initCatalogDBRollbackTable() {
116         when(catalogDbClient.getBuildingBlockRollbackEntries()).thenReturn(getRollbackBuildingBlockList());
117     }
118
119     @Before
120     public void before() throws Exception {
121         execution = new DelegateExecutionFake();
122         ServiceInstance servInstance = new ServiceInstance();
123         servInstance.setServiceInstanceId("TEST");
124         when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance);
125         workflowAction.setBbInputSetupUtils(bbSetupUtils);
126         workflowAction.setBbInputSetup(bbInputSetup);
127     }
128
129     @Test
130     public void selectBBTest() {
131         String vnfCustomizationUUID = "1234567";
132         String modelUuid = "1234567";
133         prepareDelegateExecution();
134         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
135
136         BuildingBlock buildingBlock =
137                 new BuildingBlock().setBpmnFlowName("ConfigAssignVnfBB").setKey(vnfCustomizationUUID);
138         RequestDetails rd = new RequestDetails();
139         ModelInfo mi = new ModelInfo();
140         mi.setModelUuid(modelUuid);
141         rd.setModelInfo(mi);
142         ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
143         flowsToExecute.add(ebb);
144
145         List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
146         VnfResourceCustomization vrc = new VnfResourceCustomization();
147         vrc.setSkipPostInstConf(false);
148         vrc.setModelCustomizationUUID(vnfCustomizationUUID);
149         vnfResourceCustomizations.add(vrc);
150         GenericVnf genericVnf = new GenericVnf();
151         genericVnf.setModelCustomizationId(vnfCustomizationUUID);
152         doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
153         doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
154                 vnfResourceCustomizations);
155
156         execution.setVariable("flowsToExecute", flowsToExecute);
157         workflowActionBBTasks.selectBB(execution);
158         boolean success = (boolean) execution.getVariable("completed");
159         int currentSequence = (int) execution.getVariable("gCurrentSequence");
160         assertFalse(success);
161         assertEquals(1, currentSequence);
162     }
163
164     @Test
165     public void select2BBTest() {
166         String vnfCustomizationUUID = "1234567";
167         String modelUuid = "1234567";
168
169         prepareDelegateExecution();
170         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
171         BuildingBlock buildingBlock =
172                 new BuildingBlock().setBpmnFlowName("ConfigDeployVnfBB").setKey(vnfCustomizationUUID);
173         RequestDetails rd = new RequestDetails();
174         ModelInfo mi = new ModelInfo();
175         mi.setModelUuid(modelUuid);
176         rd.setModelInfo(mi);
177         ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
178         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
179
180         flowsToExecute.add(ebb);
181
182         List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
183         VnfResourceCustomization vrc = new VnfResourceCustomization();
184
185         vrc.setSkipPostInstConf(false);
186         vrc.setModelCustomizationUUID(vnfCustomizationUUID);
187         vnfResourceCustomizations.add(vrc);
188         GenericVnf genericVnf = new GenericVnf();
189         genericVnf.setModelCustomizationId(vnfCustomizationUUID);
190
191         doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
192         doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
193                 vnfResourceCustomizations);
194
195         flowsToExecute.add(ebb2);
196         execution.setVariable("flowsToExecute", flowsToExecute);
197         workflowActionBBTasks.selectBB(execution);
198         boolean success = (boolean) execution.getVariable("completed");
199         int currentSequence = (int) execution.getVariable("gCurrentSequence");
200         assertFalse(success);
201         assertEquals(1, currentSequence);
202     }
203
204     @Test
205     public void updateRequestStatusToCompleteTest() {
206         String reqId = "reqId123";
207         execution.setVariable("mso-request-id", reqId);
208         execution.setVariable("requestAction", "createInstance");
209         execution.setVariable("resourceName", "Service");
210         execution.setVariable("aLaCarte", true);
211         InfraActiveRequests req = new InfraActiveRequests();
212         doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
213         doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
214         workflowActionBBTasks.updateRequestStatusToComplete(execution);
215         assertEquals("ALaCarte-Service-createInstance request was executed correctly.",
216                 execution.getVariable("finalStatusMessage"));
217     }
218
219     @Test
220     public void rollbackExecutionPathTest() {
221         execution.setVariable("handlingCode", "Rollback");
222         execution.setVariable("isRollback", false);
223         execution.setVariable("requestAction", EMPTY_STRING);
224         execution.setVariable("resourceName", EMPTY_STRING);
225         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
226         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
227         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
228         flowsToExecute.add(ebb1);
229
230         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
231         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
232         flowsToExecute.add(ebb2);
233
234         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
235         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
236         flowsToExecute.add(ebb3);
237
238         execution.setVariable("flowsToExecute", flowsToExecute);
239         execution.setVariable("gCurrentSequence", 3);
240         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
241
242         workflowActionBBTasks.rollbackExecutionPath(execution);
243         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
244         assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeactivateVfModuleBB");
245         assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
246         assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
247         assertEquals(0, execution.getVariable("gCurrentSequence"));
248     }
249
250     @Test
251     public void rollbackExecutionPathUnfinishedFlowTest() {
252         execution.setVariable("handlingCode", "Rollback");
253         execution.setVariable("isRollback", false);
254         execution.setVariable("requestAction", EMPTY_STRING);
255         execution.setVariable("resourceName", EMPTY_STRING);
256         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
257         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
258         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
259         flowsToExecute.add(ebb1);
260
261         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
262         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
263         flowsToExecute.add(ebb2);
264
265         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
266         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
267         flowsToExecute.add(ebb3);
268
269         execution.setVariable("flowsToExecute", flowsToExecute);
270         execution.setVariable("gCurrentSequence", 2);
271         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
272
273         workflowActionBBTasks.rollbackExecutionPath(execution);
274         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
275         assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
276         assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
277         assertEquals(0, execution.getVariable("gCurrentSequence"));
278         assertEquals(0, execution.getVariable("retryCount"));
279     }
280
281     @Test
282     public void rollbackExecutionTest() {
283         execution.setVariable("handlingCode", "Rollback");
284         execution.setVariable("isRollback", false);
285         execution.setVariable("requestAction", EMPTY_STRING);
286         execution.setVariable("resourceName", EMPTY_STRING);
287         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
288         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB");
289         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
290         flowsToExecute.add(ebb1);
291
292         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateNetworkCollectionBB");
293         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
294         flowsToExecute.add(ebb2);
295
296         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("AssignNetworkBB");
297         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
298         flowsToExecute.add(ebb3);
299
300         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("CreateNetworkBB");
301         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
302         flowsToExecute.add(ebb4);
303
304         execution.setVariable("flowsToExecute", flowsToExecute);
305         execution.setVariable("gCurrentSequence", 3);
306         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
307
308         workflowActionBBTasks.rollbackExecutionPath(execution);
309         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
310         assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "UnassignNetworkBB");
311         assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteNetworkCollectionBB");
312         assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignServiceInstanceBB");
313         assertEquals(0, execution.getVariable("gCurrentSequence"));
314     }
315
316     @Test
317     public void rollbackExecutionRollbackToAssignedTest() {
318         execution.setVariable("isRollback", false);
319         execution.setVariable("handlingCode", "RollbackToAssigned");
320         execution.setVariable("requestAction", EMPTY_STRING);
321         execution.setVariable("resourceName", EMPTY_STRING);
322         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
323
324         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
325         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
326         flowsToExecute.add(ebb1);
327
328         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
329         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
330         flowsToExecute.add(ebb2);
331
332         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
333         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
334         flowsToExecute.add(ebb3);
335
336         execution.setVariable("flowsToExecute", flowsToExecute);
337         execution.setVariable("gCurrentSequence", 2);
338
339         workflowActionBBTasks.rollbackExecutionPath(execution);
340         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
341         assertEquals("DeleteVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
342         assertEquals(0, execution.getVariable("gCurrentSequence"));
343         assertEquals(1, ebbs.size());
344     }
345
346     @Test
347     public void rollbackExecutionPathChangeBBForReplaceVFModuleTest() {
348         execution.setVariable("handlingCode", "Rollback");
349         execution.setVariable("isRollback", false);
350         execution.setVariable("requestAction", "replaceInstance");
351         execution.setVariable("resourceName", "VfModule");
352         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
353         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
354         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
355         flowsToExecute.add(ebb1);
356
357         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
358         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
359         flowsToExecute.add(ebb2);
360
361         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
362         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
363         flowsToExecute.add(ebb3);
364
365
366         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("ChangeModelVnfBB");
367         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
368         flowsToExecute.add(ebb4);
369
370         BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("ChangeModelServiceInstanceBB");
371         ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
372         flowsToExecute.add(ebb5);
373
374         execution.setVariable("flowsToExecute", flowsToExecute);
375         execution.setVariable("gCurrentSequence", 5);
376         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
377
378         workflowActionBBTasks.rollbackExecutionPath(execution);
379         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
380         assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "ChangeModelVnfBB");
381         assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "ChangeModelServiceInstanceBB");
382         assertEquals(0, execution.getVariable("gCurrentSequence"));
383     }
384
385     @Test
386     public void rollbackExecutionRollbackToAssignedWithFabricTest() {
387         execution.setVariable("isRollback", false);
388         execution.setVariable("handlingCode", "RollbackToAssigned");
389         execution.setVariable("requestAction", EMPTY_STRING);
390         execution.setVariable("resourceName", EMPTY_STRING);
391         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
392
393         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
394         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
395         flowsToExecute.add(ebb1);
396
397         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
398         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
399         flowsToExecute.add(ebb2);
400
401         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
402         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
403         flowsToExecute.add(ebb3);
404
405         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
406         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
407         flowsToExecute.add(ebb4);
408
409         execution.setVariable("flowsToExecute", flowsToExecute);
410         execution.setVariable("gCurrentSequence", 4);
411
412         workflowActionBBTasks.rollbackExecutionPath(execution);
413         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
414         assertEquals(0, execution.getVariable("gCurrentSequence"));
415         assertEquals(3, ebbs.size());
416         assertEquals("DeleteFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
417         assertEquals("DeactivateVfModuleBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
418         assertEquals("DeleteVfModuleBB", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
419
420     }
421
422     @Test
423     public void rollbackExecutionRollbackToCreatedWithFabricTest() {
424         execution.setVariable("isRollback", false);
425         execution.setVariable("handlingCode", "RollbackToCreated");
426         execution.setVariable("requestAction", EMPTY_STRING);
427         execution.setVariable("resourceName", EMPTY_STRING);
428         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
429
430         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
431         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
432         flowsToExecute.add(ebb1);
433
434         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
435         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
436         flowsToExecute.add(ebb2);
437
438         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
439         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
440         flowsToExecute.add(ebb3);
441
442         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
443         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
444         flowsToExecute.add(ebb4);
445
446         execution.setVariable("flowsToExecute", flowsToExecute);
447         execution.setVariable("gCurrentSequence", 4);
448
449         workflowActionBBTasks.rollbackExecutionPath(execution);
450         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
451         assertEquals(0, execution.getVariable("gCurrentSequence"));
452         assertEquals(2, ebbs.size());
453         assertEquals("DeleteFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
454         assertEquals("DeactivateVfModuleBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
455
456     }
457
458     @Test
459     public void rollbackExecutionRollbackToCreatedNoConfigurationWithFabricTest() {
460         execution.setVariable("isRollback", false);
461         execution.setVariable("handlingCode", "RollbackToCreatedNoConfiguration");
462         execution.setVariable("requestAction", EMPTY_STRING);
463         execution.setVariable("resourceName", EMPTY_STRING);
464         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
465
466         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
467         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
468         flowsToExecute.add(ebb1);
469
470         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
471         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
472         flowsToExecute.add(ebb2);
473
474         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
475         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
476         flowsToExecute.add(ebb3);
477
478         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
479         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
480         flowsToExecute.add(ebb4);
481
482         execution.setVariable("flowsToExecute", flowsToExecute);
483         execution.setVariable("gCurrentSequence", 4);
484
485         workflowActionBBTasks.rollbackExecutionPath(execution);
486         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
487         assertEquals(0, execution.getVariable("gCurrentSequence"));
488         assertEquals(1, ebbs.size());
489         assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
490     }
491
492     @Test
493     public void rollbackExecutionRollbackToCreatedTest() {
494         execution.setVariable("isRollback", false);
495         execution.setVariable("handlingCode", "RollbackToCreated");
496         execution.setVariable("requestAction", EMPTY_STRING);
497         execution.setVariable("resourceName", EMPTY_STRING);
498         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
499         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
500         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
501         flowsToExecute.add(ebb1);
502
503         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
504         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
505         flowsToExecute.add(ebb2);
506
507         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
508         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
509         flowsToExecute.add(ebb3);
510
511         execution.setVariable("flowsToExecute", flowsToExecute);
512         execution.setVariable("gCurrentSequence", 3);
513
514         workflowActionBBTasks.rollbackExecutionPath(execution);
515         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
516         assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
517         assertEquals(0, execution.getVariable("gCurrentSequence"));
518         assertEquals(1, ebbs.size());
519     }
520
521     @Test
522     public void rollbackExecutionRollbackInPlaceSoftwareUpdateTest() {
523         execution.setVariable("isRollback", false);
524         execution.setVariable("handlingCode", "Rollback");
525         execution.setVariable("requestAction", EMPTY_STRING);
526         execution.setVariable("resourceName", EMPTY_STRING);
527         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
528         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
529         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
530         flowsToExecute.add(ebb1);
531
532         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
533         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
534         flowsToExecute.add(ebb2);
535
536         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
537         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
538         flowsToExecute.add(ebb3);
539
540         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
541         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
542         flowsToExecute.add(ebb4);
543
544         BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
545         ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
546         flowsToExecute.add(ebb5);
547
548         BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFLockActivity");
549         ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
550         flowsToExecute.add(ebb6);
551
552         BuildingBlock buildingBlock7 = new BuildingBlock().setBpmnFlowName("VNFUpgradePreCheckActivity");
553         ExecuteBuildingBlock ebb7 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock7);
554         flowsToExecute.add(ebb7);
555
556         BuildingBlock buildingBlock8 = new BuildingBlock().setBpmnFlowName("VNFQuiesceTrafficActivity");
557         ExecuteBuildingBlock ebb8 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock8);
558         flowsToExecute.add(ebb8);
559
560         BuildingBlock buildingBlock9 = new BuildingBlock().setBpmnFlowName("VNFStopActivity");
561         ExecuteBuildingBlock ebb9 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock9);
562         flowsToExecute.add(ebb9);
563
564         BuildingBlock buildingBlock10 = new BuildingBlock().setBpmnFlowName("VNFSnapShotActivity");
565         ExecuteBuildingBlock ebb10 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock10);
566         flowsToExecute.add(ebb10);
567
568         execution.setVariable("flowsToExecute", flowsToExecute);
569         execution.setVariable("gCurrentSequence", 10);
570
571         workflowActionBBTasks.rollbackExecutionPath(execution);
572         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
573         assertEquals("VNFStartActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
574         assertEquals("VNFResumeTrafficActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
575         assertEquals("VNFUnlockActivity", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
576         assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(3).getBuildingBlock().getBpmnFlowName());
577         assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(4).getBuildingBlock().getBpmnFlowName());
578         assertEquals(0, execution.getVariable("gCurrentSequence"));
579         assertEquals(5, ebbs.size());
580     }
581
582     @Test
583     public void rollbackExecutionRollbackConfigModifyTest() {
584         execution.setVariable("isRollback", false);
585         execution.setVariable("handlingCode", "Rollback");
586         execution.setVariable("requestAction", EMPTY_STRING);
587         execution.setVariable("resourceName", EMPTY_STRING);
588         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
589         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
590         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
591         flowsToExecute.add(ebb1);
592
593         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
594         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
595         flowsToExecute.add(ebb2);
596
597         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
598         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
599         flowsToExecute.add(ebb3);
600
601         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
602         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
603         flowsToExecute.add(ebb4);
604
605         BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
606         ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
607         flowsToExecute.add(ebb5);
608
609         BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFHealthCheckActivity");
610         ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
611         flowsToExecute.add(ebb6);
612
613         execution.setVariable("flowsToExecute", flowsToExecute);
614         execution.setVariable("gCurrentSequence", 6);
615
616         workflowActionBBTasks.rollbackExecutionPath(execution);
617         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
618         assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
619         assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
620         assertEquals(0, execution.getVariable("gCurrentSequence"));
621         assertEquals(2, ebbs.size());
622     }
623
624     @Test
625     public void rollbackExecutionRollbackControllerExecutionBBTest() {
626         execution.setVariable("isRollback", false);
627         execution.setVariable("handlingCode", "Rollback");
628         execution.setVariable("requestAction", EMPTY_STRING);
629         execution.setVariable("resourceName", EMPTY_STRING);
630         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
631         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB");
632         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
633         flowsToExecute.add(ebb1);
634
635         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("AssignNetworkBB");
636         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
637         flowsToExecute.add(ebb2);
638
639         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("AssignVnfBB");
640         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
641         flowsToExecute.add(ebb3);
642
643         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
644         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
645         flowsToExecute.add(ebb4);
646
647         BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("ControllerExecutionBB");
648         buildingBlock5.setBpmnScope("vnf");
649         buildingBlock5.setBpmnAction("config-assign");
650         ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
651         flowsToExecute.add(ebb5);
652
653         BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
654         ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
655         flowsToExecute.add(ebb6);
656
657         execution.setVariable("flowsToExecute", flowsToExecute);
658         execution.setVariable("gCurrentSequence", 5);
659
660         workflowActionBBTasks.rollbackExecutionPath(execution);
661         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
662         BuildingBlock bb = ebbs.get(0).getBuildingBlock();
663         assertEquals("ControllerExecutionBB", bb.getBpmnFlowName());
664         assertEquals("vnf", bb.getBpmnScope());
665         assertEquals("config-unassign", bb.getBpmnAction());
666         assertEquals(0, execution.getVariable("gCurrentSequence"));
667         assertEquals(5, ebbs.size());
668     }
669
670     @Test
671     public void postProcessingExecuteBBActivateVfModuleNotReplaceInstanceTest() {
672         WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
673         workflowResourceIds.setServiceInstanceId("1");
674         workflowResourceIds.setVnfId("1");
675
676         BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
677         ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
678         ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
679         ebbActivateVfModule.setResourceId("1");
680
681         ServiceInstance service = new ServiceInstance();
682         service.setServiceInstanceName("name");
683         service.setModelVersionId("1");
684         doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
685
686         GenericVnf vnf = new GenericVnf();
687         vnf.setVnfName("name");
688         vnf.setModelCustomizationId("1");
689         doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
690
691         VfModule vfModule = new VfModule();
692         vfModule.setVfModuleName("name");
693         vfModule.setModelCustomizationId("1");
694         doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
695
696         List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
697         org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
698         vnfc.setModelInvariantId("1");
699         vnfc.setVnfcName("name");
700         vnfc.setModelCustomizationId("2");
701         vnfcs.add(vnfc);
702         doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
703
704         CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
705         ConfigurationResource configuration = new ConfigurationResource();
706         configuration.setToscaNodeType("FabricConfiguration");
707         configuration.setModelUUID("1");
708         vfModuleCustomization.setConfigurationResource(configuration);
709
710         doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
711
712         prepareDelegateExecution();
713         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
714         flowsToExecute.add(ebbActivateVfModule);
715
716         execution.setVariable("requestAction", "createInstance");
717         execution.setVariable("completed", true);
718
719         ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
720         ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
721         ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
722         workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
723         verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
724                 bbCaptor.capture(), listCaptor.capture());
725         assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
726         assertEquals(2, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
727         assertEquals("2",
728                 ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
729                         .getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys()
730                                 .getCvnfcCustomizationUUID());
731         assertEquals("AddFabricConfigurationBB", ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues()
732                 .get(0).getVariable("flowsToExecute")).get(1)).getBuildingBlock().getBpmnFlowName());
733     }
734
735     @Test
736     public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasConfigurationTest() {
737         RequestDetails reqDetails = new RequestDetails();
738         RelatedInstanceList[] list = new RelatedInstanceList[2];
739         RelatedInstanceList vnfList = new RelatedInstanceList();
740         RelatedInstanceList serviceList = new RelatedInstanceList();
741         list[0] = vnfList;
742         list[1] = serviceList;
743         RelatedInstance vnfInstance = new RelatedInstance();
744         RelatedInstance serviceInstance = new RelatedInstance();
745         ModelInfo vnfModelInfo = new ModelInfo();
746         vnfModelInfo.setModelType(ModelType.vnf);
747         vnfModelInfo.setModelCustomizationId("1");
748         ModelInfo serviceModelInfo = new ModelInfo();
749         serviceModelInfo.setModelType(ModelType.service);
750         serviceModelInfo.setModelVersionId("1");
751         vnfInstance.setModelInfo(vnfModelInfo);
752         serviceInstance.setModelInfo(serviceModelInfo);
753         reqDetails.setRelatedInstanceList(list);
754         vnfList.setRelatedInstance(vnfInstance);
755         serviceList.setRelatedInstance(serviceInstance);
756         ModelInfo vfModuleInfo = new ModelInfo();
757         vfModuleInfo.setModelCustomizationId("1");
758         reqDetails.setModelInfo(vfModuleInfo);
759         BuildingBlock bbAddFabric = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
760         ExecuteBuildingBlock ebbAddFabric = new ExecuteBuildingBlock().setBuildingBlock(bbAddFabric);
761         WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
762         workflowResourceIds.setServiceInstanceId("1");
763         workflowResourceIds.setVnfId("1");
764         ebbAddFabric.setWorkflowResourceIds(workflowResourceIds);
765         ebbAddFabric.setResourceId("1");
766
767         BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
768         ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
769         ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
770         ebbActivateVfModule.setResourceId("1");
771         ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
772         ebbAddFabric.setConfigurationResourceKeys(configurationResourceKeys);
773         ebbActivateVfModule.setRequestDetails(reqDetails);
774
775         ServiceInstance service = new ServiceInstance();
776         service.setServiceInstanceName("name");
777         service.setModelVersionId("1");
778         doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
779
780         GenericVnf vnf = new GenericVnf();
781         vnf.setVnfName("name");
782         vnf.setModelCustomizationId("1");
783         doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
784
785         VfModule vfModule = new VfModule();
786         vfModule.setVfModuleName("name");
787         vfModule.setModelCustomizationId("1");
788         doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
789
790         List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
791         org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
792         vnfc.setModelInvariantId("1");
793         vnfc.setVnfcName("name");
794         vnfc.setModelCustomizationId("2");
795         vnfcs.add(vnfc);
796         doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
797
798         CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
799         ConfigurationResource configuration = new ConfigurationResource();
800         configuration.setToscaNodeType("FabricConfiguration");
801         configuration.setModelUUID("1");
802         vfModuleCustomization.setConfigurationResource(configuration);
803
804         doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
805
806         prepareDelegateExecution();
807         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
808         flowsToExecute.add(ebbActivateVfModule);
809
810         ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
811         ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
812         ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
813
814         execution.setVariable("requestAction", "replaceInstance");
815         execution.setVariable("completed", true);
816         workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
817         verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
818                 bbCaptor.capture(), listCaptor.capture());
819         assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
820         assertEquals(2, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
821         assertEquals("2",
822                 ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
823                         .getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys()
824                                 .getCvnfcCustomizationUUID());
825     }
826
827     @Test
828     public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasNoConfigurationTest() {
829
830         WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
831         workflowResourceIds.setServiceInstanceId("1");
832         workflowResourceIds.setVnfId("1");
833
834         BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
835         ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
836         ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
837         ebbActivateVfModule.setResourceId("1");
838
839         ServiceInstance service = new ServiceInstance();
840         service.setServiceInstanceName("name");
841         service.setModelVersionId("1");
842         doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
843
844         GenericVnf vnf = new GenericVnf();
845         vnf.setVnfName("name");
846         vnf.setModelCustomizationId("1");
847         doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
848
849         VfModule vfModule = new VfModule();
850         vfModule.setVfModuleName("name");
851         vfModule.setModelCustomizationId("1");
852         doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
853
854         List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
855         org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
856         vnfc.setModelInvariantId("1");
857         vnfc.setVnfcName("name");
858         vnfc.setModelCustomizationId("2");
859         vnfcs.add(vnfc);
860         doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
861
862         CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
863         ConfigurationResource configuration = new ConfigurationResource();
864         configuration.setToscaNodeType("FabricConfiguration");
865         configuration.setModelUUID("1");
866         vfModuleCustomization.setConfigurationResource(configuration);
867
868         doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
869
870         prepareDelegateExecution();
871         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
872         flowsToExecute.add(ebbActivateVfModule);
873
874         ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
875         ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
876         ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
877
878         execution.setVariable("requestAction", "replaceInstance");
879         execution.setVariable("completed", true);
880
881         workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
882         verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
883                 bbCaptor.capture(), listCaptor.capture());
884         assertEquals(true, executionCaptor.getAllValues().get(0).getVariable("completed"));
885     }
886
887
888
889     @Test
890     public void getExecuteBBForConfigTest() {
891         BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
892         ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
893
894         WorkflowResourceIds resourceIdsActivateVfModule = new WorkflowResourceIds();
895         resourceIdsActivateVfModule.setServiceInstanceId("test-service-inbstance-id");
896         resourceIdsActivateVfModule.setVnfId("test-vnf-id");
897         resourceIdsActivateVfModule.setVfModuleId("test-vf-module-id");
898         resourceIdsActivateVfModule.setConfigurationId("");
899
900         RequestDetails requestDetails = new RequestDetails();
901
902         ebbActivateVfModule.setApiVersion("7");
903         ebbActivateVfModule.setaLaCarte(true);
904         ebbActivateVfModule.setRequestAction("createInstance");
905         ebbActivateVfModule.setVnfType("test-vnf-type");
906         ebbActivateVfModule.setRequestId("f6c00ae2-a205-4cbd-b055-02e553efde12");
907         ebbActivateVfModule.setRequestDetails(requestDetails);
908         ebbActivateVfModule.setWorkflowResourceIds(resourceIdsActivateVfModule);
909
910         ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
911         configurationResourceKeys.setCvnfcCustomizationUUID("07d64cd2-4427-4156-b11d-d14b96b3e4cb");
912         configurationResourceKeys.setVfModuleCustomizationUUID("50b61075-6ebb-4aab-a9fc-bedad9a2aa76");
913         configurationResourceKeys.setVnfResourceCustomizationUUID("a1d0e36e-34a9-431b-b5ba-4bbb72f63c7c");
914         configurationResourceKeys.setVnfcName("rdm54bvbgw5001vm018pim001");
915
916         ExecuteBuildingBlock ebbAddFabricConfig =
917                 workflowActionBBTasks.getExecuteBBForConfig("AddFabricConfigurationBB", ebbActivateVfModule,
918                         "cc7e12f9-967c-4362-8d14-e5b2bf0608a4", configurationResourceKeys);
919
920         assertEquals("7", ebbAddFabricConfig.getApiVersion());
921         assertTrue(ebbAddFabricConfig.isaLaCarte());
922         assertEquals("createInstance", ebbAddFabricConfig.getRequestAction());
923         assertEquals("test-vnf-type", ebbAddFabricConfig.getVnfType());
924         assertEquals("f6c00ae2-a205-4cbd-b055-02e553efde12", ebbAddFabricConfig.getRequestId());
925         assertEquals(requestDetails, ebbAddFabricConfig.getRequestDetails());
926         assertEquals("cc7e12f9-967c-4362-8d14-e5b2bf0608a4",
927                 ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId());
928         assertEquals("test-service-inbstance-id", ebbAddFabricConfig.getWorkflowResourceIds().getServiceInstanceId());
929         assertEquals("test-vnf-id", ebbAddFabricConfig.getWorkflowResourceIds().getVnfId());
930         assertEquals("test-vf-module-id", ebbAddFabricConfig.getWorkflowResourceIds().getVfModuleId());
931
932         assertThat(ebbAddFabricConfig.getConfigurationResourceKeys()).isEqualTo(configurationResourceKeys);
933         assertThat(ebbAddFabricConfig.getWorkflowResourceIds())
934                 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds());
935         assertThat(ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId())
936                 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds().getConfigurationId());
937     }
938
939     @Test
940     public void checkRetryStatusTest() {
941         String reqId = "reqId123";
942         execution.setVariable("mso-request-id", reqId);
943         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
944         doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
945         execution.setVariable("handlingCode", "Retry");
946         execution.setVariable("retryCount", 1);
947         execution.setVariable("gCurrentSequence", 1);
948         InfraActiveRequests req = new InfraActiveRequests();
949         doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
950         workflowActionBBTasks.checkRetryStatus(execution);
951         assertEquals(0, execution.getVariable("gCurrentSequence"));
952     }
953
954     @Test
955     public void checkRetryStatusTestExceededMaxRetries() {
956         String reqId = "reqId123";
957         execution.setVariable("mso-request-id", reqId);
958         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
959         doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
960         execution.setVariable("handlingCode", "Retry");
961         execution.setVariable("retryCount", 6);
962         execution.setVariable("gCurrentSequence", 1);
963         InfraActiveRequests req = new InfraActiveRequests();
964         doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
965         try {
966             workflowActionBBTasks.checkRetryStatus(execution);
967         } catch (BpmnError e) {
968             WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException");
969             assertEquals("Exceeded maximum retries. Ending flow with status Abort", exception.getErrorMessage());
970         }
971     }
972
973     @Test
974     public void checkRetryStatusNoRetryTest() {
975         String reqId = "reqId123";
976         execution.setVariable("mso-request-id", reqId);
977         execution.setVariable("retryCount", 3);
978         execution.setVariable("handlingCode", "Success");
979         execution.setVariable("gCurrentSequence", 1);
980         InfraActiveRequests req = new InfraActiveRequests();
981         doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
982         workflowActionBBTasks.checkRetryStatus(execution);
983         assertEquals(0, execution.getVariable("retryCount"));
984     }
985
986     @Test
987     public void updateInstanceId() {
988         String reqId = "req123";
989         String instanceId = "123123123";
990         execution.setVariable("mso-request-id", reqId);
991         execution.setVariable("resourceId", instanceId);
992         execution.setVariable("resourceType", WorkflowType.SERVICE);
993         doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
994         doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
995         workflowActionBBTasks.updateInstanceId(execution);
996         Mockito.verify(reqMock, Mockito.times(1)).setServiceInstanceId(instanceId);
997     }
998
999     @Test
1000     public void getConfigurationId() throws Exception {
1001         org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
1002         vnfc.setModelInvariantId("modelInvariantId");
1003         vnfc.setVnfcName("testVnfcName");
1004         List<Configuration> configurations = new ArrayList<>();
1005         org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
1006         configuration.setConfigurationId("configurationId");
1007         configuration.setModelCustomizationId("modelCustimizationId");
1008         configuration.setConfigurationName("testConfigurationName");
1009         configurations.add(configuration);
1010         doReturn(configurations.get(0).getConfigurationId()).when(workflowActionBBTasks).getConfigurationId(vnfc);
1011         assertEquals(workflowActionBBTasks.getConfigurationId(vnfc), "configurationId");
1012     }
1013
1014     @Test
1015     public void setServiceInstanceNameTest() {
1016         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1017         WorkflowType resourceType = WorkflowType.SERVICE;
1018         InfraActiveRequests request = new InfraActiveRequests();
1019         ServiceInstance service = new ServiceInstance();
1020         service.setServiceInstanceName("serviceInstanceName");
1021         doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById(resourceId);
1022
1023         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1024         assertEquals("serviceInstanceName", request.getServiceInstanceName());
1025     }
1026
1027     @Test
1028     public void setVnfNameTest() {
1029         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1030         WorkflowType resourceType = WorkflowType.VNF;
1031         InfraActiveRequests request = new InfraActiveRequests();
1032         GenericVnf vnf = new GenericVnf();
1033         vnf.setVnfName("vnfName");
1034         doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf(resourceId);
1035
1036         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1037         assertEquals("vnfName", request.getVnfName());
1038     }
1039
1040     @Test
1041     public void setVfModuleNameTest() {
1042         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1043         WorkflowType resourceType = WorkflowType.VFMODULE;
1044         InfraActiveRequests request = new InfraActiveRequests();
1045         request.setVnfId("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e");
1046         VfModule vfModule = new VfModule();
1047         vfModule.setVfModuleName("vfModuleName");
1048         doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e", resourceId);
1049
1050         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1051         assertEquals("vfModuleName", request.getVfModuleName());
1052     }
1053
1054     @Test
1055     public void setNetworkNameTest() {
1056         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1057         WorkflowType resourceType = WorkflowType.NETWORK;
1058         InfraActiveRequests request = new InfraActiveRequests();
1059         L3Network network = new L3Network();
1060         network.setNetworkName("networkName");
1061         doReturn(network).when(bbSetupUtils).getAAIL3Network(resourceId);
1062
1063         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1064         assertEquals("networkName", request.getNetworkName());
1065     }
1066
1067     @Test
1068     public void setConfigurationNameTest() {
1069         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1070         WorkflowType resourceType = WorkflowType.CONFIGURATION;
1071         InfraActiveRequests request = new InfraActiveRequests();
1072         Configuration configuration = new Configuration();
1073         configuration.setConfigurationName("configurationName");
1074         doReturn(configuration).when(bbSetupUtils).getAAIConfiguration(resourceId);
1075
1076         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1077         assertEquals("configurationName", request.getConfigurationName());
1078     }
1079
1080     @Test
1081     public void setInstanceGroupNameTest() {
1082         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1083         WorkflowType resourceType = WorkflowType.INSTANCE_GROUP;
1084         InfraActiveRequests request = new InfraActiveRequests();
1085         InstanceGroup instanceGroup = new InstanceGroup();
1086         instanceGroup.setInstanceGroupName("instanceGroupName");
1087         doReturn(instanceGroup).when(bbSetupUtils).getAAIInstanceGroup(resourceId);
1088
1089         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1090         assertEquals("instanceGroupName", request.getInstanceGroupName());
1091     }
1092
1093     @Test
1094     public void setVolumeGroupNameTest() {
1095         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1096         WorkflowType resourceType = WorkflowType.VOLUMEGROUP;
1097         InfraActiveRequests request = new InfraActiveRequests();
1098         request.setVnfId("4aa72c90-21eb-4465-8847-997e27af6c3e");
1099         VolumeGroup volumeGroup = new VolumeGroup();
1100         volumeGroup.setVolumeGroupName("volumeGroupName");
1101         Optional<VolumeGroup> returnVolumeGroup = Optional.of(volumeGroup);
1102
1103         doReturn(returnVolumeGroup).when(bbSetupUtils).getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
1104         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1105
1106         assertEquals("volumeGroupName", request.getVolumeGroupName());
1107     }
1108
1109     private void prepareDelegateExecution() {
1110         execution.setVariable("mso-request-id", SAMPLE_MSO_REQUEST_ID);
1111         execution.setVariable("requestAction", SAMPLE_REQUEST_ACTION);
1112         execution.setVariable("gCurrentSequence", SAMPLE_SEQUENCE);
1113         execution.setVariable("homing", false);
1114         execution.setVariable("calledHoming", false);
1115     }
1116
1117     private List<BuildingBlockRollback> getRollbackBuildingBlockList() {
1118         List<BuildingBlockRollback> rollbackBBList = Collections.unmodifiableList(Arrays.asList(
1119                 new BuildingBlockRollback(1, "ActivateNetworkBB", null, "DeactivateNetworkBB", null),
1120                 new BuildingBlockRollback(2, "ActivatePnfBB", null, "DeactivatePnfBB", null),
1121                 new BuildingBlockRollback(3, "ActivateServiceInstanceBB", null, "DeactivateServiceInstanceBB", null),
1122                 new BuildingBlockRollback(4, "ActivateVfModuleBB", null, "DeactivateVfModuleBB", null),
1123                 new BuildingBlockRollback(5, "ActivateVnfBB", null, "DeactivateVnfBB", null),
1124                 new BuildingBlockRollback(6, "ActivateVolumeGroupBB", null, "DeactivateVolumeGroupBB", null),
1125                 new BuildingBlockRollback(7, "AssignNetworkBB", null, "UnassignNetworkBB", null),
1126                 new BuildingBlockRollback(8, "AssignServiceInstanceBB", null, "UnassignServiceInstanceBB", null),
1127                 new BuildingBlockRollback(9, "AssignVfModuleBB", null, "UnassignVfModuleBB", null),
1128                 new BuildingBlockRollback(10, "AssignVnfBB", null, "UnassignVnfBB", null),
1129                 new BuildingBlockRollback(11, "AssignVolumeGroupBB", null, "UnassignVolumeGroupBB", null),
1130                 new BuildingBlockRollback(12, "ControllerExecutionBB", "config-assign", "ControllerExecutionBB",
1131                         "config-unassign"),
1132                 new BuildingBlockRollback(13, "ControllerExecutionBB", "config-deploy", "ControllerExecutionBB",
1133                         "config-undeploy"),
1134                 new BuildingBlockRollback(14, "ControllerExecutionBB", "service-config-deploy", "ControllerExecutionBB",
1135                         "service-config-undeploy"),
1136                 new BuildingBlockRollback(15, "CreateNetworkBB", null, "DeleteNetworkBB", null),
1137                 new BuildingBlockRollback(16, "CreateNetworkCollectionBB", null, "DeleteNetworkCollectionBB", null),
1138                 new BuildingBlockRollback(17, "CreateVfModuleBB", null, "DeleteVfModuleBB", null),
1139                 new BuildingBlockRollback(18, "CreateVolumeGroupBB", null, "DeleteVolumeGroupBB", null),
1140                 new BuildingBlockRollback(19, "VNFSetInMaintFlagActivity", null, "VNFUnsetInMaintFlagActivity", null),
1141                 new BuildingBlockRollback(20, "VNFSetClosedLoopDisabledFlagActivity", null,
1142                         "VNFUnsetClosedLoopDisabledFlagActivity", null),
1143                 new BuildingBlockRollback(21, "VNFLockActivity", null, "VNFUnlockActivity", null),
1144                 new BuildingBlockRollback(22, "VNFStopActivity", null, "VNFStartActivity", null),
1145                 new BuildingBlockRollback(23, "VNFQuiesceTrafficActivity", null, "VNFResumeTrafficActivity", null),
1146                 new BuildingBlockRollback(24, "EtsiVnfInstantiateBB", null, "EtsiVnfDeleteBB", null),
1147                 // AddFabricConfigurationBB this does not seem to be present as a bpmn in Guilin
1148                 new BuildingBlockRollback(25, "AddFabricConfigurationBB", null, "DeleteFabricConfigurationBB", null)));
1149         return rollbackBBList;
1150     }
1151
1152 }