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