Merge "Enable DeleteChildService functionality" into recursive-orch
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / aai / tasks / AAIUpdateTasksTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2020 Tech Mahindra
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.aai.tasks;
24
25 import org.camunda.bpm.engine.delegate.BpmnError;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.ArgumentMatchers;
29 import org.mockito.InjectMocks;
30 import org.mockito.Mockito;
31 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
32 import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
33 import org.onap.so.bpmn.BaseTaskTest;
34 import org.onap.so.bpmn.common.BuildingBlockExecution;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
44 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
45 import org.onap.so.client.exception.BBObjectNotFoundException;
46 import org.onap.so.db.catalog.beans.OrchestrationStatus;
47 import java.util.HashMap;
48 import static org.junit.Assert.assertEquals;
49 import static org.mockito.ArgumentMatchers.any;
50 import static org.mockito.ArgumentMatchers.eq;
51 import static org.mockito.Mockito.doNothing;
52 import static org.mockito.Mockito.doReturn;
53 import static org.mockito.Mockito.doThrow;
54 import static org.mockito.Mockito.mock;
55 import static org.mockito.Mockito.spy;
56 import static org.mockito.Mockito.times;
57 import static org.mockito.Mockito.verify;
58 import static org.mockito.Mockito.when;
59
60 public class AAIUpdateTasksTest extends BaseTaskTest {
61
62     @InjectMocks
63     private AAIUpdateTasks aaiUpdateTasks = new AAIUpdateTasks();
64
65     private L3Network network;
66     private ServiceInstance serviceInstance;
67     private VfModule vfModule;
68     private GenericVnf genericVnf;
69     private VolumeGroup volumeGroup;
70     private CloudRegion cloudRegion;
71     private Configuration configuration;
72     private Subnet subnet;
73
74     @Before
75     public void before() throws BBObjectNotFoundException {
76         serviceInstance = setServiceInstance();
77         genericVnf = setGenericVnf();
78         vfModule = setVfModule();
79         volumeGroup = setVolumeGroup();
80         cloudRegion = setCloudRegion();
81         network = setL3Network();
82         configuration = setConfiguration();
83         subnet = buildSubnet();
84
85         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
86                 .thenReturn(genericVnf);
87         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
88         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
89         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID)))
90                 .thenReturn(volumeGroup);
91         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
92                 .thenReturn(serviceInstance);
93         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID)))
94                 .thenReturn(configuration);
95
96
97         doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
98                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
99     }
100
101     @Test
102     public void updateOrchestrationStatusAssignedServiceTest() throws Exception {
103         doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance,
104                 OrchestrationStatus.ASSIGNED);
105
106         aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
107
108         verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance,
109                 OrchestrationStatus.ASSIGNED);
110     }
111
112     @Test
113     public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception {
114         expectedException.expect(BpmnError.class);
115
116         doThrow(RuntimeException.class).when(aaiServiceInstanceResources)
117                 .updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
118
119         aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
120     }
121
122     @Test
123     public void updateOrchestrationStatusActiveServiceTest() throws Exception {
124         doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance,
125                 OrchestrationStatus.ACTIVE);
126
127         aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
128
129         verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance,
130                 OrchestrationStatus.ACTIVE);
131     }
132
133     @Test
134     public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception {
135         expectedException.expect(BpmnError.class);
136
137         doThrow(RuntimeException.class).when(aaiServiceInstanceResources)
138                 .updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
139
140         aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
141     }
142
143     @Test
144     public void updateOrchestrationStatusAssignedPnfTest() throws Exception {
145         Pnf pnf = preparePnfAndExtractForPnf();
146         doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ASSIGNED);
147
148         aaiUpdateTasks.updateOrchestrationStatusAssignedPnf(execution);
149
150         verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ASSIGNED);
151     }
152
153     @Test
154     public void updateOrchestrationStatusAssignedPnfExceptionTest() throws Exception {
155         Pnf pnf = preparePnfAndExtractForPnf();
156         doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
157                 OrchestrationStatus.ASSIGNED);
158
159         expectedException.expect(BpmnError.class);
160         aaiUpdateTasks.updateOrchestrationStatusAssignedPnf(execution);
161     }
162
163     @Test
164     public void updateOrchestrationStatusInventoriedPnfTest() throws Exception {
165         Pnf pnf = preparePnfAndExtractForPnf();
166         doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.INVENTORIED);
167
168         aaiUpdateTasks.updateOrchestrationStatusInventoriedPnf(execution);
169
170         verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.INVENTORIED);
171     }
172
173     @Test
174     public void updateOrchestrationStatusInventoriedPnfExceptionTest() throws Exception {
175         Pnf pnf = preparePnfAndExtractForPnf();
176         doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
177                 OrchestrationStatus.INVENTORIED);
178
179         expectedException.expect(BpmnError.class);
180         aaiUpdateTasks.updateOrchestrationStatusInventoriedPnf(execution);
181     }
182
183     @Test
184     public void updateOrchestrationStatusActivePnfTest() throws Exception {
185         Pnf pnf = preparePnfAndExtractForPnf();
186         doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
187
188         aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
189
190         verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
191     }
192
193     @Test
194     public void updateOrchestrationStatusActivePnfExceptionTest() throws Exception {
195         Pnf pnf = preparePnfAndExtractForPnf();
196         doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
197                 OrchestrationStatus.ACTIVE);
198
199         expectedException.expect(BpmnError.class);
200         aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
201     }
202
203     @Test
204     public void updateOrchestrationStatusRegisterPnfTest() throws Exception {
205         Pnf pnf = preparePnfAndExtractForPnf();
206         doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTER);
207
208         aaiUpdateTasks.updateOrchestrationStatusRegisterPnf(execution);
209
210         verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTER);
211     }
212
213     @Test
214     public void updateOrchestrationStatusRegisteredPnfTest() throws Exception {
215         Pnf pnf = preparePnfAndExtractForPnf();
216         doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTERED);
217
218         aaiUpdateTasks.updateOrchestrationStatusRegisteredPnf(execution);
219
220         verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTERED);
221     }
222
223     @Test
224     public void updateOrchestrationStatusAssignedVnfTest() throws Exception {
225         doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
226
227         aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
228
229         verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
230     }
231
232     @Test
233     public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception {
234         expectedException.expect(BpmnError.class);
235
236         doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
237                 OrchestrationStatus.ASSIGNED);
238
239         aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
240     }
241
242     @Test
243     public void updateOrchestrationStatusActiveVnfTest() throws Exception {
244         doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
245
246         aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
247
248         verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
249     }
250
251     @Test
252     public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception {
253         expectedException.expect(BpmnError.class);
254
255         doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
256                 OrchestrationStatus.ACTIVE);
257
258         aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
259     }
260
261     @Test
262     public void updateOrchestrationStatusAssignVfModuleTest() throws Exception {
263         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
264                 OrchestrationStatus.ASSIGNED);
265         aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
266         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
267                 OrchestrationStatus.ASSIGNED);
268         assertEquals("", vfModule.getHeatStackId());
269     }
270
271     @Test
272     public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception {
273         doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
274                 genericVnf, OrchestrationStatus.ASSIGNED);
275
276         expectedException.expect(BpmnError.class);
277
278         aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
279     }
280
281     @Test
282     public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception {
283         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
284                 OrchestrationStatus.CREATED);
285         aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
286         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
287                 OrchestrationStatus.CREATED);
288     }
289
290     @Test
291     public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
292         doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
293                 genericVnf, OrchestrationStatus.CREATED);
294
295         expectedException.expect(BpmnError.class);
296
297         aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
298     }
299
300     @Test
301     public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception {
302         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
303                 OrchestrationStatus.PENDING_ACTIVATION);
304
305         aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
306
307         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
308                 OrchestrationStatus.PENDING_ACTIVATION);
309     }
310
311     @Test
312     public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
313         doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
314                 genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
315
316         expectedException.expect(BpmnError.class);
317
318         aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
319     }
320
321     @Test
322     public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception {
323         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
324                 OrchestrationStatus.CREATED);
325
326         aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
327
328         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
329                 OrchestrationStatus.CREATED);
330     }
331
332     @Test
333     public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
334         doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
335                 genericVnf, OrchestrationStatus.CREATED);
336
337         expectedException.expect(BpmnError.class);
338
339         aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
340     }
341
342     @Test
343     public void updateHeatStackIdVfModuleTest() throws Exception {
344         execution.setVariable("heatStackId", "newHeatStackId");
345         doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
346
347         aaiUpdateTasks.updateHeatStackIdVfModule(execution);
348
349         verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
350         assertEquals("newHeatStackId", vfModule.getHeatStackId());
351     }
352
353     @Test
354     public void updateHeatStackIdVfModuleToNullTest() throws Exception {
355         execution.setVariable("heatStackId", null);
356         doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
357
358         aaiUpdateTasks.updateHeatStackIdVfModule(execution);
359
360         verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
361         assertEquals(vfModule.getHeatStackId(), "");
362     }
363
364     @Test
365     public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
366         doThrow(RuntimeException.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
367
368         expectedException.expect(BpmnError.class);
369
370         aaiUpdateTasks.updateHeatStackIdVfModule(execution);
371     }
372
373     @Test
374     public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
375         doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
376                 OrchestrationStatus.ACTIVE);
377
378         aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
379
380         verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
381                 OrchestrationStatus.ACTIVE);
382     }
383
384     @Test
385     public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
386         expectedException.expect(BpmnError.class);
387         doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
388                 cloudRegion, OrchestrationStatus.ACTIVE);
389         aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
390     }
391
392     @Test
393     public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
394         doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
395                 OrchestrationStatus.CREATED);
396
397         aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
398
399         verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
400                 OrchestrationStatus.CREATED);
401     }
402
403     @Test
404     public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
405         expectedException.expect(BpmnError.class);
406         doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
407                 cloudRegion, OrchestrationStatus.CREATED);
408         aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
409     }
410
411     @Test
412     public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
413         doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
414                 OrchestrationStatus.ASSIGNED);
415
416         aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
417
418         verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
419                 OrchestrationStatus.ASSIGNED);
420         assertEquals("", volumeGroup.getHeatStackId());
421     }
422
423     @Test
424     public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
425         expectedException.expect(BpmnError.class);
426         doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
427                 cloudRegion, OrchestrationStatus.ASSIGNED);
428         aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
429     }
430
431     @Test
432     public void updateHeatStackIdVolumeGroupTest() throws Exception {
433         execution.setVariable("heatStackId", "newHeatStackId");
434         doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
435
436         aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
437
438         verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
439         assertEquals("newHeatStackId", volumeGroup.getHeatStackId());
440     }
441
442     @Test
443     public void updateHeatStackIdVolumeGroupToNullTest() throws Exception {
444         execution.setVariable("heatStackId", null);
445         doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
446
447         aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
448
449         verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
450         assertEquals(volumeGroup.getHeatStackId(), "");
451     }
452
453     @Test
454     public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
455         expectedException.expect(BpmnError.class);
456         doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup,
457                 cloudRegion);
458         aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
459     }
460
461     @Test
462     public void updateNetworkExceptionTest() throws Exception {
463         expectedException.expect(BpmnError.class);
464
465         doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
466
467         aaiUpdateTasks.updateNetwork(execution, OrchestrationStatus.ACTIVE);
468     }
469
470     @Test
471     public void updateOstatusActivedNetworkCollectionTest() throws Exception {
472         doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
473         aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
474         verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
475     }
476
477     @Test
478     public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
479         expectedException.expect(BpmnError.class);
480         doThrow(RuntimeException.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
481         aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
482     }
483
484     @Test
485     public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
486         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
487                 OrchestrationStatus.ACTIVE);
488
489         aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
490
491         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
492                 OrchestrationStatus.ACTIVE);
493     }
494
495     @Test
496     public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
497         doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
498                 genericVnf, OrchestrationStatus.ACTIVE);
499
500         expectedException.expect(BpmnError.class);
501
502         aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
503     }
504
505     @Test
506     public void updateNetworkCreatedTest() throws Exception {
507         CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
508         createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
509         createNetworkResponse.setNetworkStackId("testNetworkStackId");
510         HashMap<String, String> subnetMap = new HashMap<>();
511         subnetMap.put("testSubnetId", "testNeutronSubnetId");
512         createNetworkResponse.setSubnetMap(subnetMap);
513
514         network.getSubnets().add(subnet);
515
516         execution.setVariable("createNetworkResponse", createNetworkResponse);
517
518         doNothing().when(aaiNetworkResources).updateNetwork(network);
519         doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
520
521         aaiUpdateTasks.updateNetworkCreated(execution);
522         verify(aaiNetworkResources, times(1)).updateNetwork(network);
523         verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
524
525         assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
526         assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
527         assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
528         assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
529         String neutronSubnetId = createNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
530         assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
531     }
532
533     @Test
534     public void updateNetworkUpdatedTest() throws Exception {
535         UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse();
536         updateNetworkResponse.setNeutronNetworkId("testNeutronNetworkId");
537         HashMap<String, String> subnetMap = new HashMap<>();
538         subnetMap.put("testSubnetId", "testNeutronSubnetId");
539         updateNetworkResponse.setSubnetMap(subnetMap);
540
541         network.getSubnets().add(subnet);
542
543         execution.setVariable("updateNetworkResponse", updateNetworkResponse);
544
545         doNothing().when(aaiNetworkResources).updateNetwork(network);
546         doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
547
548         aaiUpdateTasks.updateNetworkUpdated(execution);
549         verify(aaiNetworkResources, times(1)).updateNetwork(network);
550         verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
551
552         String neutronSubnetId = updateNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
553         assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
554     }
555
556     @Test
557     public void updateOrchestrationStatusNetworkTest() {
558         AAIUpdateTasks spy = Mockito.spy(new AAIUpdateTasks());
559         doNothing().when(spy).updateNetwork(eq(execution), any());
560         spy.updateOrchestrationStatusActiveNetwork(execution);
561         verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ACTIVE);
562         spy.updateOrchestrationStatusAssignedNetwork(execution);
563         verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ASSIGNED);
564         spy.updateOrchestrationStatusCreatedNetwork(execution);
565         verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.CREATED);
566     }
567
568     @Test
569     public void updateNetworkAAITest() {
570
571         L3Network spy = spy(new L3Network());
572         L3Network shallowCopy = mock(L3Network.class);
573         Subnet mockSubnet = mock(Subnet.class);
574         Subnet shallowCopySubnet = mock(Subnet.class);
575         when(mockSubnet.shallowCopyId()).thenReturn(shallowCopySubnet);
576         doReturn(shallowCopy).when(spy).shallowCopyId();
577
578         doNothing().when(aaiNetworkResources).updateNetwork(network);
579         doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
580
581         spy.getSubnets().add(mockSubnet);
582         aaiUpdateTasks.updateNetworkAAI(spy, OrchestrationStatus.CREATED);
583
584         verify(shallowCopy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
585         verify(spy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
586         verify(shallowCopySubnet, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
587     }
588
589     @Test
590     public void updateNetworkCreatedkExceptionTest() throws Exception {
591         expectedException.expect(BpmnError.class);
592         doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
593         aaiUpdateTasks.updateNetworkCreated(execution);
594     }
595
596     @Test
597     public void updateObjectNetworkTest() {
598         doNothing().when(aaiNetworkResources).updateNetwork(network);
599
600         aaiUpdateTasks.updateObjectNetwork(execution);
601
602         verify(aaiNetworkResources, times(1)).updateNetwork(network);
603     }
604
605     @Test
606     public void updateObjectNetworkExceptionText() {
607         expectedException.expect(BpmnError.class);
608
609         doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
610
611         aaiUpdateTasks.updateObjectNetwork(execution);
612     }
613
614     @Test
615     public void test_updateServiceInstance() {
616         doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
617         aaiUpdateTasks.updateServiceInstance(execution);
618         verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
619     }
620
621     @Test
622     public void test_updateServiceInstance_exception() {
623         expectedException.expect(BpmnError.class);
624         doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
625         aaiUpdateTasks.updateServiceInstance(execution);
626     }
627
628     @Test
629     public void updateObjectVnfTest() {
630         doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
631
632         aaiUpdateTasks.updateObjectVnf(execution);
633
634         verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
635     }
636
637     @Test
638     public void updateObjectVnfExceptionTest() {
639         expectedException.expect(BpmnError.class);
640         doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
641         aaiUpdateTasks.updateObjectVnf(execution);
642     }
643
644     @Test
645     public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
646         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
647                 OrchestrationStatus.ASSIGNED);
648
649         aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
650
651         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
652                 OrchestrationStatus.ASSIGNED);
653         assertEquals("", vfModule.getHeatStackId());
654     }
655
656     @Test
657     public void updateModelVfModuleTest() {
658         doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
659         aaiUpdateTasks.updateModelVfModule(execution);
660         verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
661     }
662
663     @Test
664     public void updateModelVfModuleExceptionTest() {
665         expectedException.expect(BpmnError.class);
666         doThrow(RuntimeException.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
667         aaiUpdateTasks.updateModelVfModule(execution);
668     }
669
670     @Test
671     public void updateOrchestrationStatusDeactivateFabricConfigurationTest() throws Exception {
672         gBBInput = execution.getGeneralBuildingBlock();
673         doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
674                 OrchestrationStatus.ASSIGNED);
675
676         aaiUpdateTasks.updateOrchestrationStatusDeactivateFabricConfiguration(execution);
677
678         verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
679                 OrchestrationStatus.ASSIGNED);
680     }
681
682     @Test
683     public void updateOrchestrationStatusActivateFabricConfigurationTest() throws Exception {
684         gBBInput = execution.getGeneralBuildingBlock();
685         doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
686                 OrchestrationStatus.ACTIVE);
687
688         aaiUpdateTasks.updateOrchestrationStatusActivateFabricConfiguration(execution);
689
690         verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
691                 OrchestrationStatus.ACTIVE);
692     }
693
694     @Test
695     public void updateOrchestrationStatusAssignedFabricConfigurationTest() throws Exception {
696         gBBInput = execution.getGeneralBuildingBlock();
697         doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
698                 OrchestrationStatus.ASSIGNED);
699
700         aaiUpdateTasks.updateOrchestrationStatusAssignFabricConfiguration(execution);
701
702         verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
703                 OrchestrationStatus.ASSIGNED);
704     }
705
706     @Test
707     public void updateContrailServiceInstanceFqdnVfModuleTest() throws Exception {
708         execution.setVariable("contrailServiceInstanceFqdn", "newContrailServiceInstanceFqdn");
709         doNothing().when(aaiVfModuleResources).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
710
711         aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
712
713         verify(aaiVfModuleResources, times(1)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
714         assertEquals("newContrailServiceInstanceFqdn", vfModule.getContrailServiceInstanceFqdn());
715     }
716
717     @Test
718     public void updateContrailServiceInstanceFqdnVfModuleNoUpdateTest() throws Exception {
719         aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
720         verify(aaiVfModuleResources, times(0)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
721     }
722
723     @Test
724     public void updateIpv4OamAddressVnfTest() throws Exception {
725         execution.setVariable("oamManagementV4Address", "newIpv4OamAddress");
726         doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
727
728         aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
729
730         verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
731         assertEquals("newIpv4OamAddress", genericVnf.getIpv4OamAddress());
732     }
733
734     @Test
735     public void updateIpv4OamAddressVnfNoUpdateTest() throws Exception {
736         aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
737         verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
738     }
739
740     @Test
741     public void updateManagementV6AddressVnfTest() throws Exception {
742         execution.setVariable("oamManagementV6Address", "newManagementV6Address");
743         doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
744
745         aaiUpdateTasks.updateManagementV6AddressVnf(execution);
746
747         verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
748         assertEquals("newManagementV6Address", genericVnf.getManagementV6Address());
749     }
750
751     @Test
752     public void updateManagementV6AddressVnfNoUpdateTest() throws Exception {
753         aaiUpdateTasks.updateManagementV6AddressVnf(execution);
754         verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
755     }
756
757     @Test
758     public void updateOrchestrationStatusVnfConfigureTest() throws Exception {
759         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
760                 OrchestrationStatus.CONFIGURE);
761
762         aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfigureVnf(execution);
763     }
764
765     @Test
766     public void updateOrchestrationStatusVnfConfiguredTest() throws Exception {
767         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
768                 OrchestrationStatus.CONFIGURED);
769
770         aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfiguredVnf(execution);
771     }
772
773     private Pnf preparePnfAndExtractForPnf() throws BBObjectNotFoundException {
774         Pnf pnf = buildPnf();
775         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf);
776         return pnf;
777     }
778
779     @Test
780     public void updateOrchestrationStatusVnfConfigAssignedTest() throws Exception {
781         doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGASSIGNED);
782
783         aaiUpdateTasks.updateOrchestrationStatus(execution, "vnf", "config-assign");
784
785         verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGASSIGNED);
786     }
787
788     @Test
789     public void updateOrchestrationStatusVnfConfigDeployedTest() throws Exception {
790         doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGDEPLOYED);
791
792         aaiUpdateTasks.updateOrchestrationStatus(execution, "vnf", "config-deploy");
793
794         verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGDEPLOYED);
795     }
796
797     @Test
798     public void updateOrchestrationStatusVfModuleConfigDeployedTest() throws Exception {
799         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
800                 OrchestrationStatus.CONFIGDEPLOYED);
801         aaiUpdateTasks.updateOrchestrationStatus(execution, "vfmodule", "config-deploy");
802         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
803                 OrchestrationStatus.CONFIGDEPLOYED);
804     }
805
806     @Test
807     public void updateOrchestrationStatusVfModuleConfigAssignedTest() throws Exception {
808         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
809                 OrchestrationStatus.CONFIGASSIGNED);
810         aaiUpdateTasks.updateOrchestrationStatus(execution, "vfmodule", "config-assign");
811         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
812                 OrchestrationStatus.CONFIGASSIGNED);
813     }
814 }