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