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