b45752957e2e60a10fd47944854145eb3103e886
[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                 execution.setVariable("heatStackId", "newHeatStackId");
208                 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
209
210                 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
211
212                 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
213                 assertEquals("newHeatStackId", vfModule.getHeatStackId());
214         }
215         
216         @Test
217         public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
218                 doThrow(Exception.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
219                 
220                 expectedException.expect(BpmnError.class);
221         
222                 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
223         }
224         
225         @Test
226         public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
227                 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
228
229                 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
230
231                 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
232         }
233         
234         @Test
235         public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
236                 expectedException.expect(BpmnError.class);
237                 doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
238                 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
239         }
240         
241         @Test
242         public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
243                 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
244
245                 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
246
247                 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
248         }
249         
250         @Test
251         public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
252                 expectedException.expect(BpmnError.class);
253                 doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
254                 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
255         }       
256         
257         @Test
258         public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
259                 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
260
261                 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
262
263                 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
264                 assertEquals("", volumeGroup.getHeatStackId());
265         }
266         
267         @Test
268         public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
269                 expectedException.expect(BpmnError.class);
270                 doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
271                 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
272         }
273         @Test
274         public void updateHeatStackIdVolumeGroupTest() throws Exception {
275                 execution.setVariable("heatStackId", "newHeatStackId");
276                 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
277
278                 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
279
280                 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
281                 assertEquals("newHeatStackId", volumeGroup.getHeatStackId());
282         }
283         
284         @Test
285         public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
286                 expectedException.expect(BpmnError.class);
287                 doThrow(Exception.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
288                 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
289         }
290         
291         @Test
292         public void updateOstatusAssignedNetworkTest() throws Exception {
293                 doNothing().when(aaiNetworkResources).updateNetwork(network);
294
295                 aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution);
296
297                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
298                 assertEquals("", network.getHeatStackId());
299         }
300
301         @Test
302         public void updateOstatusAssignedNetworkExceptionTest() throws Exception {
303                 expectedException.expect(BpmnError.class);
304                 
305                 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
306                 
307                 aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution);
308         }
309         
310         @Test
311         public void updateOstatusActivedNetworkTest() throws Exception {
312                 doNothing().when(aaiNetworkResources).updateNetwork(network);
313
314                 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
315
316                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
317         }
318         
319         @Test
320         public void updateOstatusCreatedNetworkTest() throws Exception {
321                 doNothing().when(aaiNetworkResources).updateNetwork(network);
322
323                 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
324
325                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
326         }
327
328         @Test
329         public void updateOstatusActiveNetworkExceptionTest() throws Exception {
330                 expectedException.expect(BpmnError.class);
331
332                 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
333                 
334                 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
335         }
336         
337         @Test
338         public void updateOstatusActivedNetworkCollectionTest() throws Exception {
339                 doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
340                 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
341                 verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
342         }
343
344         @Test
345         public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
346                 expectedException.expect(BpmnError.class);
347                 doThrow(Exception.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
348                 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
349         }
350
351         @Test
352         public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
353                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
354
355                 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
356
357                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
358         }
359         
360         @Test
361         public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
362                 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
363                 
364                 expectedException.expect(BpmnError.class);
365                 
366                 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
367         }
368         
369         @Test
370         public void updateNetworkCreatedTest() throws Exception {
371                 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
372                 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
373                 createNetworkResponse.setNetworkStackId("testNetworkStackId");
374                 
375                 execution.setVariable("createNetworkResponse", createNetworkResponse);
376                 
377                 doNothing().when(aaiNetworkResources).updateNetwork(network);
378                 aaiUpdateTasks.updateNetworkCreated(execution);
379                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
380                 
381                 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
382                 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
383                 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
384                 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
385         }
386
387         @Test
388         public void updateNetworkCreatedkExceptionTest() throws Exception {
389                 expectedException.expect(BpmnError.class);
390                 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
391                 aaiUpdateTasks.updateNetworkCreated(execution);
392         }
393         
394         @Test
395         public void updateObjectNetworkTest() {
396                 doNothing().when(aaiNetworkResources).updateNetwork(network);
397                 
398                 aaiUpdateTasks.updateObjectNetwork(execution);
399                 
400                 verify(aaiNetworkResources, times(1)).updateNetwork(network);
401         }
402         
403         @Test
404         public void updateObjectNetworkExceptionText() {
405                 expectedException.expect(BpmnError.class);
406                 
407                 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
408                 
409                 aaiUpdateTasks.updateObjectNetwork(execution);
410         }
411         
412         @Test
413         public void test_updateServiceInstance() {
414                 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
415                 aaiUpdateTasks.updateServiceInstance(execution);
416                 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
417         }
418
419         @Test
420         public void test_updateServiceInstance_exception() {
421                 expectedException.expect(BpmnError.class);
422                 doThrow(Exception.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
423                 aaiUpdateTasks.updateServiceInstance(execution);
424         }
425         
426         @Test
427         public void updateObjectVnfTest() {
428                 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
429                 
430                 aaiUpdateTasks.updateObjectVnf(execution);
431                 
432                 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
433         }
434         
435         @Test
436         public void updateObjectVnfExceptionTest() {
437                 expectedException.expect(BpmnError.class);
438                 doThrow(Exception.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
439                 aaiUpdateTasks.updateObjectVnf(execution);
440         }
441         
442         @Test
443         public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
444                 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
445
446                 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
447
448                 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
449                 assertEquals("", vfModule.getHeatStackId());
450         }
451         
452         @Test
453         public void updateModelVfModuleTest() {
454                 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
455                 aaiUpdateTasks.updateModelVfModule(execution);
456                 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
457         }
458         
459         @Test
460         public void updateModelVfModuleExceptionTest() {
461                 expectedException.expect(BpmnError.class);
462                 doThrow(Exception.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
463                 aaiUpdateTasks.updateModelVfModule(execution);
464         }
465 }