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