Merge "Fix Parsing Of Etsi Catalog Notifications"
[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.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.Mockito;
35 import org.mockito.Spy;
36 import org.onap.aai.domain.yang.Configuration;
37 import org.onap.aai.domain.yang.GenericVnf;
38 import org.onap.aai.domain.yang.InstanceGroup;
39 import org.onap.aai.domain.yang.L3Network;
40 import org.onap.aai.domain.yang.ServiceInstance;
41 import org.onap.aai.domain.yang.VfModule;
42 import org.onap.aai.domain.yang.VolumeGroup;
43 import org.onap.so.bpmn.BaseTaskTest;
44 import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner;
45 import org.onap.so.bpmn.core.WorkflowException;
46 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
47 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
48 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
49 import org.onap.so.db.request.beans.InfraActiveRequests;
50 import org.onap.so.serviceinstancebeans.ModelInfo;
51 import org.onap.so.serviceinstancebeans.RequestDetails;
52 import org.springframework.core.env.Environment;
53 import java.util.ArrayList;
54 import java.util.List;
55 import java.util.Optional;
56 import static org.junit.Assert.assertEquals;
57 import static org.junit.Assert.assertTrue;
58 import static org.mockito.ArgumentMatchers.anyObject;
59 import static org.mockito.ArgumentMatchers.anyString;
60 import static org.mockito.ArgumentMatchers.isA;
61 import static org.mockito.Mockito.doNothing;
62 import static org.mockito.Mockito.doReturn;
63 import static org.mockito.Mockito.when;
64
65 public class WorkflowActionBBTasksTest extends BaseTaskTest {
66
67     private static final String SAMPLE_MSO_REQUEST_ID = "00f704ca-c5e5-4f95-a72c-6889db7b0688";
68     private static final String SAMPLE_REQUEST_ACTION = "Delete-Network-Collection";
69     private static final int SAMPLE_SEQUENCE = 0;
70     @Mock
71     protected WorkflowAction workflowAction;
72
73     @Mock
74     protected WorkflowActionBBFailure workflowActionBBFailure;
75
76     @InjectMocks
77     @Spy
78     protected WorkflowActionBBTasks workflowActionBBTasks;
79
80     @Mock
81     InfraActiveRequests reqMock;
82
83     private DelegateExecution execution;
84
85     @Mock
86     protected Environment environment;
87
88     @Mock
89     private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
90
91     @Rule
92     public ExpectedException thrown = ExpectedException.none();
93
94     @Before
95     public void before() throws Exception {
96         execution = new DelegateExecutionFake();
97         ServiceInstance servInstance = new ServiceInstance();
98         servInstance.setServiceInstanceId("TEST");
99         when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance);
100         workflowAction.setBbInputSetupUtils(bbSetupUtils);
101         workflowAction.setBbInputSetup(bbInputSetup);
102     }
103
104     @Test
105     public void selectBBTest() {
106         String vnfCustomizationUUID = "1234567";
107         String modelUuid = "1234567";
108         prepareDelegateExecution();
109         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
110
111         BuildingBlock buildingBlock =
112                 new BuildingBlock().setBpmnFlowName("ConfigAssignVnfBB").setKey(vnfCustomizationUUID);
113         RequestDetails rd = new RequestDetails();
114         ModelInfo mi = new ModelInfo();
115         mi.setModelUuid(modelUuid);
116         rd.setModelInfo(mi);
117         ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
118         flowsToExecute.add(ebb);
119
120         List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
121         VnfResourceCustomization vrc = new VnfResourceCustomization();
122         vrc.setSkipPostInstConf(false);
123         vrc.setModelCustomizationUUID(vnfCustomizationUUID);
124         vnfResourceCustomizations.add(vrc);
125         GenericVnf genericVnf = new GenericVnf();
126         genericVnf.setModelCustomizationId(vnfCustomizationUUID);
127         doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
128         doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
129                 vnfResourceCustomizations);
130
131         execution.setVariable("flowsToExecute", flowsToExecute);
132         workflowActionBBTasks.selectBB(execution);
133         boolean success = (boolean) execution.getVariable("completed");
134         int currentSequence = (int) execution.getVariable("gCurrentSequence");
135         assertTrue(success);
136         assertEquals(1, currentSequence);
137     }
138
139     @Test
140     public void select2BBTest() {
141         String vnfCustomizationUUID = "1234567";
142         String modelUuid = "1234567";
143
144         prepareDelegateExecution();
145         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
146         BuildingBlock buildingBlock =
147                 new BuildingBlock().setBpmnFlowName("ConfigDeployVnfBB").setKey(vnfCustomizationUUID);
148         RequestDetails rd = new RequestDetails();
149         ModelInfo mi = new ModelInfo();
150         mi.setModelUuid(modelUuid);
151         rd.setModelInfo(mi);
152         ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
153         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
154
155         flowsToExecute.add(ebb);
156
157         List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
158         VnfResourceCustomization vrc = new VnfResourceCustomization();
159
160         vrc.setSkipPostInstConf(false);
161         vrc.setModelCustomizationUUID(vnfCustomizationUUID);
162         vnfResourceCustomizations.add(vrc);
163         GenericVnf genericVnf = new GenericVnf();
164         genericVnf.setModelCustomizationId(vnfCustomizationUUID);
165
166         doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
167         doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
168                 vnfResourceCustomizations);
169
170         flowsToExecute.add(ebb2);
171         execution.setVariable("flowsToExecute", flowsToExecute);
172         workflowActionBBTasks.selectBB(execution);
173         boolean success = (boolean) execution.getVariable("completed");
174         int currentSequence = (int) execution.getVariable("gCurrentSequence");
175         assertEquals(false, success);
176         assertEquals(1, currentSequence);
177     }
178
179     @Test
180     public void updateRequestStatusToCompleteTest() {
181         String reqId = "reqId123";
182         execution.setVariable("mso-request-id", reqId);
183         execution.setVariable("requestAction", "createInstance");
184         execution.setVariable("resourceName", "Service");
185         execution.setVariable("aLaCarte", true);
186         InfraActiveRequests req = new InfraActiveRequests();
187         doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
188         doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
189         workflowActionBBTasks.updateRequestStatusToComplete(execution);
190         assertEquals("ALaCarte-Service-createInstance request was executed correctly.",
191                 execution.getVariable("finalStatusMessage"));
192     }
193
194     @Test
195     public void rollbackExecutionPathTest() {
196         execution.setVariable("handlingCode", "Rollback");
197         execution.setVariable("isRollback", false);
198         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
199         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
200         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
201         flowsToExecute.add(ebb1);
202
203         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
204         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
205         flowsToExecute.add(ebb2);
206
207         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
208         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
209         flowsToExecute.add(ebb3);
210
211         execution.setVariable("flowsToExecute", flowsToExecute);
212         execution.setVariable("gCurrentSequence", 3);
213         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
214
215         workflowActionBBTasks.rollbackExecutionPath(execution);
216         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
217         assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeactivateVfModuleBB");
218         assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
219         assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
220         assertEquals(0, execution.getVariable("gCurrentSequence"));
221     }
222
223     @Test
224     public void rollbackExecutionPathUnfinishedFlowTest() {
225         execution.setVariable("handlingCode", "Rollback");
226         execution.setVariable("isRollback", false);
227         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
228         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
229         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
230         flowsToExecute.add(ebb1);
231
232         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
233         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
234         flowsToExecute.add(ebb2);
235
236         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
237         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
238         flowsToExecute.add(ebb3);
239
240         execution.setVariable("flowsToExecute", flowsToExecute);
241         execution.setVariable("gCurrentSequence", 2);
242         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
243
244         workflowActionBBTasks.rollbackExecutionPath(execution);
245         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
246         assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
247         assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
248         assertEquals(0, execution.getVariable("gCurrentSequence"));
249         assertEquals(0, execution.getVariable("retryCount"));
250     }
251
252     @Test
253     public void rollbackExecutionTest() {
254         execution.setVariable("handlingCode", "Rollback");
255         execution.setVariable("isRollback", false);
256         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
257         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB");
258         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
259         flowsToExecute.add(ebb1);
260
261         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateNetworkCollectionBB");
262         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
263         flowsToExecute.add(ebb2);
264
265         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("AssignNetworkBB");
266         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
267         flowsToExecute.add(ebb3);
268
269         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("CreateNetworkBB");
270         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
271         flowsToExecute.add(ebb4);
272
273         execution.setVariable("flowsToExecute", flowsToExecute);
274         execution.setVariable("gCurrentSequence", 3);
275         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
276
277         workflowActionBBTasks.rollbackExecutionPath(execution);
278         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
279         assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "UnassignNetworkBB");
280         assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteNetworkCollectionBB");
281         assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignServiceInstanceBB");
282         assertEquals(0, execution.getVariable("gCurrentSequence"));
283     }
284
285     @Test
286     public void rollbackExecutionRollbackToAssignedTest() {
287         execution.setVariable("isRollback", false);
288         execution.setVariable("handlingCode", "RollbackToAssigned");
289         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
290
291         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
292         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
293         flowsToExecute.add(ebb1);
294
295         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
296         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
297         flowsToExecute.add(ebb2);
298
299         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
300         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
301         flowsToExecute.add(ebb3);
302
303         execution.setVariable("flowsToExecute", flowsToExecute);
304         execution.setVariable("gCurrentSequence", 2);
305
306         workflowActionBBTasks.rollbackExecutionPath(execution);
307         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
308         assertEquals("DeleteVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
309         assertEquals(0, execution.getVariable("gCurrentSequence"));
310         assertEquals(1, ebbs.size());
311     }
312
313     @Test
314     public void rollbackExecutionRollbackToAssignedWithFabricTest() {
315         execution.setVariable("isRollback", false);
316         execution.setVariable("handlingCode", "RollbackToAssigned");
317         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
318
319         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
320         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
321         flowsToExecute.add(ebb1);
322
323         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
324         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
325         flowsToExecute.add(ebb2);
326
327         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
328         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
329         flowsToExecute.add(ebb3);
330
331         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
332         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
333         flowsToExecute.add(ebb4);
334
335         execution.setVariable("flowsToExecute", flowsToExecute);
336         execution.setVariable("gCurrentSequence", 4);
337
338         workflowActionBBTasks.rollbackExecutionPath(execution);
339         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
340         assertEquals(0, execution.getVariable("gCurrentSequence"));
341         assertEquals(3, ebbs.size());
342         assertEquals("DeleteFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
343         assertEquals("DeactivateVfModuleBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
344         assertEquals("DeleteVfModuleBB", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
345
346     }
347
348     @Test
349     public void rollbackExecutionRollbackToCreatedTest() {
350         execution.setVariable("isRollback", false);
351         execution.setVariable("handlingCode", "RollbackToCreated");
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         execution.setVariable("flowsToExecute", flowsToExecute);
366         execution.setVariable("gCurrentSequence", 3);
367
368         workflowActionBBTasks.rollbackExecutionPath(execution);
369         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
370         assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
371         assertEquals(0, execution.getVariable("gCurrentSequence"));
372         assertEquals(1, ebbs.size());
373     }
374
375     @Test
376     public void rollbackExecutionRollbackInPlaceSoftwareUpdateTest() {
377         execution.setVariable("isRollback", false);
378         execution.setVariable("handlingCode", "Rollback");
379         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
380         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
381         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
382         flowsToExecute.add(ebb1);
383
384         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
385         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
386         flowsToExecute.add(ebb2);
387
388         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
389         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
390         flowsToExecute.add(ebb3);
391
392         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
393         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
394         flowsToExecute.add(ebb4);
395
396         BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
397         ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
398         flowsToExecute.add(ebb5);
399
400         BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFLockActivity");
401         ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
402         flowsToExecute.add(ebb6);
403
404         BuildingBlock buildingBlock7 = new BuildingBlock().setBpmnFlowName("VNFUpgradePreCheckActivity");
405         ExecuteBuildingBlock ebb7 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock7);
406         flowsToExecute.add(ebb7);
407
408         BuildingBlock buildingBlock8 = new BuildingBlock().setBpmnFlowName("VNFQuiesceTrafficActivity");
409         ExecuteBuildingBlock ebb8 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock8);
410         flowsToExecute.add(ebb8);
411
412         BuildingBlock buildingBlock9 = new BuildingBlock().setBpmnFlowName("VNFStopActivity");
413         ExecuteBuildingBlock ebb9 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock9);
414         flowsToExecute.add(ebb9);
415
416         BuildingBlock buildingBlock10 = new BuildingBlock().setBpmnFlowName("VNFSnapShotActivity");
417         ExecuteBuildingBlock ebb10 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock10);
418         flowsToExecute.add(ebb10);
419
420         execution.setVariable("flowsToExecute", flowsToExecute);
421         execution.setVariable("gCurrentSequence", 10);
422
423         workflowActionBBTasks.rollbackExecutionPath(execution);
424         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
425         assertEquals("VNFStartActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
426         assertEquals("VNFResumeTrafficActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
427         assertEquals("VNFUnlockActivity", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
428         assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(3).getBuildingBlock().getBpmnFlowName());
429         assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(4).getBuildingBlock().getBpmnFlowName());
430         assertEquals(0, execution.getVariable("gCurrentSequence"));
431         assertEquals(5, ebbs.size());
432     }
433
434     @Test
435     public void rollbackExecutionRollbackConfigModifyTest() {
436         execution.setVariable("isRollback", false);
437         execution.setVariable("handlingCode", "Rollback");
438         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
439         BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
440         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
441         flowsToExecute.add(ebb1);
442
443         BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
444         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
445         flowsToExecute.add(ebb2);
446
447         BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
448         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
449         flowsToExecute.add(ebb3);
450
451         BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
452         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
453         flowsToExecute.add(ebb4);
454
455         BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
456         ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
457         flowsToExecute.add(ebb5);
458
459         BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFHealthCheckActivity");
460         ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
461         flowsToExecute.add(ebb6);
462
463         execution.setVariable("flowsToExecute", flowsToExecute);
464         execution.setVariable("gCurrentSequence", 6);
465
466         workflowActionBBTasks.rollbackExecutionPath(execution);
467         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
468         assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
469         assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
470         assertEquals(0, execution.getVariable("gCurrentSequence"));
471         assertEquals(2, ebbs.size());
472     }
473
474
475     @Test
476     public void checkRetryStatusTest() {
477         String reqId = "reqId123";
478         execution.setVariable("mso-request-id", reqId);
479         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
480         doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
481         execution.setVariable("handlingCode", "Retry");
482         execution.setVariable("retryCount", 1);
483         execution.setVariable("gCurrentSequence", 1);
484         InfraActiveRequests req = new InfraActiveRequests();
485         doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
486         workflowActionBBTasks.checkRetryStatus(execution);
487         assertEquals(0, execution.getVariable("gCurrentSequence"));
488     }
489
490     @Test
491     public void checkRetryStatusTestExceededMaxRetries() {
492         String reqId = "reqId123";
493         execution.setVariable("mso-request-id", reqId);
494         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
495         doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
496         execution.setVariable("handlingCode", "Retry");
497         execution.setVariable("retryCount", 6);
498         execution.setVariable("gCurrentSequence", 1);
499         InfraActiveRequests req = new InfraActiveRequests();
500         doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
501         try {
502             workflowActionBBTasks.checkRetryStatus(execution);
503         } catch (BpmnError e) {
504             WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException");
505             assertEquals("Exceeded maximum retries. Ending flow with status Abort", exception.getErrorMessage());
506         }
507     }
508
509     @Test
510     public void checkRetryStatusNoRetryTest() {
511         String reqId = "reqId123";
512         execution.setVariable("mso-request-id", reqId);
513         execution.setVariable("retryCount", 3);
514         execution.setVariable("handlingCode", "Success");
515         execution.setVariable("gCurrentSequence", 1);
516         InfraActiveRequests req = new InfraActiveRequests();
517         doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
518         workflowActionBBTasks.checkRetryStatus(execution);
519         assertEquals(0, execution.getVariable("retryCount"));
520     }
521
522     @Test
523     public void updateInstanceId() {
524         String reqId = "req123";
525         String instanceId = "123123123";
526         execution.setVariable("mso-request-id", reqId);
527         execution.setVariable("resourceId", instanceId);
528         execution.setVariable("resourceType", WorkflowType.SERVICE);
529         doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
530         doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
531         workflowActionBBTasks.updateInstanceId(execution);
532         Mockito.verify(reqMock, Mockito.times(1)).setServiceInstanceId(instanceId);
533     }
534
535     @Test
536     public void getConfigurationId() {
537         org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
538         vnfc.setModelInvariantId("modelInvariantId");
539         vnfc.setVnfcName("testVnfcName");
540         List<Configuration> configurations = new ArrayList<>();
541         org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
542         configuration.setConfigurationId("configurationId");
543         configuration.setModelCustomizationId("modelCustimizationId");
544         configuration.setConfigurationName("testConfigurationName");
545         configurations.add(configuration);
546         doReturn(configurations.get(0).getConfigurationId()).when(workflowActionBBTasks).getConfigurationId(vnfc);
547         assertEquals(workflowActionBBTasks.getConfigurationId(vnfc), "configurationId");
548     }
549
550     @Test
551     public void setServiceInstanceNameTest() {
552         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
553         WorkflowType resourceType = WorkflowType.SERVICE;
554         InfraActiveRequests request = new InfraActiveRequests();
555         ServiceInstance service = new ServiceInstance();
556         service.setServiceInstanceName("serviceInstanceName");
557         doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById(resourceId);
558
559         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
560         assertEquals("serviceInstanceName", request.getServiceInstanceName());
561     }
562
563     @Test
564     public void setVnfNameTest() {
565         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
566         WorkflowType resourceType = WorkflowType.VNF;
567         InfraActiveRequests request = new InfraActiveRequests();
568         GenericVnf vnf = new GenericVnf();
569         vnf.setVnfName("vnfName");
570         doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf(resourceId);
571
572         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
573         assertEquals("vnfName", request.getVnfName());
574     }
575
576     @Test
577     public void setVfModuleNameTest() {
578         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
579         WorkflowType resourceType = WorkflowType.VFMODULE;
580         InfraActiveRequests request = new InfraActiveRequests();
581         request.setVnfId("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e");
582         VfModule vfModule = new VfModule();
583         vfModule.setVfModuleName("vfModuleName");
584         doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e", resourceId);
585
586         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
587         assertEquals("vfModuleName", request.getVfModuleName());
588     }
589
590     @Test
591     public void setNetworkNameTest() {
592         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
593         WorkflowType resourceType = WorkflowType.NETWORK;
594         InfraActiveRequests request = new InfraActiveRequests();
595         L3Network network = new L3Network();
596         network.setNetworkName("networkName");
597         doReturn(network).when(bbSetupUtils).getAAIL3Network(resourceId);
598
599         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
600         assertEquals("networkName", request.getNetworkName());
601     }
602
603     @Test
604     public void setConfigurationNameTest() {
605         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
606         WorkflowType resourceType = WorkflowType.CONFIGURATION;
607         InfraActiveRequests request = new InfraActiveRequests();
608         Configuration configuration = new Configuration();
609         configuration.setConfigurationName("configurationName");
610         doReturn(configuration).when(bbSetupUtils).getAAIConfiguration(resourceId);
611
612         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
613         assertEquals("configurationName", request.getConfigurationName());
614     }
615
616     @Test
617     public void setInstanceGroupNameTest() {
618         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
619         WorkflowType resourceType = WorkflowType.INSTANCE_GROUP;
620         InfraActiveRequests request = new InfraActiveRequests();
621         InstanceGroup instanceGroup = new InstanceGroup();
622         instanceGroup.setInstanceGroupName("instanceGroupName");
623         doReturn(instanceGroup).when(bbSetupUtils).getAAIInstanceGroup(resourceId);
624
625         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
626         assertEquals("instanceGroupName", request.getInstanceGroupName());
627     }
628
629     @Test
630     public void setVolumeGroupNameTest() {
631         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
632         WorkflowType resourceType = WorkflowType.VOLUMEGROUP;
633         InfraActiveRequests request = new InfraActiveRequests();
634         request.setVnfId("4aa72c90-21eb-4465-8847-997e27af6c3e");
635         VolumeGroup volumeGroup = new VolumeGroup();
636         volumeGroup.setVolumeGroupName("volumeGroupName");
637         Optional<VolumeGroup> returnVolumeGroup = Optional.of(volumeGroup);
638
639         doReturn(returnVolumeGroup).when(bbSetupUtils).getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
640         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
641
642         assertEquals("volumeGroupName", request.getVolumeGroupName());
643     }
644
645     private void prepareDelegateExecution() {
646         execution.setVariable("mso-request-id", SAMPLE_MSO_REQUEST_ID);
647         execution.setVariable("requestAction", SAMPLE_REQUEST_ACTION);
648         execution.setVariable("gCurrentSequence", SAMPLE_SEQUENCE);
649         execution.setVariable("homing", false);
650         execution.setVariable("calledHoming", false);
651     }
652 }