Bugfixes for December 2018
[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
36 import java.util.HashMap;
37
38 import org.camunda.bpm.engine.delegate.BpmnError;
39 import org.hamcrest.Matchers;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.mockito.ArgumentMatchers;
43 import org.mockito.InjectMocks;
44 import org.mockito.Mockito;
45 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
46 import org.onap.so.bpmn.BaseTaskTest;
47 import org.onap.so.bpmn.common.BuildingBlockExecution;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
50 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
51 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
52 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
53 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
54 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
55 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
56 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
57 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
58 import org.onap.so.client.exception.BBObjectNotFoundException;
59 import org.onap.so.db.catalog.beans.OrchestrationStatus;
60
61 public class AAIUpdateTasksTest extends BaseTaskTest{
62         
63         @InjectMocks
64         private AAIUpdateTasks aaiUpdateTasks = new AAIUpdateTasks();
65         
66         private L3Network network;
67         private ServiceInstance serviceInstance;
68         private VfModule vfModule;
69         private GenericVnf genericVnf;
70         private VolumeGroup volumeGroup;
71         private CloudRegion cloudRegion;
72         private Configuration configuration;
73         private Subnet subnet;
74         
75         @Before
76         public void before() throws BBObjectNotFoundException {
77                 serviceInstance = setServiceInstance();
78                 genericVnf = setGenericVnf();
79                 vfModule = setVfModule();
80                 volumeGroup = setVolumeGroup();
81                 cloudRegion = setCloudRegion();
82                 network = setL3Network();
83                 configuration = setConfiguration();
84                 subnet = buildSubnet();
85
86                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf);
87                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule);
88                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID), any())).thenReturn(network);
89                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID), any())).thenReturn(volumeGroup);
90                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID), any())).thenReturn(serviceInstance);
91                 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID), any())).thenReturn(configuration);
92                 
93
94                 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
95         }
96         
97         @Test
98         public void updateOrchestrationStatusAssignedServiceTest() throws Exception {
99                 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
100
101                 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
102
103                 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
104         }
105         
106         @Test
107         public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception {
108                 expectedException.expect(BpmnError.class);
109                 
110                 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
111
112                 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
113         }
114         
115         @Test
116         public void updateOrchestrationStatusActiveServiceTest() throws Exception {
117                 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
118
119                 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
120
121                 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
122         }
123         
124         @Test
125         public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception {
126                 expectedException.expect(BpmnError.class);
127                 
128                 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
129
130                 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
131         }
132
133         @Test
134         public void updateOrchestrationStatusAssignedVnfTest() throws Exception {
135                 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
136
137                 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
138
139                 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
140         }
141         
142         @Test
143         public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception {
144                 expectedException.expect(BpmnError.class);
145                 
146                 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
147
148                 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
149         }
150         
151         @Test
152         public void updateOrchestrationStatusActiveVnfTest() throws Exception {
153                 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
154
155                 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
156
157                 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
158         }
159         
160         @Test
161         public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception {
162                 expectedException.expect(BpmnError.class);
163                 
164                 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
165
166                 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
167         }
168         
169         @Test
170         public void updateOrchestrationStatusAssignVfModuleTest() throws Exception {            
171                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
172                 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
173                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
174                 assertEquals("", vfModule.getHeatStackId());
175         }
176         
177         @Test
178         public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception {
179                 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
180                 
181                 expectedException.expect(BpmnError.class);
182                 
183                 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
184         }
185         
186         @Test
187         public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleNoMultiStageTest() throws Exception {
188                 execution.setVariable("aLaCarte", true);
189                 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
190                 modelInfoGenericVnf.setMultiStageDesign("false");
191                 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
192                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
193                 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
194                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
195                 assertEquals("", vfModule.getHeatStackId());
196         }
197         
198         @Test
199         public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleMultiStageButNotAlacarteTest() throws Exception {
200                 execution.setVariable("aLaCarte", false);
201                 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
202                 modelInfoGenericVnf.setMultiStageDesign("true");
203                 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
204                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
205                 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
206                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
207                 assertEquals("", vfModule.getHeatStackId());
208         }
209         
210         @Test
211         public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleWithMultiStageTest() throws Exception {
212                 execution.setVariable("aLaCarte", true);
213                 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
214                 modelInfoGenericVnf.setMultiStageDesign("true");
215                 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
216                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
217                 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
218                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
219                 assertEquals("", vfModule.getHeatStackId());
220         }
221         
222         @Test
223         public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleExceptionTest() throws Exception {
224                 execution.setVariable("aLaCarte", true);
225                 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
226                 
227                 expectedException.expect(BpmnError.class);
228                 
229                 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
230         }
231         
232         @Test
233         public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception {           
234                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
235                 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
236                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
237         }
238         
239         @Test
240         public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
241                 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
242                 
243                 expectedException.expect(BpmnError.class);
244                 
245                 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
246         }
247         
248         @Test
249         public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception {
250                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
251
252                 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
253
254                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
255         }
256         
257         @Test
258         public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
259                 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
260                 
261                 expectedException.expect(BpmnError.class);
262         
263                 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
264         }
265         
266         @Test
267         public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception {
268                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
269
270                 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
271
272                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
273         }
274         
275         @Test
276         public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
277                 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
278                 
279                 expectedException.expect(BpmnError.class);
280         
281                 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
282         }
283         
284         @Test
285         public void updateHeatStackIdVfModuleTest() throws Exception {
286                 execution.setVariable("heatStackId", "newHeatStackId");
287                 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
288
289                 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
290
291                 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
292                 assertEquals("newHeatStackId", vfModule.getHeatStackId());
293         }
294         
295         @Test
296         public void updateHeatStackIdVfModuleToNullTest() throws Exception {
297                 execution.setVariable("heatStackId", null);
298                 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
299
300                 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
301
302                 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
303                 assertEquals(vfModule.getHeatStackId(), "");
304         }
305         
306         @Test
307         public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
308                 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
309                 
310                 expectedException.expect(BpmnError.class);
311         
312                 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
313         }
314         
315         @Test
316         public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
317                 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
318
319                 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
320
321                 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
322         }
323         
324         @Test
325         public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
326                 expectedException.expect(BpmnError.class);
327                 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
328                 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
329         }
330         
331         @Test
332         public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
333                 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
334
335                 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
336
337                 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
338         }
339         
340         @Test
341         public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
342                 expectedException.expect(BpmnError.class);
343                 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
344                 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
345         }       
346         
347         @Test
348         public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
349                 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
350
351                 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
352
353                 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
354                 assertEquals("", volumeGroup.getHeatStackId());
355         }
356         
357         @Test
358         public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
359                 expectedException.expect(BpmnError.class);
360                 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
361                 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
362         }
363         @Test
364         public void updateHeatStackIdVolumeGroupTest() throws Exception {
365                 execution.setVariable("heatStackId", "newHeatStackId");
366                 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
367
368                 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
369
370                 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
371                 assertEquals("newHeatStackId", volumeGroup.getHeatStackId());
372         }
373         @Test
374         public void updateHeatStackIdVolumeGroupToNullTest() throws Exception {
375                 execution.setVariable("heatStackId", null);
376                 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
377
378                 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
379
380                 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
381                 assertEquals(volumeGroup.getHeatStackId(), "");
382         }
383         
384         @Test
385         public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
386                 expectedException.expect(BpmnError.class);
387                 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
388                 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
389         }
390
391         @Test
392         public void updateNetworkExceptionTest() throws Exception {
393                 expectedException.expect(BpmnError.class);
394
395                 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
396                 
397                 aaiUpdateTasks.updateNetwork(execution, OrchestrationStatus.ACTIVE);
398         }
399         
400         @Test
401         public void updateOstatusActivedNetworkCollectionTest() throws Exception {
402                 doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
403                 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
404                 verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
405         }
406
407         @Test
408         public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
409                 expectedException.expect(BpmnError.class);
410                 doThrow(RuntimeException.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
411                 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
412         }
413
414         @Test
415         public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
416                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
417
418                 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
419
420                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
421         }
422         
423         @Test
424         public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
425                 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
426                 
427                 expectedException.expect(BpmnError.class);
428                 
429                 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
430         }
431         
432         @Test
433         public void updateNetworkCreatedTest() throws Exception {
434                 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
435                 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
436                 createNetworkResponse.setNetworkStackId("testNetworkStackId");
437                 HashMap<String, String> subnetMap = new HashMap<>();
438                 subnetMap.put("testSubnetId", "testNeutronSubnetId");
439                 createNetworkResponse.setSubnetMap(subnetMap);
440                 
441                 network.getSubnets().add(subnet);
442                 
443                 execution.setVariable("createNetworkResponse", createNetworkResponse);
444                 
445                 doNothing().when(aaiNetworkResources).updateNetwork(network);
446                 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
447
448                 aaiUpdateTasks.updateNetworkCreated(execution);
449                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
450                 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
451                 
452                 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
453                 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
454                 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
455                 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
456                 String neutronSubnetId = createNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
457                 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
458         }
459
460         @Test
461         public void updateOrchestrationStatusNetworkTest() {
462                 AAIUpdateTasks spy = Mockito.spy(new AAIUpdateTasks());
463                 doNothing().when(spy).updateNetwork(eq(execution), any());
464                 spy.updateOrchestrationStatusActiveNetwork(execution);
465                 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ACTIVE);
466                 spy.updateOrchestrationStatusAssignedNetwork(execution);
467                 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ASSIGNED);
468                 spy.updateOrchestrationStatusCreatedNetwork(execution);
469                 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.CREATED);
470         }
471         
472         @Test
473         public void updateNetworkAAITest() {
474                 
475                 L3Network spy = spy(new L3Network());
476                 L3Network shallowCopy = mock(L3Network.class);
477                 Subnet mockSubnet = mock(Subnet.class);
478                 Subnet shallowCopySubnet = mock(Subnet.class);
479                 when(mockSubnet.shallowCopyId()).thenReturn(shallowCopySubnet);
480                 doReturn(shallowCopy).when(spy).shallowCopyId();
481                                 
482                 doNothing().when(aaiNetworkResources).updateNetwork(network);
483                 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
484                 
485                 spy.getSubnets().add(mockSubnet);
486                 aaiUpdateTasks.updateNetworkAAI(spy, OrchestrationStatus.CREATED);
487                         
488                 verify(shallowCopy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
489                 verify(spy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
490                 verify(shallowCopySubnet, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
491         }
492         @Test
493         public void updateNetworkCreatedkExceptionTest() throws Exception {
494                 expectedException.expect(BpmnError.class);
495                 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
496                 aaiUpdateTasks.updateNetworkCreated(execution);
497         }
498         
499         @Test
500         public void updateObjectNetworkTest() {
501                 doNothing().when(aaiNetworkResources).updateNetwork(network);
502                 
503                 aaiUpdateTasks.updateObjectNetwork(execution);
504                 
505                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
506         }
507         
508         @Test
509         public void updateObjectNetworkExceptionText() {
510                 expectedException.expect(BpmnError.class);
511                 
512                 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
513                 
514                 aaiUpdateTasks.updateObjectNetwork(execution);
515         }
516         
517         @Test
518         public void test_updateServiceInstance() {
519                 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
520                 aaiUpdateTasks.updateServiceInstance(execution);
521                 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
522         }
523
524         @Test
525         public void test_updateServiceInstance_exception() {
526                 expectedException.expect(BpmnError.class);
527                 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
528                 aaiUpdateTasks.updateServiceInstance(execution);
529         }
530         
531         @Test
532         public void updateObjectVnfTest() {
533                 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
534                 
535                 aaiUpdateTasks.updateObjectVnf(execution);
536                 
537                 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
538         }
539         
540         @Test
541         public void updateObjectVnfExceptionTest() {
542                 expectedException.expect(BpmnError.class);
543                 doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
544                 aaiUpdateTasks.updateObjectVnf(execution);
545         }
546         
547         @Test
548         public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
549                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
550
551                 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
552
553                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
554                 assertEquals("", vfModule.getHeatStackId());
555         }
556         
557         @Test
558         public void updateModelVfModuleTest() {
559                 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
560                 aaiUpdateTasks.updateModelVfModule(execution);
561                 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
562         }
563         
564         @Test
565         public void updateModelVfModuleExceptionTest() {
566                 expectedException.expect(BpmnError.class);
567                 doThrow(RuntimeException.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
568                 aaiUpdateTasks.updateModelVfModule(execution);
569         }
570         
571         @Test
572         public void updateOrchestrationStatusDeactivateFabricConfigurationTest() throws Exception {
573                 gBBInput = execution.getGeneralBuildingBlock();
574                 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ASSIGNED);
575
576                 aaiUpdateTasks.updateOrchestrationStatusDeactivateFabricConfiguration(execution);
577
578                 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ASSIGNED);
579         }
580         @Test
581         public void updateOrchestrationStatusActivateFabricConfigurationTest() throws Exception {
582                 gBBInput = execution.getGeneralBuildingBlock();
583                 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ACTIVE);
584
585                 aaiUpdateTasks.updateOrchestrationStatusActivateFabricConfiguration(execution);
586
587                 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ACTIVE);
588         }
589 }