AssignPnfBB - set orchestration status to Assigned after successful assignment
[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     @Test
143     public void updateOrchestrationStatusAssignedPnfTest() throws Exception {
144         Pnf pnf = preparePnfAndExtractForPnf();
145         doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ASSIGNED);
146
147         aaiUpdateTasks.updateOrchestrationStatusAssignedPnf(execution);
148
149         verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ASSIGNED);
150     }
151
152     @Test
153     public void updateOrchestrationStatusAssignedPnfExceptionTest() throws Exception {
154         Pnf pnf = preparePnfAndExtractForPnf();
155         doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
156                 OrchestrationStatus.ASSIGNED);
157
158         expectedException.expect(BpmnError.class);
159         aaiUpdateTasks.updateOrchestrationStatusAssignedPnf(execution);
160     }
161
162     @Test
163     public void updateOrchestrationStatusActivePnfTest() throws Exception {
164         Pnf pnf = preparePnfAndExtractForPnf();
165         doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
166
167         aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
168
169         verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
170     }
171
172     @Test
173     public void updateOrchestrationStatusActivePnfExceptionTest() throws Exception {
174         Pnf pnf = preparePnfAndExtractForPnf();
175         doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
176                 OrchestrationStatus.ACTIVE);
177
178         expectedException.expect(BpmnError.class);
179         aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
180     }
181
182     @Test
183     public void updateOrchestrationStatusRegisterPnfTest() throws Exception {
184         Pnf pnf = preparePnfAndExtractForPnf();
185         doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTER);
186
187         aaiUpdateTasks.updateOrchestrationStatusRegisterPnf(execution);
188
189         verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTER);
190     }
191
192     @Test
193     public void updateOrchestrationStatusRegisteredPnfTest() throws Exception {
194         Pnf pnf = preparePnfAndExtractForPnf();
195         doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTERED);
196
197         aaiUpdateTasks.updateOrchestrationStatusRegisteredPnf(execution);
198
199         verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTERED);
200     }
201
202     @Test
203     public void updateOrchestrationStatusAssignedVnfTest() throws Exception {
204         doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
205
206         aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
207
208         verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
209     }
210
211     @Test
212     public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception {
213         expectedException.expect(BpmnError.class);
214
215         doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
216                 OrchestrationStatus.ASSIGNED);
217
218         aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
219     }
220
221     @Test
222     public void updateOrchestrationStatusActiveVnfTest() throws Exception {
223         doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
224
225         aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
226
227         verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
228     }
229
230     @Test
231     public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception {
232         expectedException.expect(BpmnError.class);
233
234         doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
235                 OrchestrationStatus.ACTIVE);
236
237         aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
238     }
239
240     @Test
241     public void updateOrchestrationStatusAssignVfModuleTest() throws Exception {
242         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
243                 OrchestrationStatus.ASSIGNED);
244         aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
245         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
246                 OrchestrationStatus.ASSIGNED);
247         assertEquals("", vfModule.getHeatStackId());
248     }
249
250     @Test
251     public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception {
252         doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
253                 genericVnf, OrchestrationStatus.ASSIGNED);
254
255         expectedException.expect(BpmnError.class);
256
257         aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
258     }
259
260     @Test
261     public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleNoMultiStageTest() throws Exception {
262         execution.setVariable("aLaCarte", true);
263         ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
264         modelInfoGenericVnf.setMultiStageDesign("false");
265         genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
266         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
267                 OrchestrationStatus.ASSIGNED);
268         aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
269         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
270                 OrchestrationStatus.ASSIGNED);
271         assertEquals("", vfModule.getHeatStackId());
272     }
273
274     @Test
275     public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleMultiStageButNotAlacarteTest()
276             throws Exception {
277         execution.setVariable("aLaCarte", false);
278         ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
279         modelInfoGenericVnf.setMultiStageDesign("true");
280         genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
281         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
282                 OrchestrationStatus.ASSIGNED);
283         aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
284         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
285                 OrchestrationStatus.ASSIGNED);
286         assertEquals("", vfModule.getHeatStackId());
287     }
288
289     @Test
290     public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleWithMultiStageTest() throws Exception {
291         execution.setVariable("aLaCarte", true);
292         ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
293         modelInfoGenericVnf.setMultiStageDesign("true");
294         genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
295         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
296                 OrchestrationStatus.PENDING_ACTIVATION);
297         aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
298         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
299                 OrchestrationStatus.PENDING_ACTIVATION);
300         assertEquals("", vfModule.getHeatStackId());
301     }
302
303     @Test
304     public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleExceptionTest() throws Exception {
305         execution.setVariable("aLaCarte", true);
306         doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
307                 genericVnf, OrchestrationStatus.ASSIGNED);
308
309         expectedException.expect(BpmnError.class);
310
311         aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
312     }
313
314     @Test
315     public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception {
316         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
317                 OrchestrationStatus.CREATED);
318         aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
319         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
320                 OrchestrationStatus.CREATED);
321     }
322
323     @Test
324     public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
325         doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
326                 genericVnf, OrchestrationStatus.CREATED);
327
328         expectedException.expect(BpmnError.class);
329
330         aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
331     }
332
333     @Test
334     public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception {
335         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
336                 OrchestrationStatus.PENDING_ACTIVATION);
337
338         aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
339
340         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
341                 OrchestrationStatus.PENDING_ACTIVATION);
342     }
343
344     @Test
345     public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
346         doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
347                 genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
348
349         expectedException.expect(BpmnError.class);
350
351         aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
352     }
353
354     @Test
355     public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception {
356         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
357                 OrchestrationStatus.CREATED);
358
359         aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
360
361         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
362                 OrchestrationStatus.CREATED);
363     }
364
365     @Test
366     public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
367         doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
368                 genericVnf, OrchestrationStatus.CREATED);
369
370         expectedException.expect(BpmnError.class);
371
372         aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
373     }
374
375     @Test
376     public void updateHeatStackIdVfModuleTest() throws Exception {
377         execution.setVariable("heatStackId", "newHeatStackId");
378         doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
379
380         aaiUpdateTasks.updateHeatStackIdVfModule(execution);
381
382         verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
383         assertEquals("newHeatStackId", vfModule.getHeatStackId());
384     }
385
386     @Test
387     public void updateHeatStackIdVfModuleToNullTest() throws Exception {
388         execution.setVariable("heatStackId", null);
389         doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
390
391         aaiUpdateTasks.updateHeatStackIdVfModule(execution);
392
393         verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
394         assertEquals(vfModule.getHeatStackId(), "");
395     }
396
397     @Test
398     public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
399         doThrow(RuntimeException.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
400
401         expectedException.expect(BpmnError.class);
402
403         aaiUpdateTasks.updateHeatStackIdVfModule(execution);
404     }
405
406     @Test
407     public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
408         doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
409                 OrchestrationStatus.ACTIVE);
410
411         aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
412
413         verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
414                 OrchestrationStatus.ACTIVE);
415     }
416
417     @Test
418     public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
419         expectedException.expect(BpmnError.class);
420         doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
421                 cloudRegion, OrchestrationStatus.ACTIVE);
422         aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
423     }
424
425     @Test
426     public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
427         doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
428                 OrchestrationStatus.CREATED);
429
430         aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
431
432         verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
433                 OrchestrationStatus.CREATED);
434     }
435
436     @Test
437     public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
438         expectedException.expect(BpmnError.class);
439         doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
440                 cloudRegion, OrchestrationStatus.CREATED);
441         aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
442     }
443
444     @Test
445     public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
446         doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
447                 OrchestrationStatus.ASSIGNED);
448
449         aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
450
451         verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
452                 OrchestrationStatus.ASSIGNED);
453         assertEquals("", volumeGroup.getHeatStackId());
454     }
455
456     @Test
457     public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
458         expectedException.expect(BpmnError.class);
459         doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
460                 cloudRegion, OrchestrationStatus.ASSIGNED);
461         aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
462     }
463
464     @Test
465     public void updateHeatStackIdVolumeGroupTest() throws Exception {
466         execution.setVariable("heatStackId", "newHeatStackId");
467         doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
468
469         aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
470
471         verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
472         assertEquals("newHeatStackId", volumeGroup.getHeatStackId());
473     }
474
475     @Test
476     public void updateHeatStackIdVolumeGroupToNullTest() throws Exception {
477         execution.setVariable("heatStackId", null);
478         doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
479
480         aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
481
482         verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
483         assertEquals(volumeGroup.getHeatStackId(), "");
484     }
485
486     @Test
487     public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
488         expectedException.expect(BpmnError.class);
489         doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup,
490                 cloudRegion);
491         aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
492     }
493
494     @Test
495     public void updateNetworkExceptionTest() throws Exception {
496         expectedException.expect(BpmnError.class);
497
498         doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
499
500         aaiUpdateTasks.updateNetwork(execution, OrchestrationStatus.ACTIVE);
501     }
502
503     @Test
504     public void updateOstatusActivedNetworkCollectionTest() throws Exception {
505         doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
506         aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
507         verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
508     }
509
510     @Test
511     public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
512         expectedException.expect(BpmnError.class);
513         doThrow(RuntimeException.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
514         aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
515     }
516
517     @Test
518     public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
519         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
520                 OrchestrationStatus.ACTIVE);
521
522         aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
523
524         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
525                 OrchestrationStatus.ACTIVE);
526     }
527
528     @Test
529     public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
530         doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
531                 genericVnf, OrchestrationStatus.ACTIVE);
532
533         expectedException.expect(BpmnError.class);
534
535         aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
536     }
537
538     @Test
539     public void updateNetworkCreatedTest() throws Exception {
540         CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
541         createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
542         createNetworkResponse.setNetworkStackId("testNetworkStackId");
543         HashMap<String, String> subnetMap = new HashMap<>();
544         subnetMap.put("testSubnetId", "testNeutronSubnetId");
545         createNetworkResponse.setSubnetMap(subnetMap);
546
547         network.getSubnets().add(subnet);
548
549         execution.setVariable("createNetworkResponse", createNetworkResponse);
550
551         doNothing().when(aaiNetworkResources).updateNetwork(network);
552         doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
553
554         aaiUpdateTasks.updateNetworkCreated(execution);
555         verify(aaiNetworkResources, times(1)).updateNetwork(network);
556         verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
557
558         assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
559         assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
560         assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
561         assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
562         String neutronSubnetId = createNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
563         assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
564     }
565
566     @Test
567     public void updateNetworkUpdatedTest() throws Exception {
568         UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse();
569         updateNetworkResponse.setNeutronNetworkId("testNeutronNetworkId");
570         HashMap<String, String> subnetMap = new HashMap<>();
571         subnetMap.put("testSubnetId", "testNeutronSubnetId");
572         updateNetworkResponse.setSubnetMap(subnetMap);
573
574         network.getSubnets().add(subnet);
575
576         execution.setVariable("updateNetworkResponse", updateNetworkResponse);
577
578         doNothing().when(aaiNetworkResources).updateNetwork(network);
579         doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
580
581         aaiUpdateTasks.updateNetworkUpdated(execution);
582         verify(aaiNetworkResources, times(1)).updateNetwork(network);
583         verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
584
585         String neutronSubnetId = updateNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
586         assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
587     }
588
589     @Test
590     public void updateOrchestrationStatusNetworkTest() {
591         AAIUpdateTasks spy = Mockito.spy(new AAIUpdateTasks());
592         doNothing().when(spy).updateNetwork(eq(execution), any());
593         spy.updateOrchestrationStatusActiveNetwork(execution);
594         verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ACTIVE);
595         spy.updateOrchestrationStatusAssignedNetwork(execution);
596         verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ASSIGNED);
597         spy.updateOrchestrationStatusCreatedNetwork(execution);
598         verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.CREATED);
599     }
600
601     @Test
602     public void updateNetworkAAITest() {
603
604         L3Network spy = spy(new L3Network());
605         L3Network shallowCopy = mock(L3Network.class);
606         Subnet mockSubnet = mock(Subnet.class);
607         Subnet shallowCopySubnet = mock(Subnet.class);
608         when(mockSubnet.shallowCopyId()).thenReturn(shallowCopySubnet);
609         doReturn(shallowCopy).when(spy).shallowCopyId();
610
611         doNothing().when(aaiNetworkResources).updateNetwork(network);
612         doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
613
614         spy.getSubnets().add(mockSubnet);
615         aaiUpdateTasks.updateNetworkAAI(spy, OrchestrationStatus.CREATED);
616
617         verify(shallowCopy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
618         verify(spy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
619         verify(shallowCopySubnet, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
620     }
621
622     @Test
623     public void updateNetworkCreatedkExceptionTest() throws Exception {
624         expectedException.expect(BpmnError.class);
625         doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
626         aaiUpdateTasks.updateNetworkCreated(execution);
627     }
628
629     @Test
630     public void updateObjectNetworkTest() {
631         doNothing().when(aaiNetworkResources).updateNetwork(network);
632
633         aaiUpdateTasks.updateObjectNetwork(execution);
634
635         verify(aaiNetworkResources, times(1)).updateNetwork(network);
636     }
637
638     @Test
639     public void updateObjectNetworkExceptionText() {
640         expectedException.expect(BpmnError.class);
641
642         doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
643
644         aaiUpdateTasks.updateObjectNetwork(execution);
645     }
646
647     @Test
648     public void test_updateServiceInstance() {
649         doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
650         aaiUpdateTasks.updateServiceInstance(execution);
651         verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
652     }
653
654     @Test
655     public void test_updateServiceInstance_exception() {
656         expectedException.expect(BpmnError.class);
657         doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
658         aaiUpdateTasks.updateServiceInstance(execution);
659     }
660
661     @Test
662     public void updateObjectVnfTest() {
663         doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
664
665         aaiUpdateTasks.updateObjectVnf(execution);
666
667         verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
668     }
669
670     @Test
671     public void updateObjectVnfExceptionTest() {
672         expectedException.expect(BpmnError.class);
673         doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
674         aaiUpdateTasks.updateObjectVnf(execution);
675     }
676
677     @Test
678     public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
679         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
680                 OrchestrationStatus.ASSIGNED);
681
682         aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
683
684         verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
685                 OrchestrationStatus.ASSIGNED);
686         assertEquals("", vfModule.getHeatStackId());
687     }
688
689     @Test
690     public void updateModelVfModuleTest() {
691         doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
692         aaiUpdateTasks.updateModelVfModule(execution);
693         verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
694     }
695
696     @Test
697     public void updateModelVfModuleExceptionTest() {
698         expectedException.expect(BpmnError.class);
699         doThrow(RuntimeException.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
700         aaiUpdateTasks.updateModelVfModule(execution);
701     }
702
703     @Test
704     public void updateOrchestrationStatusDeactivateFabricConfigurationTest() throws Exception {
705         gBBInput = execution.getGeneralBuildingBlock();
706         doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
707                 OrchestrationStatus.ASSIGNED);
708
709         aaiUpdateTasks.updateOrchestrationStatusDeactivateFabricConfiguration(execution);
710
711         verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
712                 OrchestrationStatus.ASSIGNED);
713     }
714
715     @Test
716     public void updateOrchestrationStatusActivateFabricConfigurationTest() throws Exception {
717         gBBInput = execution.getGeneralBuildingBlock();
718         doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
719                 OrchestrationStatus.ACTIVE);
720
721         aaiUpdateTasks.updateOrchestrationStatusActivateFabricConfiguration(execution);
722
723         verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
724                 OrchestrationStatus.ACTIVE);
725     }
726
727     @Test
728     public void updateOrchestrationStatusAssignedFabricConfigurationTest() throws Exception {
729         gBBInput = execution.getGeneralBuildingBlock();
730         doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
731                 OrchestrationStatus.ASSIGNED);
732
733         aaiUpdateTasks.updateOrchestrationStatusAssignFabricConfiguration(execution);
734
735         verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
736                 OrchestrationStatus.ASSIGNED);
737     }
738
739     @Test
740     public void updateContrailServiceInstanceFqdnVfModuleTest() throws Exception {
741         execution.setVariable("contrailServiceInstanceFqdn", "newContrailServiceInstanceFqdn");
742         doNothing().when(aaiVfModuleResources).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
743
744         aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
745
746         verify(aaiVfModuleResources, times(1)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
747         assertEquals("newContrailServiceInstanceFqdn", vfModule.getContrailServiceInstanceFqdn());
748     }
749
750     @Test
751     public void updateContrailServiceInstanceFqdnVfModuleNoUpdateTest() throws Exception {
752         aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
753         verify(aaiVfModuleResources, times(0)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
754     }
755
756     @Test
757     public void updateIpv4OamAddressVnfTest() throws Exception {
758         execution.setVariable("oamManagementV4Address", "newIpv4OamAddress");
759         doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
760
761         aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
762
763         verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
764         assertEquals("newIpv4OamAddress", genericVnf.getIpv4OamAddress());
765     }
766
767     @Test
768     public void updateIpv4OamAddressVnfNoUpdateTest() throws Exception {
769         aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
770         verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
771     }
772
773     @Test
774     public void updateManagementV6AddressVnfTest() throws Exception {
775         execution.setVariable("oamManagementV6Address", "newManagementV6Address");
776         doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
777
778         aaiUpdateTasks.updateManagementV6AddressVnf(execution);
779
780         verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
781         assertEquals("newManagementV6Address", genericVnf.getManagementV6Address());
782     }
783
784     @Test
785     public void updateManagementV6AddressVnfNoUpdateTest() throws Exception {
786         aaiUpdateTasks.updateManagementV6AddressVnf(execution);
787         verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
788     }
789
790     @Test
791     public void updateOrchestrationStatusVnfConfigureTest() throws Exception {
792         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
793                 OrchestrationStatus.CONFIGURE);
794
795         aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfigureVnf(execution);
796     }
797
798     @Test
799     public void updateOrchestrationStatusVnfConfiguredTest() throws Exception {
800         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
801                 OrchestrationStatus.CONFIGURED);
802
803         aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfiguredVnf(execution);
804     }
805
806     private Pnf preparePnfAndExtractForPnf() throws BBObjectNotFoundException {
807         Pnf pnf = buildPnf();
808         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf);
809         return pnf;
810     }
811 }