4991fa59eef50a539fec7e0b78340dd8b624614c
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.workflow.tasks;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertThat;
25 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
26 import static org.mockito.ArgumentMatchers.anyObject;
27 import static org.mockito.ArgumentMatchers.anyString;
28 import static org.mockito.ArgumentMatchers.isA;
29 import static org.mockito.Mockito.doNothing;
30 import static org.mockito.Mockito.doReturn;
31 import static org.mockito.Mockito.when;
32 import java.io.IOException;
33 import java.util.ArrayList;
34 import java.util.List;
35 import java.util.Optional;
36 import org.camunda.bpm.engine.delegate.BpmnError;
37 import org.camunda.bpm.engine.delegate.DelegateExecution;
38 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
39 import org.junit.Before;
40 import org.junit.Rule;
41 import org.junit.Test;
42 import org.junit.rules.ExpectedException;
43 import org.mockito.InjectMocks;
44 import org.mockito.Mock;
45 import org.mockito.Mockito;
46 import org.mockito.Spy;
47 import org.onap.aai.domain.yang.Configuration;
48 import org.onap.aai.domain.yang.GenericVnf;
49 import org.onap.aai.domain.yang.InstanceGroup;
50 import org.onap.aai.domain.yang.L3Network;
51 import org.onap.aai.domain.yang.ServiceInstance;
52 import org.onap.aai.domain.yang.VfModule;
53 import org.onap.aai.domain.yang.VolumeGroup;
54 import org.onap.so.bpmn.BaseTaskTest;
55 import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner;
56 import org.onap.so.bpmn.core.WorkflowException;
57 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
58 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
59 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
60 import org.onap.so.db.request.beans.InfraActiveRequests;
61 import org.onap.so.serviceinstancebeans.CloudConfiguration;
62 import org.onap.so.serviceinstancebeans.ModelInfo;
63 import org.onap.so.serviceinstancebeans.ModelType;
64 import org.onap.so.serviceinstancebeans.RequestDetails;
65 import org.onap.so.serviceinstancebeans.RequestInfo;
66 import org.springframework.core.env.Environment;
67
68 public class WorkflowActionBBTasksTest extends BaseTaskTest {
69
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         org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.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() throws Exception {
106         String gAction = "Delete-Network-Collection";
107         execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
108         execution.setVariable("requestAction", gAction);
109         execution.setVariable("gCurrentSequence", 0);
110         execution.setVariable("homing", false);
111         execution.setVariable("calledHoming", false);
112         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
113         ExecuteBuildingBlock ebb = new ExecuteBuildingBlock();
114
115         String vnfCustomizationUUID = "1234567";
116         String modelUuid = "1234567";
117         BuildingBlock buildingBlock = new BuildingBlock();
118         buildingBlock.setBpmnFlowName("ConfigAssignVnfBB");
119         buildingBlock.setKey(vnfCustomizationUUID);
120         ebb.setBuildingBlock(buildingBlock);
121         RequestDetails rd = new RequestDetails();
122         ModelInfo mi = new ModelInfo();
123         mi.setModelUuid(modelUuid);
124         rd.setModelInfo(mi);
125         ebb.setRequestDetails(rd);
126         flowsToExecute.add(ebb);
127
128         List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList();
129         VnfResourceCustomization vrc = new VnfResourceCustomization();
130         vrc.setSkipPostInstConf(false);
131         vrc.setModelCustomizationUUID(vnfCustomizationUUID);
132         vnfResourceCustomizations.add(vrc);
133         GenericVnf genericVnf = new GenericVnf();
134         genericVnf.setModelCustomizationId(vnfCustomizationUUID);
135         doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
136         doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
137                 vnfResourceCustomizations);
138
139         execution.setVariable("flowsToExecute", flowsToExecute);
140         workflowActionBBTasks.selectBB(execution);
141         boolean success = (boolean) execution.getVariable("completed");
142         int currentSequence = (int) execution.getVariable("gCurrentSequence");
143         assertEquals(true, success);
144         assertEquals(1, currentSequence);
145     }
146
147     @Test
148     public void select2BBTest() throws Exception {
149         String gAction = "Delete-Network-Collection";
150         execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
151         execution.setVariable("requestAction", gAction);
152         execution.setVariable("gCurrentSequence", 0);
153         execution.setVariable("homing", false);
154         execution.setVariable("calledHoming", false);
155         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
156         ExecuteBuildingBlock ebb = new ExecuteBuildingBlock();
157         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
158
159         String vnfCustomizationUUID = "1234567";
160         String modelUuid = "1234567";
161         BuildingBlock buildingBlock = new BuildingBlock();
162         buildingBlock.setBpmnFlowName("ConfigDeployVnfBB");
163         buildingBlock.setKey(vnfCustomizationUUID);
164         ebb.setBuildingBlock(buildingBlock);
165         RequestDetails rd = new RequestDetails();
166         ModelInfo mi = new ModelInfo();
167         mi.setModelUuid(modelUuid);
168         rd.setModelInfo(mi);
169         ebb.setRequestDetails(rd);
170         flowsToExecute.add(ebb);
171
172         List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList();
173         VnfResourceCustomization vrc = new VnfResourceCustomization();
174         vrc.setSkipPostInstConf(false);
175         vrc.setModelCustomizationUUID(vnfCustomizationUUID);
176         vnfResourceCustomizations.add(vrc);
177         GenericVnf genericVnf = new GenericVnf();
178         genericVnf.setModelCustomizationId(vnfCustomizationUUID);
179         doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
180         doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
181                 vnfResourceCustomizations);
182
183         flowsToExecute.add(ebb2);
184         execution.setVariable("flowsToExecute", flowsToExecute);
185         workflowActionBBTasks.selectBB(execution);
186         boolean success = (boolean) execution.getVariable("completed");
187         int currentSequence = (int) execution.getVariable("gCurrentSequence");
188         assertEquals(false, success);
189         assertEquals(1, currentSequence);
190     }
191
192     @Test
193     public void updateRequestStatusToCompleteTest() throws Exception {
194         String reqId = "reqId123";
195         execution.setVariable("mso-request-id", reqId);
196         execution.setVariable("requestAction", "createInstance");
197         execution.setVariable("resourceName", "Service");
198         execution.setVariable("aLaCarte", true);
199         InfraActiveRequests req = new InfraActiveRequests();
200         doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
201         doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
202         workflowActionBBTasks.updateRequestStatusToComplete(execution);
203         assertEquals("ALaCarte-Service-createInstance request was executed correctly.",
204                 execution.getVariable("finalStatusMessage"));
205     }
206
207     @Test
208     public void rollbackExecutionPathTest() {
209         execution.setVariable("handlingCode", "Rollback");
210         execution.setVariable("isRollback", false);
211         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
212         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
213         BuildingBlock bb1 = new BuildingBlock();
214         bb1.setBpmnFlowName("AssignVfModuleBB");
215         ebb1.setBuildingBlock(bb1);
216         flowsToExecute.add(ebb1);
217         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
218         BuildingBlock bb2 = new BuildingBlock();
219         bb2.setBpmnFlowName("CreateVfModuleBB");
220         ebb2.setBuildingBlock(bb2);
221         flowsToExecute.add(ebb2);
222         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
223         BuildingBlock bb3 = new BuildingBlock();
224         bb3.setBpmnFlowName("ActivateVfModuleBB");
225         ebb3.setBuildingBlock(bb3);
226         flowsToExecute.add(ebb3);
227
228         execution.setVariable("flowsToExecute", flowsToExecute);
229         execution.setVariable("gCurrentSequence", 3);
230         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
231
232         workflowActionBBTasks.rollbackExecutionPath(execution);
233         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
234         assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeactivateVfModuleBB");
235         assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
236         assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
237         assertEquals(0, execution.getVariable("gCurrentSequence"));
238     }
239
240     @Test
241     public void rollbackExecutionPathUnfinishedFlowTest() {
242         execution.setVariable("handlingCode", "Rollback");
243         execution.setVariable("isRollback", false);
244         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
245         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
246         BuildingBlock bb1 = new BuildingBlock();
247         bb1.setBpmnFlowName("AssignVfModuleBB");
248         ebb1.setBuildingBlock(bb1);
249         flowsToExecute.add(ebb1);
250         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
251         BuildingBlock bb2 = new BuildingBlock();
252         bb2.setBpmnFlowName("CreateVfModuleBB");
253         ebb2.setBuildingBlock(bb2);
254         flowsToExecute.add(ebb2);
255         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
256         BuildingBlock bb3 = new BuildingBlock();
257         bb3.setBpmnFlowName("ActivateVfModuleBB");
258         ebb3.setBuildingBlock(bb3);
259         flowsToExecute.add(ebb3);
260
261         execution.setVariable("flowsToExecute", flowsToExecute);
262         execution.setVariable("gCurrentSequence", 2);
263         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
264
265         workflowActionBBTasks.rollbackExecutionPath(execution);
266         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
267         assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
268         assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
269         assertEquals(0, execution.getVariable("gCurrentSequence"));
270         assertEquals(0, execution.getVariable("retryCount"));
271     }
272
273     @Test
274     public void rollbackExecutionTest() {
275         execution.setVariable("handlingCode", "Rollback");
276         execution.setVariable("isRollback", false);
277         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
278         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
279         BuildingBlock bb1 = new BuildingBlock();
280         bb1.setBpmnFlowName("AssignServiceInstanceBB");
281         ebb1.setBuildingBlock(bb1);
282         flowsToExecute.add(ebb1);
283         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
284         BuildingBlock bb2 = new BuildingBlock();
285         bb2.setBpmnFlowName("CreateNetworkCollectionBB");
286         ebb2.setBuildingBlock(bb2);
287         flowsToExecute.add(ebb2);
288         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
289         BuildingBlock bb3 = new BuildingBlock();
290         bb3.setBpmnFlowName("AssignNetworkBB");
291         ebb3.setBuildingBlock(bb3);
292         flowsToExecute.add(ebb3);
293         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock();
294         BuildingBlock bb4 = new BuildingBlock();
295         bb4.setBpmnFlowName("CreateNetworkBB");
296         ebb4.setBuildingBlock(bb4);
297         flowsToExecute.add(ebb4);
298
299         execution.setVariable("flowsToExecute", flowsToExecute);
300         execution.setVariable("gCurrentSequence", 3);
301         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
302
303         workflowActionBBTasks.rollbackExecutionPath(execution);
304         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
305         assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "UnassignNetworkBB");
306         assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteNetworkCollectionBB");
307         assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignServiceInstanceBB");
308         assertEquals(0, execution.getVariable("gCurrentSequence"));
309     }
310
311     @Test
312     public void rollbackExecutionRollbackToAssignedTest() {
313         execution.setVariable("isRollback", false);
314         execution.setVariable("handlingCode", "RollbackToAssigned");
315         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
316         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
317         BuildingBlock bb1 = new BuildingBlock();
318         bb1.setBpmnFlowName("AssignVfModuleBB");
319         ebb1.setBuildingBlock(bb1);
320         flowsToExecute.add(ebb1);
321         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
322         BuildingBlock bb2 = new BuildingBlock();
323         bb2.setBpmnFlowName("CreateVfModuleBB");
324         ebb2.setBuildingBlock(bb2);
325         flowsToExecute.add(ebb2);
326         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
327         BuildingBlock bb3 = new BuildingBlock();
328         bb3.setBpmnFlowName("ActivateVfModuleBB");
329         ebb3.setBuildingBlock(bb3);
330         flowsToExecute.add(ebb3);
331
332         execution.setVariable("flowsToExecute", flowsToExecute);
333         execution.setVariable("gCurrentSequence", 2);
334
335         workflowActionBBTasks.rollbackExecutionPath(execution);
336         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
337         assertEquals("DeleteVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
338         assertEquals(0, execution.getVariable("gCurrentSequence"));
339         assertEquals(1, ebbs.size());
340     }
341
342     @Test
343     public void rollbackExecutionRollbackToAssignedWithFabricTest() {
344         execution.setVariable("isRollback", false);
345         execution.setVariable("handlingCode", "RollbackToAssigned");
346         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
347         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
348         BuildingBlock bb1 = new BuildingBlock();
349         bb1.setBpmnFlowName("AssignVfModuleBB");
350         ebb1.setBuildingBlock(bb1);
351         flowsToExecute.add(ebb1);
352         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
353         BuildingBlock bb2 = new BuildingBlock();
354         bb2.setBpmnFlowName("CreateVfModuleBB");
355         ebb2.setBuildingBlock(bb2);
356         flowsToExecute.add(ebb2);
357         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
358         BuildingBlock bb3 = new BuildingBlock();
359         bb3.setBpmnFlowName("ActivateVfModuleBB");
360         ebb3.setBuildingBlock(bb3);
361         flowsToExecute.add(ebb3);
362         ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock();
363         BuildingBlock bb4 = new BuildingBlock();
364         bb4.setBpmnFlowName("AssignFabricConfigurationBB");
365         ebb4.setBuildingBlock(bb4);
366         flowsToExecute.add(ebb4);
367         ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock();
368         BuildingBlock bb5 = new BuildingBlock();
369         bb5.setBpmnFlowName("ActivateFabricConfigurationBB");
370         ebb5.setBuildingBlock(bb5);
371         flowsToExecute.add(ebb5);
372
373         execution.setVariable("flowsToExecute", flowsToExecute);
374         execution.setVariable("gCurrentSequence", 5);
375
376         workflowActionBBTasks.rollbackExecutionPath(execution);
377         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
378         assertEquals(0, execution.getVariable("gCurrentSequence"));
379         assertEquals(4, ebbs.size());
380         assertEquals("DeactivateFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
381         assertEquals("UnassignFabricConfigurationBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
382         assertEquals("DeactivateVfModuleBB", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
383         assertEquals("DeleteVfModuleBB", ebbs.get(3).getBuildingBlock().getBpmnFlowName());
384
385     }
386
387     @Test
388     public void rollbackExecutionRollbackToCreatedTest() {
389         execution.setVariable("isRollback", false);
390         execution.setVariable("handlingCode", "RollbackToCreated");
391         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList();
392         ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock();
393         BuildingBlock bb1 = new BuildingBlock();
394         bb1.setBpmnFlowName("AssignVfModuleBB");
395         ebb1.setBuildingBlock(bb1);
396         flowsToExecute.add(ebb1);
397         ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
398         BuildingBlock bb2 = new BuildingBlock();
399         bb2.setBpmnFlowName("CreateVfModuleBB");
400         ebb2.setBuildingBlock(bb2);
401         flowsToExecute.add(ebb2);
402         ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock();
403         BuildingBlock bb3 = new BuildingBlock();
404         bb3.setBpmnFlowName("ActivateVfModuleBB");
405         ebb3.setBuildingBlock(bb3);
406         flowsToExecute.add(ebb3);
407
408         execution.setVariable("flowsToExecute", flowsToExecute);
409         execution.setVariable("gCurrentSequence", 3);
410
411         workflowActionBBTasks.rollbackExecutionPath(execution);
412         List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
413         assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
414         assertEquals(0, execution.getVariable("gCurrentSequence"));
415         assertEquals(1, ebbs.size());
416     }
417
418     @Test
419     public void checkRetryStatusTest() {
420         String reqId = "reqId123";
421         execution.setVariable("mso-request-id", reqId);
422         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
423         doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
424         execution.setVariable("handlingCode", "Retry");
425         execution.setVariable("retryCount", 1);
426         execution.setVariable("gCurrentSequence", 1);
427         InfraActiveRequests req = new InfraActiveRequests();
428         doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
429         workflowActionBBTasks.checkRetryStatus(execution);
430         assertEquals(0, execution.getVariable("gCurrentSequence"));
431     }
432
433     @Test
434     public void checkRetryStatusTestExceededMaxRetries() {
435         String reqId = "reqId123";
436         execution.setVariable("mso-request-id", reqId);
437         doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
438         doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
439         execution.setVariable("handlingCode", "Retry");
440         execution.setVariable("retryCount", 6);
441         execution.setVariable("gCurrentSequence", 1);
442         InfraActiveRequests req = new InfraActiveRequests();
443         doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
444         try {
445             workflowActionBBTasks.checkRetryStatus(execution);
446         } catch (BpmnError e) {
447             WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException");
448             assertEquals("Exceeded maximum retries. Ending flow with status Abort", exception.getErrorMessage());
449         }
450     }
451
452     @Test
453     public void checkRetryStatusNoRetryTest() {
454         String reqId = "reqId123";
455         execution.setVariable("mso-request-id", reqId);
456         execution.setVariable("retryCount", 3);
457         execution.setVariable("handlingCode", "Success");
458         execution.setVariable("gCurrentSequence", 1);
459         InfraActiveRequests req = new InfraActiveRequests();
460         doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
461         workflowActionBBTasks.checkRetryStatus(execution);
462         assertEquals(0, execution.getVariable("retryCount"));
463     }
464
465     @Test
466     public void updateInstanceId() {
467         String reqId = "req123";
468         String instanceId = "123123123";
469         execution.setVariable("mso-request-id", reqId);
470         execution.setVariable("resourceId", instanceId);
471         execution.setVariable("resourceType", WorkflowType.SERVICE);
472         doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
473         doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
474         workflowActionBBTasks.updateInstanceId(execution);
475         Mockito.verify(reqMock, Mockito.times(1)).setServiceInstanceId(instanceId);
476     }
477
478     @Test
479     public void getConfigurationId() {
480         org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
481         vnfc.setModelInvariantId("modelInvariantId");
482         vnfc.setVnfcName("testVnfcName");
483         List<org.onap.aai.domain.yang.Configuration> configurations =
484                 new ArrayList<org.onap.aai.domain.yang.Configuration>();
485         org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
486         configuration.setConfigurationId("configurationId");
487         configuration.setModelCustomizationId("modelCustimizationId");
488         configuration.setConfigurationName("testConfigurationName");
489         configurations.add(configuration);
490         doReturn(configurations.get(0).getConfigurationId()).when(workflowActionBBTasks).getConfigurationId(vnfc);
491         assertEquals(workflowActionBBTasks.getConfigurationId(vnfc), "configurationId");
492     }
493
494     @Test
495     public void setServiceInstanceNameTest() {
496         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
497         WorkflowType resourceType = WorkflowType.SERVICE;
498         InfraActiveRequests request = new InfraActiveRequests();
499         ServiceInstance service = new ServiceInstance();
500         service.setServiceInstanceName("serviceInstanceName");
501         doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById(resourceId);
502
503         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
504         assertEquals("serviceInstanceName", request.getServiceInstanceName());
505     }
506
507     @Test
508     public void setVnfNameTest() {
509         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
510         WorkflowType resourceType = WorkflowType.VNF;
511         InfraActiveRequests request = new InfraActiveRequests();
512         GenericVnf vnf = new GenericVnf();
513         vnf.setVnfName("vnfName");
514         doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf(resourceId);
515
516         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
517         assertEquals("vnfName", request.getVnfName());
518     }
519
520     @Test
521     public void setVfModuleNameTest() {
522         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
523         WorkflowType resourceType = WorkflowType.VFMODULE;
524         InfraActiveRequests request = new InfraActiveRequests();
525         request.setVnfId("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e");
526         VfModule vfModule = new VfModule();
527         vfModule.setVfModuleName("vfModuleName");
528         doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e", resourceId);
529
530         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
531         assertEquals("vfModuleName", request.getVfModuleName());
532     }
533
534     @Test
535     public void setNetworkNameTest() {
536         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
537         WorkflowType resourceType = WorkflowType.NETWORK;
538         InfraActiveRequests request = new InfraActiveRequests();
539         L3Network network = new L3Network();
540         network.setNetworkName("networkName");
541         doReturn(network).when(bbSetupUtils).getAAIL3Network(resourceId);
542
543         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
544         assertEquals("networkName", request.getNetworkName());
545     }
546
547     @Test
548     public void setConfigurationNameTest() {
549         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
550         WorkflowType resourceType = WorkflowType.CONFIGURATION;
551         InfraActiveRequests request = new InfraActiveRequests();
552         Configuration configuration = new Configuration();
553         configuration.setConfigurationName("configurationName");
554         doReturn(configuration).when(bbSetupUtils).getAAIConfiguration(resourceId);
555
556         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
557         assertEquals("configurationName", request.getConfigurationName());
558     }
559
560     @Test
561     public void setInstanceGroupNameTest() {
562         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
563         WorkflowType resourceType = WorkflowType.INSTANCE_GROUP;
564         InfraActiveRequests request = new InfraActiveRequests();
565         InstanceGroup instanceGroup = new InstanceGroup();
566         instanceGroup.setInstanceGroupName("instanceGroupName");
567         doReturn(instanceGroup).when(bbSetupUtils).getAAIInstanceGroup(resourceId);
568
569         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
570         assertEquals("instanceGroupName", request.getInstanceGroupName());
571     }
572
573     @Test
574     public void setVolumeGroupNameTest() {
575         String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
576         WorkflowType resourceType = WorkflowType.VOLUMEGROUP;
577         InfraActiveRequests request = new InfraActiveRequests();
578         request.setVnfId("4aa72c90-21eb-4465-8847-997e27af6c3e");
579         VolumeGroup volumeGroup = new VolumeGroup();
580         volumeGroup.setVolumeGroupName("volumeGroupName");
581         Optional<VolumeGroup> returnVolumeGroup = Optional.of(volumeGroup);
582
583         doReturn(returnVolumeGroup).when(bbSetupUtils).getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
584         workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
585
586         assertEquals("volumeGroupName", request.getVolumeGroupName());
587     }
588 }