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 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
209 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
211 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
215 public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
216 doThrow(Exception.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
218 expectedException.expect(BpmnError.class);
220 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
224 public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
225 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
227 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
229 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
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);
240 public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
241 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
243 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
245 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
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);
256 public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
257 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
259 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
261 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
262 assertEquals("", volumeGroup.getHeatStackId());
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);
272 public void updateHeatStackIdVolumeGroupTest() throws Exception {
273 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
275 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
277 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
281 public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
282 expectedException.expect(BpmnError.class);
283 doThrow(Exception.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
284 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
288 public void updateOstatusAssignedNetworkTest() throws Exception {
289 doNothing().when(aaiNetworkResources).updateNetwork(network);
291 aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution);
293 verify(aaiNetworkResources, times(1)).updateNetwork(network);
294 assertEquals("", network.getHeatStackId());
298 public void updateOstatusAssignedNetworkExceptionTest() throws Exception {
299 expectedException.expect(BpmnError.class);
301 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
303 aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution);
307 public void updateOstatusActivedNetworkTest() throws Exception {
308 doNothing().when(aaiNetworkResources).updateNetwork(network);
310 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
312 verify(aaiNetworkResources, times(1)).updateNetwork(network);
316 public void updateOstatusCreatedNetworkTest() throws Exception {
317 doNothing().when(aaiNetworkResources).updateNetwork(network);
319 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
321 verify(aaiNetworkResources, times(1)).updateNetwork(network);
325 public void updateOstatusActiveNetworkExceptionTest() throws Exception {
326 expectedException.expect(BpmnError.class);
328 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
330 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
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());
341 public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
342 expectedException.expect(BpmnError.class);
343 doThrow(Exception.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
344 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
348 public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
349 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
351 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
353 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
357 public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
358 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
360 expectedException.expect(BpmnError.class);
362 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
366 public void updateNetworkCreatedTest() throws Exception {
367 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
368 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
369 createNetworkResponse.setNetworkStackId("testNetworkStackId");
371 execution.setVariable("createNetworkResponse", createNetworkResponse);
373 doNothing().when(aaiNetworkResources).updateNetwork(network);
374 aaiUpdateTasks.updateNetworkCreated(execution);
375 verify(aaiNetworkResources, times(1)).updateNetwork(network);
377 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
378 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
379 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
380 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
384 public void updateNetworkCreatedkExceptionTest() throws Exception {
385 expectedException.expect(BpmnError.class);
386 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
387 aaiUpdateTasks.updateNetworkCreated(execution);
391 public void updateObjectNetworkTest() {
392 doNothing().when(aaiNetworkResources).updateNetwork(network);
394 aaiUpdateTasks.updateObjectNetwork(execution);
396 verify(aaiNetworkResources, times(1)).updateNetwork(network);
400 public void updateObjectNetworkExceptionText() {
401 expectedException.expect(BpmnError.class);
403 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
405 aaiUpdateTasks.updateObjectNetwork(execution);
409 public void test_updateServiceInstance() {
410 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
411 aaiUpdateTasks.updateServiceInstance(execution);
412 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
416 public void test_updateServiceInstance_exception() {
417 expectedException.expect(BpmnError.class);
418 doThrow(Exception.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
419 aaiUpdateTasks.updateServiceInstance(execution);
423 public void updateObjectVnfTest() {
424 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
426 aaiUpdateTasks.updateObjectVnf(execution);
428 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
432 public void updateObjectVnfExceptionTest() {
433 expectedException.expect(BpmnError.class);
434 doThrow(Exception.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
435 aaiUpdateTasks.updateObjectVnf(execution);
439 public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
440 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
442 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
444 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
445 assertEquals("", vfModule.getHeatStackId());
449 public void updateModelVfModuleTest() {
450 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
451 aaiUpdateTasks.updateModelVfModule(execution);
452 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
456 public void updateModelVfModuleExceptionTest() {
457 expectedException.expect(BpmnError.class);
458 doThrow(Exception.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
459 aaiUpdateTasks.updateModelVfModule(execution);