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