Merge "update the known issues"
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / workflow / tasks / WorkflowActionBBTasksTest.java
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 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;
76
77 public class WorkflowActionBBTasksTest extends BaseTaskTest {
78
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 = "";
83     @Mock
84     protected WorkflowAction workflowAction;
85
86     @Mock
87     protected WorkflowActionBBFailure workflowActionBBFailure;
88
89     @InjectMocks
90     @Spy
91     protected WorkflowActionBBTasks workflowActionBBTasks;
92
93     @Mock
94     InfraActiveRequests reqMock;
95
96     private DelegateExecution execution;
97
98     @Mock
99     protected Environment environment;
100
101     @Mock
102     private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
103
104     @Rule
105     public ExpectedException thrown = ExpectedException.none();
106
107     @Mock
108     private DelegateExecution mockExecution;
109
110     @Before
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);
118     }
119
120     @Test
121     public void selectBBTest() {
122         String vnfCustomizationUUID = "1234567";
123         String modelUuid = "1234567";
124         prepareDelegateExecution();
125         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
126
127         BuildingBlock buildingBlock =
128                 new BuildingBlock().setBpmnFlowName("ConfigAssignVnfBB").setKey(vnfCustomizationUUID);
129         RequestDetails rd = new RequestDetails();
130         ModelInfo mi = new ModelInfo();
131         mi.setModelUuid(modelUuid);
132         rd.setModelInfo(mi);
133         ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
134         flowsToExecute.add(ebb);
135
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);
146
147         execution.setVariable("flowsToExecute", flowsToExecute);
148         workflowActionBBTasks.selectBB(execution);
149         boolean success = (boolean) execution.getVariable("completed");
150         int currentSequence = (int) execution.getVariable("gCurrentSequence");
151         assertTrue(success);
152         assertEquals(1, currentSequence);
153     }
154
155     @Test
156     public void select2BBTest() {
157         String vnfCustomizationUUID = "1234567";
158         String modelUuid = "1234567";
159
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);
167         rd.setModelInfo(mi);
168         ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
169         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
170
171         flowsToExecute.add(ebb);
172
173         List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
174         VnfResourceCustomization vrc = new VnfResourceCustomization();
175
176         vrc.setSkipPostInstConf(false);
177         vrc.setModelCustomizationUUID(vnfCustomizationUUID);
178         vnfResourceCustomizations.add(vrc);
179         GenericVnf genericVnf = new GenericVnf();
180         genericVnf.setModelCustomizationId(vnfCustomizationUUID);
181
182         doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
183         doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
184                 vnfResourceCustomizations);
185
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);
193     }
194
195     @Test
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"));
208     }
209
210     @Test
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);
220
221         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
222         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
223         flowsToExecute.add(ebb2);
224
225         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
226         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
227         flowsToExecute.add(ebb3);
228
229         execution.setVariable("flowsToExecute", flowsToExecute);
230         execution.setVariable("gCurrentSequence", 3);
231         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
232
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"));
239     }
240
241     @Test
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);
251
252         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
253         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
254         flowsToExecute.add(ebb2);
255
256         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
257         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
258         flowsToExecute.add(ebb3);
259
260         execution.setVariable("flowsToExecute", flowsToExecute);
261         execution.setVariable("gCurrentSequence", 2);
262         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
263
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"));
270     }
271
272     @Test
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);
282
283         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateNetworkCollectionBB");
284         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
285         flowsToExecute.add(ebb2);
286
287         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("AssignNetworkBB");
288         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
289         flowsToExecute.add(ebb3);
290
291         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("CreateNetworkBB");
292         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
293         flowsToExecute.add(ebb4);
294
295         execution.setVariable("flowsToExecute", flowsToExecute);
296         execution.setVariable("gCurrentSequence", 3);
297         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
298
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"));
305     }
306
307     @Test
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<>();
314
315         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
316         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
317         flowsToExecute.add(ebb1);
318
319         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
320         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
321         flowsToExecute.add(ebb2);
322
323         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
324         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
325         flowsToExecute.add(ebb3);
326
327         execution.setVariable("flowsToExecute", flowsToExecute);
328         execution.setVariable("gCurrentSequence", 2);
329
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());
335     }
336
337     @Test
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);
347
348         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
349         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
350         flowsToExecute.add(ebb2);
351
352         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
353         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
354         flowsToExecute.add(ebb3);
355
356
357         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("ChangeModelVnfBB");
358         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
359         flowsToExecute.add(ebb4);
360
361         BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("ChangeModelServiceInstanceBB");
362         ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
363         flowsToExecute.add(ebb5);
364
365         execution.setVariable("flowsToExecute", flowsToExecute);
366         execution.setVariable("gCurrentSequence", 5);
367         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
368
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"));
374     }
375
376     @Test
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<>();
383
384         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
385         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
386         flowsToExecute.add(ebb1);
387
388         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
389         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
390         flowsToExecute.add(ebb2);
391
392         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
393         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
394         flowsToExecute.add(ebb3);
395
396         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
397         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
398         flowsToExecute.add(ebb4);
399
400         execution.setVariable("flowsToExecute", flowsToExecute);
401         execution.setVariable("gCurrentSequence", 4);
402
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());
410
411     }
412
413     @Test
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<>();
420
421         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
422         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
423         flowsToExecute.add(ebb1);
424
425         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
426         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
427         flowsToExecute.add(ebb2);
428
429         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
430         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
431         flowsToExecute.add(ebb3);
432
433         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
434         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
435         flowsToExecute.add(ebb4);
436
437         execution.setVariable("flowsToExecute", flowsToExecute);
438         execution.setVariable("gCurrentSequence", 4);
439
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());
446
447     }
448
449     @Test
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<>();
456
457         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
458         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
459         flowsToExecute.add(ebb1);
460
461         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
462         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
463         flowsToExecute.add(ebb2);
464
465         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
466         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
467         flowsToExecute.add(ebb3);
468
469         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
470         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
471         flowsToExecute.add(ebb4);
472
473         execution.setVariable("flowsToExecute", flowsToExecute);
474         execution.setVariable("gCurrentSequence", 4);
475
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());
481     }
482
483     @Test
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);
493
494         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
495         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
496         flowsToExecute.add(ebb2);
497
498         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
499         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
500         flowsToExecute.add(ebb3);
501
502         execution.setVariable("flowsToExecute", flowsToExecute);
503         execution.setVariable("gCurrentSequence", 3);
504
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());
510     }
511
512     @Test
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);
522
523         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
524         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
525         flowsToExecute.add(ebb2);
526
527         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
528         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
529         flowsToExecute.add(ebb3);
530
531         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
532         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
533         flowsToExecute.add(ebb4);
534
535         BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
536         ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
537         flowsToExecute.add(ebb5);
538
539         BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFLockActivity");
540         ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
541         flowsToExecute.add(ebb6);
542
543         BuildingBlock buildingBlock7 = new BuildingBlock().setBpmnFlowName("VNFUpgradePreCheckActivity");
544         ExecuteBuildingBlock ebb7 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock7);
545         flowsToExecute.add(ebb7);
546
547         BuildingBlock buildingBlock8 = new BuildingBlock().setBpmnFlowName("VNFQuiesceTrafficActivity");
548         ExecuteBuildingBlock ebb8 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock8);
549         flowsToExecute.add(ebb8);
550
551         BuildingBlock buildingBlock9 = new BuildingBlock().setBpmnFlowName("VNFStopActivity");
552         ExecuteBuildingBlock ebb9 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock9);
553         flowsToExecute.add(ebb9);
554
555         BuildingBlock buildingBlock10 = new BuildingBlock().setBpmnFlowName("VNFSnapShotActivity");
556         ExecuteBuildingBlock ebb10 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock10);
557         flowsToExecute.add(ebb10);
558
559         execution.setVariable("flowsToExecute", flowsToExecute);
560         execution.setVariable("gCurrentSequence", 10);
561
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());
571     }
572
573     @Test
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);
583
584         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
585         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
586         flowsToExecute.add(ebb2);
587
588         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
589         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
590         flowsToExecute.add(ebb3);
591
592         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
593         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
594         flowsToExecute.add(ebb4);
595
596         BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
597         ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
598         flowsToExecute.add(ebb5);
599
600         BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFHealthCheckActivity");
601         ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
602         flowsToExecute.add(ebb6);
603
604         execution.setVariable("flowsToExecute", flowsToExecute);
605         execution.setVariable("gCurrentSequence", 6);
606
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());
613     }
614
615     @Test
616     public void postProcessingExecuteBBActivateVfModuleNotReplaceInstanceTest() throws CloneNotSupportedException {
617         WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
618         workflowResourceIds.setServiceInstanceId("1");
619         workflowResourceIds.setVnfId("1");
620
621         BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
622         ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
623         ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
624         ebbActivateVfModule.setResourceId("1");
625
626         ServiceInstance service = new ServiceInstance();
627         service.setServiceInstanceName("name");
628         service.setModelVersionId("1");
629         doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
630
631         GenericVnf vnf = new GenericVnf();
632         vnf.setVnfName("name");
633         vnf.setModelCustomizationId("1");
634         doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
635
636         VfModule vfModule = new VfModule();
637         vfModule.setVfModuleName("name");
638         vfModule.setModelCustomizationId("1");
639         doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
640
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");
646         vnfcs.add(vnfc);
647         doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
648
649         CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
650         ConfigurationResource configuration = new ConfigurationResource();
651         configuration.setToscaNodeType("FabricConfiguration");
652         configuration.setModelUUID("1");
653         vfModuleCustomization.setConfigurationResource(configuration);
654
655         doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
656
657         prepareDelegateExecution();
658         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
659         flowsToExecute.add(ebbActivateVfModule);
660
661         execution.setVariable("requestAction", "createInstance");
662         execution.setVariable("completed", true);
663
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());
672         assertEquals("2",
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());
678     }
679
680     @Test
681     public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasConfigurationTest()
682             throws CloneNotSupportedException {
683
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");
691
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);
698
699         ServiceInstance service = new ServiceInstance();
700         service.setServiceInstanceName("name");
701         service.setModelVersionId("1");
702         doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
703
704         GenericVnf vnf = new GenericVnf();
705         vnf.setVnfName("name");
706         vnf.setModelCustomizationId("1");
707         doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
708
709         VfModule vfModule = new VfModule();
710         vfModule.setVfModuleName("name");
711         vfModule.setModelCustomizationId("1");
712         doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
713
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");
719         vnfcs.add(vnfc);
720         doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
721
722         CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
723         ConfigurationResource configuration = new ConfigurationResource();
724         configuration.setToscaNodeType("FabricConfiguration");
725         configuration.setModelUUID("1");
726         vfModuleCustomization.setConfigurationResource(configuration);
727
728         doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
729
730         prepareDelegateExecution();
731         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
732         flowsToExecute.add(ebbActivateVfModule);
733         flowsToExecute.add(ebbAddFabric);
734
735         ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
736         ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
737         ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
738
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());
746         assertEquals("2",
747                 ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
748                         .getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys()
749                                 .getCvnfcCustomizationUUID());
750     }
751
752     @Test
753     public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasNoConfigurationTest()
754             throws CloneNotSupportedException {
755
756         WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
757         workflowResourceIds.setServiceInstanceId("1");
758         workflowResourceIds.setVnfId("1");
759
760         BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
761         ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
762         ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
763         ebbActivateVfModule.setResourceId("1");
764
765         ServiceInstance service = new ServiceInstance();
766         service.setServiceInstanceName("name");
767         service.setModelVersionId("1");
768         doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
769
770         GenericVnf vnf = new GenericVnf();
771         vnf.setVnfName("name");
772         vnf.setModelCustomizationId("1");
773         doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
774
775         VfModule vfModule = new VfModule();
776         vfModule.setVfModuleName("name");
777         vfModule.setModelCustomizationId("1");
778         doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
779
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");
785         vnfcs.add(vnfc);
786         doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
787
788         CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
789         ConfigurationResource configuration = new ConfigurationResource();
790         configuration.setToscaNodeType("FabricConfiguration");
791         configuration.setModelUUID("1");
792         vfModuleCustomization.setConfigurationResource(configuration);
793
794         doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
795
796         prepareDelegateExecution();
797         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
798         flowsToExecute.add(ebbActivateVfModule);
799
800         ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
801         ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
802         ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
803
804         execution.setVariable("requestAction", "replaceInstance");
805         execution.setVariable("completed", true);
806
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"));
811     }
812
813
814
815     @Test
816     public void getExecuteBBForConfigTest() throws CloneNotSupportedException {
817         BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
818         ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
819
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("");
825
826         RequestDetails requestDetails = new RequestDetails();
827
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);
835
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");
841
842         ExecuteBuildingBlock ebbAddFabricConfig =
843                 workflowActionBBTasks.getExecuteBBForConfig("AddFabricConfigurationBB", ebbActivateVfModule,
844                         "cc7e12f9-967c-4362-8d14-e5b2bf0608a4", configurationResourceKeys);
845
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());
857
858         assertThat(ebbAddFabricConfig.getConfigurationResourceKeys()).isEqualTo(configurationResourceKeys);
859         assertThat(ebbAddFabricConfig.getWorkflowResourceIds())
860                 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds());
861         assertThat(ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId())
862                 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds().getConfigurationId());
863     }
864
865     @Test
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"));
878     }
879
880     @Test
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);
891         try {
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());
896         }
897     }
898
899     @Test
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"));
910     }
911
912     @Test
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);
923     }
924
925     @Test
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");
938     }
939
940     @Test
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);
948
949         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
950         assertEquals("serviceInstanceName", request.getServiceInstanceName());
951     }
952
953     @Test
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);
961
962         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
963         assertEquals("vnfName", request.getVnfName());
964     }
965
966     @Test
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);
975
976         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
977         assertEquals("vfModuleName", request.getVfModuleName());
978     }
979
980     @Test
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);
988
989         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
990         assertEquals("networkName", request.getNetworkName());
991     }
992
993     @Test
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);
1001
1002         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1003         assertEquals("configurationName", request.getConfigurationName());
1004     }
1005
1006     @Test
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);
1014
1015         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1016         assertEquals("instanceGroupName", request.getInstanceGroupName());
1017     }
1018
1019     @Test
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);
1028
1029         doReturn(returnVolumeGroup).when(bbSetupUtils).getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
1030         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1031
1032         assertEquals("volumeGroupName", request.getVolumeGroupName());
1033     }
1034
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);
1041     }
1042 }