2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.aai.tasks;
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;
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;
43 public class AAIUpdateTasksTest extends BaseTaskTest{
45 private AAIUpdateTasks aaiUpdateTasks;
47 private L3Network network;
48 private ServiceInstance serviceInstance;
49 private VfModule vfModule;
50 private GenericVnf genericVnf;
51 private VolumeGroup volumeGroup;
52 private CloudRegion cloudRegion;
55 public void before() {
56 serviceInstance = setServiceInstance();
57 genericVnf = setGenericVnf();
58 vfModule = setVfModule();
59 volumeGroup = setVolumeGroup();
60 cloudRegion = setCloudRegion();
61 network = setL3Network();
65 public void updateOrchestrationStatusAssignedServiceTest() throws Exception {
66 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
68 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
70 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
74 public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception {
75 expectedException.expect(BpmnError.class);
77 doThrow(Exception.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
79 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
83 public void updateOrchestrationStatusActiveServiceTest() throws Exception {
84 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
86 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
88 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
92 public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception {
93 expectedException.expect(BpmnError.class);
95 doThrow(Exception.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
97 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
101 public void updateOrchestrationStatusAssignedVnfTest() throws Exception {
102 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
104 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
106 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
110 public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception {
111 expectedException.expect(BpmnError.class);
113 doThrow(Exception.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
115 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
119 public void updateOrchestrationStatusActiveVnfTest() throws Exception {
120 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
122 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
124 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
128 public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception {
129 expectedException.expect(BpmnError.class);
131 doThrow(Exception.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
133 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
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());
145 public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception {
146 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
148 expectedException.expect(BpmnError.class);
150 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
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);
161 public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
162 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
164 expectedException.expect(BpmnError.class);
166 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
170 public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception {
171 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
173 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
175 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
179 public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
180 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
182 expectedException.expect(BpmnError.class);
184 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
188 public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception {
189 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
191 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
193 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
197 public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
198 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
200 expectedException.expect(BpmnError.class);
202 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
206 public void updateHeatStackIdVfModuleTest() throws Exception {
207 execution.setVariable("heatStackId", "newHeatStackId");
208 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
210 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
212 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
213 assertEquals("newHeatStackId", vfModule.getHeatStackId());
217 public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
218 doThrow(Exception.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
220 expectedException.expect(BpmnError.class);
222 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
226 public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
227 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
229 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
231 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
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);
242 public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
243 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
245 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
247 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
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);
258 public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
259 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
261 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
263 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
264 assertEquals("", volumeGroup.getHeatStackId());
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);
274 public void updateHeatStackIdVolumeGroupTest() throws Exception {
275 execution.setVariable("heatStackId", "newHeatStackId");
276 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
278 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
280 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
281 assertEquals("newHeatStackId", volumeGroup.getHeatStackId());
285 public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
286 expectedException.expect(BpmnError.class);
287 doThrow(Exception.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
288 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
292 public void updateOstatusAssignedNetworkTest() throws Exception {
293 doNothing().when(aaiNetworkResources).updateNetwork(network);
295 aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution);
297 verify(aaiNetworkResources, times(1)).updateNetwork(network);
298 assertEquals("", network.getHeatStackId());
302 public void updateOstatusAssignedNetworkExceptionTest() throws Exception {
303 expectedException.expect(BpmnError.class);
305 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
307 aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution);
311 public void updateOstatusActivedNetworkTest() throws Exception {
312 doNothing().when(aaiNetworkResources).updateNetwork(network);
314 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
316 verify(aaiNetworkResources, times(1)).updateNetwork(network);
320 public void updateOstatusCreatedNetworkTest() throws Exception {
321 doNothing().when(aaiNetworkResources).updateNetwork(network);
323 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
325 verify(aaiNetworkResources, times(1)).updateNetwork(network);
329 public void updateOstatusActiveNetworkExceptionTest() throws Exception {
330 expectedException.expect(BpmnError.class);
332 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
334 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
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());
345 public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
346 expectedException.expect(BpmnError.class);
347 doThrow(Exception.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
348 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
352 public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
353 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
355 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
357 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
361 public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
362 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
364 expectedException.expect(BpmnError.class);
366 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
370 public void updateNetworkCreatedTest() throws Exception {
371 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
372 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
373 createNetworkResponse.setNetworkStackId("testNetworkStackId");
375 execution.setVariable("createNetworkResponse", createNetworkResponse);
377 doNothing().when(aaiNetworkResources).updateNetwork(network);
378 aaiUpdateTasks.updateNetworkCreated(execution);
379 verify(aaiNetworkResources, times(1)).updateNetwork(network);
381 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
382 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
383 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
384 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
388 public void updateNetworkCreatedkExceptionTest() throws Exception {
389 expectedException.expect(BpmnError.class);
390 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
391 aaiUpdateTasks.updateNetworkCreated(execution);
395 public void updateObjectNetworkTest() {
396 doNothing().when(aaiNetworkResources).updateNetwork(network);
398 aaiUpdateTasks.updateObjectNetwork(execution);
400 verify(aaiNetworkResources, times(1)).updateNetwork(network);
404 public void updateObjectNetworkExceptionText() {
405 expectedException.expect(BpmnError.class);
407 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
409 aaiUpdateTasks.updateObjectNetwork(execution);
413 public void test_updateServiceInstance() {
414 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
415 aaiUpdateTasks.updateServiceInstance(execution);
416 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
420 public void test_updateServiceInstance_exception() {
421 expectedException.expect(BpmnError.class);
422 doThrow(Exception.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
423 aaiUpdateTasks.updateServiceInstance(execution);
427 public void updateObjectVnfTest() {
428 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
430 aaiUpdateTasks.updateObjectVnf(execution);
432 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
436 public void updateObjectVnfExceptionTest() {
437 expectedException.expect(BpmnError.class);
438 doThrow(Exception.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
439 aaiUpdateTasks.updateObjectVnf(execution);
443 public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
444 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
446 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
448 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
449 assertEquals("", vfModule.getHeatStackId());
453 public void updateModelVfModuleTest() {
454 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
455 aaiUpdateTasks.updateModelVfModule(execution);
456 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
460 public void updateModelVfModuleExceptionTest() {
461 expectedException.expect(BpmnError.class);
462 doThrow(Exception.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
463 aaiUpdateTasks.updateModelVfModule(execution);