11/7: merge casablanca to master
[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                 execution.setVariable("aLaCarte", true);
188                 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
189                 modelInfoGenericVnf.setMultiStageDesign("false");
190                 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
191                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
192                 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
193                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
194                 assertEquals("", vfModule.getHeatStackId());
195         }
196         
197         @Test
198         public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleMultiStageButNotAlacarteTest() throws Exception {
199                 execution.setVariable("aLaCarte", false);
200                 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
201                 modelInfoGenericVnf.setMultiStageDesign("true");
202                 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
203                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
204                 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
205                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
206                 assertEquals("", vfModule.getHeatStackId());
207         }
208         
209         @Test
210         public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleWithMultiStageTest() throws Exception {
211                 execution.setVariable("aLaCarte", true);
212                 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
213                 modelInfoGenericVnf.setMultiStageDesign("true");
214                 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
215                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
216                 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
217                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
218                 assertEquals("", vfModule.getHeatStackId());
219         }
220         
221         @Test
222         public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleExceptionTest() throws Exception {
223                 execution.setVariable("aLaCarte", true);
224                 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
225                 
226                 expectedException.expect(BpmnError.class);
227                 
228                 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
229         }
230         
231         @Test
232         public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception {           
233                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
234                 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
235                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
236         }
237         
238         @Test
239         public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
240                 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
241                 
242                 expectedException.expect(BpmnError.class);
243                 
244                 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
245         }
246         
247         @Test
248         public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception {
249                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
250
251                 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
252
253                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
254         }
255         
256         @Test
257         public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
258                 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
259                 
260                 expectedException.expect(BpmnError.class);
261         
262                 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
263         }
264         
265         @Test
266         public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception {
267                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
268
269                 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
270
271                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
272         }
273         
274         @Test
275         public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
276                 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
277                 
278                 expectedException.expect(BpmnError.class);
279         
280                 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
281         }
282         
283         @Test
284         public void updateHeatStackIdVfModuleTest() throws Exception {
285                 execution.setVariable("heatStackId", "newHeatStackId");
286                 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
287
288                 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
289
290                 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
291                 assertEquals("newHeatStackId", vfModule.getHeatStackId());
292         }
293         
294         @Test
295         public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
296                 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
297                 
298                 expectedException.expect(BpmnError.class);
299         
300                 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
301         }
302         
303         @Test
304         public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
305                 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
306
307                 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
308
309                 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
310         }
311         
312         @Test
313         public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
314                 expectedException.expect(BpmnError.class);
315                 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
316                 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
317         }
318         
319         @Test
320         public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
321                 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
322
323                 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
324
325                 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
326         }
327         
328         @Test
329         public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
330                 expectedException.expect(BpmnError.class);
331                 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
332                 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
333         }       
334         
335         @Test
336         public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
337                 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
338
339                 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
340
341                 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
342                 assertEquals("", volumeGroup.getHeatStackId());
343         }
344         
345         @Test
346         public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
347                 expectedException.expect(BpmnError.class);
348                 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
349                 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
350         }
351         @Test
352         public void updateHeatStackIdVolumeGroupTest() throws Exception {
353                 execution.setVariable("heatStackId", "newHeatStackId");
354                 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
355
356                 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
357
358                 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
359                 assertEquals("newHeatStackId", volumeGroup.getHeatStackId());
360         }
361         
362         @Test
363         public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
364                 expectedException.expect(BpmnError.class);
365                 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
366                 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
367         }
368
369         @Test
370         public void updateNetworkExceptionTest() throws Exception {
371                 expectedException.expect(BpmnError.class);
372
373                 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
374                 
375                 aaiUpdateTasks.updateNetwork(execution, OrchestrationStatus.ACTIVE);
376         }
377         
378         @Test
379         public void updateOstatusActivedNetworkCollectionTest() throws Exception {
380                 doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
381                 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
382                 verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
383         }
384
385         @Test
386         public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
387                 expectedException.expect(BpmnError.class);
388                 doThrow(RuntimeException.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
389                 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
390         }
391
392         @Test
393         public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
394                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
395
396                 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
397
398                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
399         }
400         
401         @Test
402         public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
403                 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
404                 
405                 expectedException.expect(BpmnError.class);
406                 
407                 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
408         }
409         
410         @Test
411         public void updateNetworkCreatedTest() throws Exception {
412                 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
413                 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
414                 createNetworkResponse.setNetworkStackId("testNetworkStackId");
415                 HashMap<String, String> subnetMap = new HashMap<>();
416                 subnetMap.put("testSubnetId", "testNeutronSubnetId");
417                 createNetworkResponse.setSubnetMap(subnetMap);
418                 
419                 network.getSubnets().add(subnet);
420                 
421                 execution.setVariable("createNetworkResponse", createNetworkResponse);
422                 
423                 doNothing().when(aaiNetworkResources).updateNetwork(network);
424                 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
425
426                 aaiUpdateTasks.updateNetworkCreated(execution);
427                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
428                 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
429                 
430                 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
431                 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
432                 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
433                 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
434                 String neutronSubnetId = createNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
435                 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
436         }
437
438         @Test
439         public void updateOrchestrationStatusNetworkTest() {
440                 AAIUpdateTasks spy = Mockito.spy(new AAIUpdateTasks());
441                 doNothing().when(spy).updateNetwork(eq(execution), any());
442                 spy.updateOrchestrationStatusActiveNetwork(execution);
443                 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ACTIVE);
444                 spy.updateOrchestrationStatusAssignedNetwork(execution);
445                 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ASSIGNED);
446                 spy.updateOrchestrationStatusCreatedNetwork(execution);
447                 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.CREATED);
448         }
449         
450         @Test
451         public void updateNetworkAAITest() {
452                 
453                 L3Network spy = spy(new L3Network());
454                 L3Network shallowCopy = mock(L3Network.class);
455                 Subnet mockSubnet = mock(Subnet.class);
456                 Subnet shallowCopySubnet = mock(Subnet.class);
457                 when(mockSubnet.shallowCopyId()).thenReturn(shallowCopySubnet);
458                 doReturn(shallowCopy).when(spy).shallowCopyId();
459                                 
460                 doNothing().when(aaiNetworkResources).updateNetwork(network);
461                 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
462                 
463                 spy.getSubnets().add(mockSubnet);
464                 aaiUpdateTasks.updateNetworkAAI(spy, OrchestrationStatus.CREATED);
465                         
466                 verify(shallowCopy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
467                 verify(spy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
468                 verify(shallowCopySubnet, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
469         }
470         @Test
471         public void updateNetworkCreatedkExceptionTest() throws Exception {
472                 expectedException.expect(BpmnError.class);
473                 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
474                 aaiUpdateTasks.updateNetworkCreated(execution);
475         }
476         
477         @Test
478         public void updateObjectNetworkTest() {
479                 doNothing().when(aaiNetworkResources).updateNetwork(network);
480                 
481                 aaiUpdateTasks.updateObjectNetwork(execution);
482                 
483                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
484         }
485         
486         @Test
487         public void updateObjectNetworkExceptionText() {
488                 expectedException.expect(BpmnError.class);
489                 
490                 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
491                 
492                 aaiUpdateTasks.updateObjectNetwork(execution);
493         }
494         
495         @Test
496         public void test_updateServiceInstance() {
497                 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
498                 aaiUpdateTasks.updateServiceInstance(execution);
499                 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
500         }
501
502         @Test
503         public void test_updateServiceInstance_exception() {
504                 expectedException.expect(BpmnError.class);
505                 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
506                 aaiUpdateTasks.updateServiceInstance(execution);
507         }
508         
509         @Test
510         public void updateObjectVnfTest() {
511                 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
512                 
513                 aaiUpdateTasks.updateObjectVnf(execution);
514                 
515                 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
516         }
517         
518         @Test
519         public void updateObjectVnfExceptionTest() {
520                 expectedException.expect(BpmnError.class);
521                 doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
522                 aaiUpdateTasks.updateObjectVnf(execution);
523         }
524         
525         @Test
526         public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
527                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
528
529                 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
530
531                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
532                 assertEquals("", vfModule.getHeatStackId());
533         }
534         
535         @Test
536         public void updateModelVfModuleTest() {
537                 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
538                 aaiUpdateTasks.updateModelVfModule(execution);
539                 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
540         }
541         
542         @Test
543         public void updateModelVfModuleExceptionTest() {
544                 expectedException.expect(BpmnError.class);
545                 doThrow(RuntimeException.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
546                 aaiUpdateTasks.updateModelVfModule(execution);
547         }
548         
549         @Test
550         public void updateOrchestrationStatusDeactivateFabricConfigurationTest() throws Exception {
551                 gBBInput = execution.getGeneralBuildingBlock();
552                 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ASSIGNED);
553
554                 aaiUpdateTasks.updateOrchestrationStatusDeactivateFabricConfiguration(execution);
555
556                 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ASSIGNED);
557         }
558         @Test
559         public void updateOrchestrationStatusActivateFabricConfigurationTest() throws Exception {
560                 gBBInput = execution.getGeneralBuildingBlock();
561                 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ACTIVE);
562
563                 aaiUpdateTasks.updateOrchestrationStatusActivateFabricConfiguration(execution);
564
565                 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ACTIVE);
566         }
567 }