c9433a6212aeb1562b980c6917f412a7f9b7c72a
[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.Mockito.doNothing;
25 import static org.mockito.Mockito.doThrow;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28
29 import org.camunda.bpm.engine.delegate.BpmnError;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
33 import org.onap.so.bpmn.BaseTaskTest;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
40 import org.onap.so.db.catalog.beans.OrchestrationStatus;
41 import org.springframework.beans.factory.annotation.Autowired;
42
43 public class AAIUpdateTasksTest extends BaseTaskTest{
44         @Autowired
45         private AAIUpdateTasks aaiUpdateTasks;
46         
47         private L3Network network;
48         private ServiceInstance serviceInstance;
49         private VfModule vfModule;
50         private GenericVnf genericVnf;
51         private VolumeGroup volumeGroup;
52         private CloudRegion cloudRegion;
53         
54         @Before
55         public void before() {
56                 serviceInstance = setServiceInstance();
57                 genericVnf = setGenericVnf();
58                 vfModule = setVfModule();
59                 volumeGroup = setVolumeGroup();
60                 cloudRegion = setCloudRegion();
61                 network = setL3Network();
62         }
63         
64         @Test
65         public void updateOrchestrationStatusAssignedServiceTest() throws Exception {
66                 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
67
68                 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
69
70                 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
71         }
72         
73         @Test
74         public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception {
75                 expectedException.expect(BpmnError.class);
76                 
77                 doThrow(Exception.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
78
79                 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
80         }
81         
82         @Test
83         public void updateOrchestrationStatusActiveServiceTest() throws Exception {
84                 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
85
86                 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
87
88                 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
89         }
90         
91         @Test
92         public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception {
93                 expectedException.expect(BpmnError.class);
94                 
95                 doThrow(Exception.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
96
97                 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
98         }
99
100         @Test
101         public void updateOrchestrationStatusAssignedVnfTest() throws Exception {
102                 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
103
104                 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
105
106                 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
107         }
108         
109         @Test
110         public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception {
111                 expectedException.expect(BpmnError.class);
112                 
113                 doThrow(Exception.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
114
115                 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
116         }
117         
118         @Test
119         public void updateOrchestrationStatusActiveVnfTest() throws Exception {
120                 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
121
122                 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
123
124                 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
125         }
126         
127         @Test
128         public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception {
129                 expectedException.expect(BpmnError.class);
130                 
131                 doThrow(Exception.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
132
133                 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
134         }
135         
136         @Test
137         public void updateOrchestrationStatusAssignVfModuleTest() throws Exception {            
138                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
139                 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
140                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
141                 assertEquals("", vfModule.getHeatStackId());
142         }
143         
144         @Test
145         public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception {
146                 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
147                 
148                 expectedException.expect(BpmnError.class);
149                 
150                 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
151         }
152         
153         @Test
154         public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception {           
155                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
156                 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
157                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
158         }
159         
160         @Test
161         public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
162                 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
163                 
164                 expectedException.expect(BpmnError.class);
165                 
166                 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
167         }
168         
169         @Test
170         public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception {
171                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
172
173                 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
174
175                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
176         }
177         
178         @Test
179         public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
180                 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
181                 
182                 expectedException.expect(BpmnError.class);
183         
184                 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
185         }
186         
187         @Test
188         public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception {
189                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
190
191                 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
192
193                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
194         }
195         
196         @Test
197         public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
198                 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
199                 
200                 expectedException.expect(BpmnError.class);
201         
202                 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
203         }
204         
205         @Test
206         public void updateHeatStackIdVfModuleTest() throws Exception {
207                 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
208
209                 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
210
211                 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
212         }
213         
214         @Test
215         public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
216                 doThrow(Exception.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
217                 
218                 expectedException.expect(BpmnError.class);
219         
220                 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
221         }
222         
223         @Test
224         public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
225                 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
226
227                 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
228
229                 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
230         }
231         
232         @Test
233         public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
234                 expectedException.expect(BpmnError.class);
235                 doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
236                 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
237         }
238         
239         @Test
240         public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
241                 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
242
243                 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
244
245                 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
246         }
247         
248         @Test
249         public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
250                 expectedException.expect(BpmnError.class);
251                 doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
252                 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
253         }       
254         
255         @Test
256         public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
257                 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
258
259                 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
260
261                 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
262                 assertEquals("", volumeGroup.getHeatStackId());
263         }
264         
265         @Test
266         public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
267                 expectedException.expect(BpmnError.class);
268                 doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
269                 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
270         }
271         @Test
272         public void updateHeatStackIdVolumeGroupTest() throws Exception {
273                 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
274
275                 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
276
277                 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
278         }
279         
280         @Test
281         public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
282                 expectedException.expect(BpmnError.class);
283                 doThrow(Exception.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
284                 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
285         }
286         
287         @Test
288         public void updateOstatusAssignedNetworkTest() throws Exception {
289                 doNothing().when(aaiNetworkResources).updateNetwork(network);
290
291                 aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution);
292
293                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
294                 assertEquals("", network.getHeatStackId());
295         }
296
297         @Test
298         public void updateOstatusAssignedNetworkExceptionTest() throws Exception {
299                 expectedException.expect(BpmnError.class);
300                 
301                 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
302                 
303                 aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution);
304         }
305         
306         @Test
307         public void updateOstatusActivedNetworkTest() throws Exception {
308                 doNothing().when(aaiNetworkResources).updateNetwork(network);
309
310                 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
311
312                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
313         }
314         
315         @Test
316         public void updateOstatusCreatedNetworkTest() throws Exception {
317                 doNothing().when(aaiNetworkResources).updateNetwork(network);
318
319                 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
320
321                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
322         }
323
324         @Test
325         public void updateOstatusActiveNetworkExceptionTest() throws Exception {
326                 expectedException.expect(BpmnError.class);
327
328                 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
329                 
330                 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
331         }
332         
333         @Test
334         public void updateOstatusActivedNetworkCollectionTest() throws Exception {
335                 doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
336                 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
337                 verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
338         }
339
340         @Test
341         public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
342                 expectedException.expect(BpmnError.class);
343                 doThrow(Exception.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
344                 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
345         }
346
347         @Test
348         public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
349                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
350
351                 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
352
353                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
354         }
355         
356         @Test
357         public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
358                 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
359                 
360                 expectedException.expect(BpmnError.class);
361                 
362                 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
363         }
364         
365         @Test
366         public void updateNetworkCreatedTest() throws Exception {
367                 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
368                 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
369                 createNetworkResponse.setNetworkStackId("testNetworkStackId");
370                 
371                 execution.setVariable("createNetworkResponse", createNetworkResponse);
372                 
373                 doNothing().when(aaiNetworkResources).updateNetwork(network);
374                 aaiUpdateTasks.updateNetworkCreated(execution);
375                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
376                 
377                 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
378                 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
379                 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
380                 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
381         }
382
383         @Test
384         public void updateNetworkCreatedkExceptionTest() throws Exception {
385                 expectedException.expect(BpmnError.class);
386                 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
387                 aaiUpdateTasks.updateNetworkCreated(execution);
388         }
389         
390         @Test
391         public void updateObjectNetworkTest() {
392                 doNothing().when(aaiNetworkResources).updateNetwork(network);
393                 
394                 aaiUpdateTasks.updateObjectNetwork(execution);
395                 
396                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
397         }
398         
399         @Test
400         public void updateObjectNetworkExceptionText() {
401                 expectedException.expect(BpmnError.class);
402                 
403                 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
404                 
405                 aaiUpdateTasks.updateObjectNetwork(execution);
406         }
407         
408         @Test
409         public void test_updateServiceInstance() {
410                 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
411                 aaiUpdateTasks.updateServiceInstance(execution);
412                 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
413         }
414
415         @Test
416         public void test_updateServiceInstance_exception() {
417                 expectedException.expect(BpmnError.class);
418                 doThrow(Exception.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
419                 aaiUpdateTasks.updateServiceInstance(execution);
420         }
421         
422         @Test
423         public void updateObjectVnfTest() {
424                 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
425                 
426                 aaiUpdateTasks.updateObjectVnf(execution);
427                 
428                 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
429         }
430         
431         @Test
432         public void updateObjectVnfExceptionTest() {
433                 expectedException.expect(BpmnError.class);
434                 doThrow(Exception.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
435                 aaiUpdateTasks.updateObjectVnf(execution);
436         }
437         
438         @Test
439         public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
440                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
441
442                 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
443
444                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
445                 assertEquals("", vfModule.getHeatStackId());
446         }
447         
448         @Test
449         public void updateModelVfModuleTest() {
450                 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
451                 aaiUpdateTasks.updateModelVfModule(execution);
452                 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
453         }
454         
455         @Test
456         public void updateModelVfModuleExceptionTest() {
457                 expectedException.expect(BpmnError.class);
458                 doThrow(Exception.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
459                 aaiUpdateTasks.updateModelVfModule(execution);
460         }
461 }