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.junit.Assert.assertNull;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.ArgumentMatchers.eq;
27 import static org.mockito.Mockito.doNothing;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.doThrow;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.spy;
32 import static org.mockito.Mockito.times;
33 import static org.mockito.Mockito.verify;
34 import static org.mockito.Mockito.when;
36 import java.util.HashMap;
38 import org.camunda.bpm.engine.delegate.BpmnError;
39 import org.hamcrest.Matchers;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.mockito.ArgumentMatchers;
43 import org.mockito.InjectMocks;
44 import org.mockito.Mockito;
45 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
46 import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
47 import org.onap.so.bpmn.BaseTaskTest;
48 import org.onap.so.bpmn.common.BuildingBlockExecution;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
50 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
51 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
52 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
53 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
54 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
55 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
56 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
57 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
58 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
59 import org.onap.so.client.exception.BBObjectNotFoundException;
60 import org.onap.so.db.catalog.beans.OrchestrationStatus;
62 public class AAIUpdateTasksTest extends BaseTaskTest{
65 private AAIUpdateTasks aaiUpdateTasks = new AAIUpdateTasks();
67 private L3Network network;
68 private ServiceInstance serviceInstance;
69 private VfModule vfModule;
70 private GenericVnf genericVnf;
71 private VolumeGroup volumeGroup;
72 private CloudRegion cloudRegion;
73 private Configuration configuration;
74 private Subnet subnet;
77 public void before() throws BBObjectNotFoundException {
78 serviceInstance = setServiceInstance();
79 genericVnf = setGenericVnf();
80 vfModule = setVfModule();
81 volumeGroup = setVolumeGroup();
82 cloudRegion = setCloudRegion();
83 network = setL3Network();
84 configuration = setConfiguration();
85 subnet = buildSubnet();
87 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(genericVnf);
88 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
89 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
90 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID))).thenReturn(volumeGroup);
91 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))).thenReturn(serviceInstance);
92 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID))).thenReturn(configuration);
95 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
99 public void updateOrchestrationStatusAssignedServiceTest() throws Exception {
100 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
102 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
104 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
108 public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception {
109 expectedException.expect(BpmnError.class);
111 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
113 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
117 public void updateOrchestrationStatusActiveServiceTest() throws Exception {
118 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
120 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
122 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
126 public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception {
127 expectedException.expect(BpmnError.class);
129 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
131 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
135 public void updateOrchestrationStatusAssignedVnfTest() throws Exception {
136 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
138 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
140 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
144 public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception {
145 expectedException.expect(BpmnError.class);
147 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
149 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
153 public void updateOrchestrationStatusActiveVnfTest() throws Exception {
154 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
156 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
158 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
162 public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception {
163 expectedException.expect(BpmnError.class);
165 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
167 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
171 public void updateOrchestrationStatusAssignVfModuleTest() throws Exception {
172 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
173 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
174 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
175 assertEquals("", vfModule.getHeatStackId());
179 public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception {
180 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
182 expectedException.expect(BpmnError.class);
184 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
188 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleNoMultiStageTest() throws Exception {
189 execution.setVariable("aLaCarte", true);
190 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
191 modelInfoGenericVnf.setMultiStageDesign("false");
192 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
193 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
194 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
195 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
196 assertEquals("", vfModule.getHeatStackId());
200 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleMultiStageButNotAlacarteTest() throws Exception {
201 execution.setVariable("aLaCarte", false);
202 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
203 modelInfoGenericVnf.setMultiStageDesign("true");
204 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
205 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
206 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
207 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
208 assertEquals("", vfModule.getHeatStackId());
212 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleWithMultiStageTest() throws Exception {
213 execution.setVariable("aLaCarte", true);
214 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
215 modelInfoGenericVnf.setMultiStageDesign("true");
216 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
217 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
218 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
219 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
220 assertEquals("", vfModule.getHeatStackId());
224 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleExceptionTest() throws Exception {
225 execution.setVariable("aLaCarte", true);
226 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
228 expectedException.expect(BpmnError.class);
230 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
234 public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception {
235 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
236 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
237 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
241 public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
242 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
244 expectedException.expect(BpmnError.class);
246 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
250 public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception {
251 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
253 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
255 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
259 public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
260 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
262 expectedException.expect(BpmnError.class);
264 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
268 public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception {
269 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
271 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
273 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
277 public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
278 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
280 expectedException.expect(BpmnError.class);
282 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
286 public void updateHeatStackIdVfModuleTest() throws Exception {
287 execution.setVariable("heatStackId", "newHeatStackId");
288 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
290 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
292 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
293 assertEquals("newHeatStackId", vfModule.getHeatStackId());
297 public void updateHeatStackIdVfModuleToNullTest() throws Exception {
298 execution.setVariable("heatStackId", null);
299 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
301 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
303 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
304 assertEquals(vfModule.getHeatStackId(), "");
308 public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
309 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
311 expectedException.expect(BpmnError.class);
313 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
317 public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
318 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
320 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
322 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
326 public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
327 expectedException.expect(BpmnError.class);
328 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
329 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
333 public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
334 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
336 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
338 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
342 public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
343 expectedException.expect(BpmnError.class);
344 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
345 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
349 public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
350 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
352 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
354 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
355 assertEquals("", volumeGroup.getHeatStackId());
359 public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
360 expectedException.expect(BpmnError.class);
361 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
362 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
365 public void updateHeatStackIdVolumeGroupTest() throws Exception {
366 execution.setVariable("heatStackId", "newHeatStackId");
367 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
369 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
371 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
372 assertEquals("newHeatStackId", volumeGroup.getHeatStackId());
375 public void updateHeatStackIdVolumeGroupToNullTest() throws Exception {
376 execution.setVariable("heatStackId", null);
377 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
379 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
381 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
382 assertEquals(volumeGroup.getHeatStackId(), "");
386 public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
387 expectedException.expect(BpmnError.class);
388 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
389 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
393 public void updateNetworkExceptionTest() throws Exception {
394 expectedException.expect(BpmnError.class);
396 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
398 aaiUpdateTasks.updateNetwork(execution, OrchestrationStatus.ACTIVE);
402 public void updateOstatusActivedNetworkCollectionTest() throws Exception {
403 doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
404 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
405 verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
409 public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
410 expectedException.expect(BpmnError.class);
411 doThrow(RuntimeException.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
412 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
416 public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
417 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
419 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
421 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
425 public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
426 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
428 expectedException.expect(BpmnError.class);
430 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
434 public void updateNetworkCreatedTest() throws Exception {
435 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
436 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
437 createNetworkResponse.setNetworkStackId("testNetworkStackId");
438 HashMap<String, String> subnetMap = new HashMap<>();
439 subnetMap.put("testSubnetId", "testNeutronSubnetId");
440 createNetworkResponse.setSubnetMap(subnetMap);
442 network.getSubnets().add(subnet);
444 execution.setVariable("createNetworkResponse", createNetworkResponse);
446 doNothing().when(aaiNetworkResources).updateNetwork(network);
447 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
449 aaiUpdateTasks.updateNetworkCreated(execution);
450 verify(aaiNetworkResources, times(1)).updateNetwork(network);
451 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
453 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
454 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
455 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
456 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
457 String neutronSubnetId = createNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
458 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
462 public void updateNetworkUpdatedTest() throws Exception {
463 UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse();
464 updateNetworkResponse.setNeutronNetworkId("testNeutronNetworkId");
465 HashMap<String, String> subnetMap = new HashMap<>();
466 subnetMap.put("testSubnetId", "testNeutronSubnetId");
467 updateNetworkResponse.setSubnetMap(subnetMap);
469 network.getSubnets().add(subnet);
471 execution.setVariable("updateNetworkResponse", updateNetworkResponse);
473 doNothing().when(aaiNetworkResources).updateNetwork(network);
474 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
476 aaiUpdateTasks.updateNetworkUpdated(execution);
477 verify(aaiNetworkResources, times(1)).updateNetwork(network);
478 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
480 String neutronSubnetId = updateNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
481 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
485 public void updateOrchestrationStatusNetworkTest() {
486 AAIUpdateTasks spy = Mockito.spy(new AAIUpdateTasks());
487 doNothing().when(spy).updateNetwork(eq(execution), any());
488 spy.updateOrchestrationStatusActiveNetwork(execution);
489 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ACTIVE);
490 spy.updateOrchestrationStatusAssignedNetwork(execution);
491 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ASSIGNED);
492 spy.updateOrchestrationStatusCreatedNetwork(execution);
493 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.CREATED);
497 public void updateNetworkAAITest() {
499 L3Network spy = spy(new L3Network());
500 L3Network shallowCopy = mock(L3Network.class);
501 Subnet mockSubnet = mock(Subnet.class);
502 Subnet shallowCopySubnet = mock(Subnet.class);
503 when(mockSubnet.shallowCopyId()).thenReturn(shallowCopySubnet);
504 doReturn(shallowCopy).when(spy).shallowCopyId();
506 doNothing().when(aaiNetworkResources).updateNetwork(network);
507 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
509 spy.getSubnets().add(mockSubnet);
510 aaiUpdateTasks.updateNetworkAAI(spy, OrchestrationStatus.CREATED);
512 verify(shallowCopy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
513 verify(spy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
514 verify(shallowCopySubnet, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
517 public void updateNetworkCreatedkExceptionTest() throws Exception {
518 expectedException.expect(BpmnError.class);
519 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
520 aaiUpdateTasks.updateNetworkCreated(execution);
524 public void updateObjectNetworkTest() {
525 doNothing().when(aaiNetworkResources).updateNetwork(network);
527 aaiUpdateTasks.updateObjectNetwork(execution);
529 verify(aaiNetworkResources, times(1)).updateNetwork(network);
533 public void updateObjectNetworkExceptionText() {
534 expectedException.expect(BpmnError.class);
536 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
538 aaiUpdateTasks.updateObjectNetwork(execution);
542 public void test_updateServiceInstance() {
543 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
544 aaiUpdateTasks.updateServiceInstance(execution);
545 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
549 public void test_updateServiceInstance_exception() {
550 expectedException.expect(BpmnError.class);
551 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
552 aaiUpdateTasks.updateServiceInstance(execution);
556 public void updateObjectVnfTest() {
557 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
559 aaiUpdateTasks.updateObjectVnf(execution);
561 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
565 public void updateObjectVnfExceptionTest() {
566 expectedException.expect(BpmnError.class);
567 doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
568 aaiUpdateTasks.updateObjectVnf(execution);
572 public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
573 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
575 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
577 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
578 assertEquals("", vfModule.getHeatStackId());
582 public void updateModelVfModuleTest() {
583 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
584 aaiUpdateTasks.updateModelVfModule(execution);
585 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
589 public void updateModelVfModuleExceptionTest() {
590 expectedException.expect(BpmnError.class);
591 doThrow(RuntimeException.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
592 aaiUpdateTasks.updateModelVfModule(execution);
596 public void updateOrchestrationStatusDeactivateFabricConfigurationTest() throws Exception {
597 gBBInput = execution.getGeneralBuildingBlock();
598 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ASSIGNED);
600 aaiUpdateTasks.updateOrchestrationStatusDeactivateFabricConfiguration(execution);
602 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ASSIGNED);
605 public void updateOrchestrationStatusActivateFabricConfigurationTest() throws Exception {
606 gBBInput = execution.getGeneralBuildingBlock();
607 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ACTIVE);
609 aaiUpdateTasks.updateOrchestrationStatusActivateFabricConfiguration(execution);
611 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ACTIVE);
614 public void updateContrailServiceInstanceFqdnVfModuleTest() throws Exception {
615 execution.setVariable("contrailServiceInstanceFqdn", "newContrailServiceInstanceFqdn");
616 doNothing().when(aaiVfModuleResources).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
618 aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
620 verify(aaiVfModuleResources, times(1)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
621 assertEquals("newContrailServiceInstanceFqdn", vfModule.getContrailServiceInstanceFqdn());
624 public void updateContrailServiceInstanceFqdnVfModuleNoUpdateTest() throws Exception {
625 aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
626 verify(aaiVfModuleResources, times(0)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
629 public void updateIpv4OamAddressVnfTest() throws Exception {
630 execution.setVariable("oamManagementV4Address", "newIpv4OamAddress");
631 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
633 aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
635 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
636 assertEquals("newIpv4OamAddress", genericVnf.getIpv4OamAddress());
639 public void updateIpv4OamAddressVnfNoUpdateTest() throws Exception {
640 aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
641 verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
644 public void updateManagementV6AddressVnfTest() throws Exception {
645 execution.setVariable("oamManagementV6Address", "newManagementV6Address");
646 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
648 aaiUpdateTasks.updateManagementV6AddressVnf(execution);
650 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
651 assertEquals("newManagementV6Address", genericVnf.getManagementV6Address());
654 public void updateManagementV6AddressVnfNoUpdateTest() throws Exception {
655 aaiUpdateTasks.updateManagementV6AddressVnf(execution);
656 verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);