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