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;
35 import java.util.HashMap;
36 import org.camunda.bpm.engine.delegate.BpmnError;
37 import org.hamcrest.Matchers;
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.mockito.ArgumentMatchers;
41 import org.mockito.InjectMocks;
42 import org.mockito.Mockito;
43 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
44 import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
45 import org.onap.so.bpmn.BaseTaskTest;
46 import org.onap.so.bpmn.common.BuildingBlockExecution;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
50 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
51 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
52 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
53 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
54 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
55 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
56 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
57 import org.onap.so.client.exception.BBObjectNotFoundException;
58 import org.onap.so.db.catalog.beans.OrchestrationStatus;
60 public class AAIUpdateTasksTest extends BaseTaskTest {
63 private AAIUpdateTasks aaiUpdateTasks = new AAIUpdateTasks();
65 private L3Network network;
66 private ServiceInstance serviceInstance;
67 private VfModule vfModule;
68 private GenericVnf genericVnf;
69 private VolumeGroup volumeGroup;
70 private CloudRegion cloudRegion;
71 private Configuration configuration;
72 private Subnet subnet;
75 public void before() throws BBObjectNotFoundException {
76 serviceInstance = setServiceInstance();
77 genericVnf = setGenericVnf();
78 vfModule = setVfModule();
79 volumeGroup = setVolumeGroup();
80 cloudRegion = setCloudRegion();
81 network = setL3Network();
82 configuration = setConfiguration();
83 subnet = buildSubnet();
85 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
86 .thenReturn(genericVnf);
87 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
88 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
89 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID)))
90 .thenReturn(volumeGroup);
91 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
92 .thenReturn(serviceInstance);
93 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID)))
94 .thenReturn(configuration);
97 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
98 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
102 public void updateOrchestrationStatusAssignedServiceTest() throws Exception {
103 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance,
104 OrchestrationStatus.ASSIGNED);
106 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
108 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance,
109 OrchestrationStatus.ASSIGNED);
113 public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception {
114 expectedException.expect(BpmnError.class);
116 doThrow(RuntimeException.class).when(aaiServiceInstanceResources)
117 .updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
119 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
123 public void updateOrchestrationStatusActiveServiceTest() throws Exception {
124 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance,
125 OrchestrationStatus.ACTIVE);
127 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
129 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance,
130 OrchestrationStatus.ACTIVE);
134 public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception {
135 expectedException.expect(BpmnError.class);
137 doThrow(RuntimeException.class).when(aaiServiceInstanceResources)
138 .updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
140 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
144 public void updateOrchestrationStatusAssignedVnfTest() throws Exception {
145 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
147 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
149 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
153 public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception {
154 expectedException.expect(BpmnError.class);
156 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
157 OrchestrationStatus.ASSIGNED);
159 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
163 public void updateOrchestrationStatusActiveVnfTest() throws Exception {
164 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
166 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
168 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
172 public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception {
173 expectedException.expect(BpmnError.class);
175 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
176 OrchestrationStatus.ACTIVE);
178 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
182 public void updateOrchestrationStatusAssignVfModuleTest() throws Exception {
183 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
184 OrchestrationStatus.ASSIGNED);
185 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
186 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
187 OrchestrationStatus.ASSIGNED);
188 assertEquals("", vfModule.getHeatStackId());
192 public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception {
193 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
194 genericVnf, OrchestrationStatus.ASSIGNED);
196 expectedException.expect(BpmnError.class);
198 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
202 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleNoMultiStageTest() throws Exception {
203 execution.setVariable("aLaCarte", true);
204 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
205 modelInfoGenericVnf.setMultiStageDesign("false");
206 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
207 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
208 OrchestrationStatus.ASSIGNED);
209 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
210 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
211 OrchestrationStatus.ASSIGNED);
212 assertEquals("", vfModule.getHeatStackId());
216 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleMultiStageButNotAlacarteTest()
218 execution.setVariable("aLaCarte", false);
219 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
220 modelInfoGenericVnf.setMultiStageDesign("true");
221 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
222 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
223 OrchestrationStatus.ASSIGNED);
224 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
225 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
226 OrchestrationStatus.ASSIGNED);
227 assertEquals("", vfModule.getHeatStackId());
231 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleWithMultiStageTest() throws Exception {
232 execution.setVariable("aLaCarte", true);
233 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
234 modelInfoGenericVnf.setMultiStageDesign("true");
235 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
236 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
237 OrchestrationStatus.PENDING_ACTIVATION);
238 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
239 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
240 OrchestrationStatus.PENDING_ACTIVATION);
241 assertEquals("", vfModule.getHeatStackId());
245 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleExceptionTest() throws Exception {
246 execution.setVariable("aLaCarte", true);
247 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
248 genericVnf, OrchestrationStatus.ASSIGNED);
250 expectedException.expect(BpmnError.class);
252 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
256 public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception {
257 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
258 OrchestrationStatus.CREATED);
259 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
260 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
261 OrchestrationStatus.CREATED);
265 public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
266 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
267 genericVnf, OrchestrationStatus.CREATED);
269 expectedException.expect(BpmnError.class);
271 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
275 public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception {
276 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
277 OrchestrationStatus.PENDING_ACTIVATION);
279 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
281 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
282 OrchestrationStatus.PENDING_ACTIVATION);
286 public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
287 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
288 genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
290 expectedException.expect(BpmnError.class);
292 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
296 public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception {
297 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
298 OrchestrationStatus.CREATED);
300 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
302 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
303 OrchestrationStatus.CREATED);
307 public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
308 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
309 genericVnf, OrchestrationStatus.CREATED);
311 expectedException.expect(BpmnError.class);
313 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
317 public void updateHeatStackIdVfModuleTest() throws Exception {
318 execution.setVariable("heatStackId", "newHeatStackId");
319 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
321 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
323 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
324 assertEquals("newHeatStackId", vfModule.getHeatStackId());
328 public void updateHeatStackIdVfModuleToNullTest() throws Exception {
329 execution.setVariable("heatStackId", null);
330 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
332 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
334 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
335 assertEquals(vfModule.getHeatStackId(), "");
339 public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
340 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
342 expectedException.expect(BpmnError.class);
344 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
348 public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
349 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
350 OrchestrationStatus.ACTIVE);
352 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
354 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
355 OrchestrationStatus.ACTIVE);
359 public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
360 expectedException.expect(BpmnError.class);
361 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
362 cloudRegion, OrchestrationStatus.ACTIVE);
363 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
367 public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
368 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
369 OrchestrationStatus.CREATED);
371 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
373 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
374 OrchestrationStatus.CREATED);
378 public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
379 expectedException.expect(BpmnError.class);
380 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
381 cloudRegion, OrchestrationStatus.CREATED);
382 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
386 public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
387 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
388 OrchestrationStatus.ASSIGNED);
390 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
392 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
393 OrchestrationStatus.ASSIGNED);
394 assertEquals("", volumeGroup.getHeatStackId());
398 public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
399 expectedException.expect(BpmnError.class);
400 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
401 cloudRegion, OrchestrationStatus.ASSIGNED);
402 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
406 public void updateHeatStackIdVolumeGroupTest() throws Exception {
407 execution.setVariable("heatStackId", "newHeatStackId");
408 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
410 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
412 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
413 assertEquals("newHeatStackId", volumeGroup.getHeatStackId());
417 public void updateHeatStackIdVolumeGroupToNullTest() throws Exception {
418 execution.setVariable("heatStackId", null);
419 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
421 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
423 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
424 assertEquals(volumeGroup.getHeatStackId(), "");
428 public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
429 expectedException.expect(BpmnError.class);
430 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup,
432 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
436 public void updateNetworkExceptionTest() throws Exception {
437 expectedException.expect(BpmnError.class);
439 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
441 aaiUpdateTasks.updateNetwork(execution, OrchestrationStatus.ACTIVE);
445 public void updateOstatusActivedNetworkCollectionTest() throws Exception {
446 doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
447 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
448 verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
452 public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
453 expectedException.expect(BpmnError.class);
454 doThrow(RuntimeException.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
455 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
459 public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
460 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
461 OrchestrationStatus.ACTIVE);
463 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
465 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
466 OrchestrationStatus.ACTIVE);
470 public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
471 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
472 genericVnf, OrchestrationStatus.ACTIVE);
474 expectedException.expect(BpmnError.class);
476 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
480 public void updateNetworkCreatedTest() throws Exception {
481 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
482 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
483 createNetworkResponse.setNetworkStackId("testNetworkStackId");
484 HashMap<String, String> subnetMap = new HashMap<>();
485 subnetMap.put("testSubnetId", "testNeutronSubnetId");
486 createNetworkResponse.setSubnetMap(subnetMap);
488 network.getSubnets().add(subnet);
490 execution.setVariable("createNetworkResponse", createNetworkResponse);
492 doNothing().when(aaiNetworkResources).updateNetwork(network);
493 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
495 aaiUpdateTasks.updateNetworkCreated(execution);
496 verify(aaiNetworkResources, times(1)).updateNetwork(network);
497 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
499 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
500 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
501 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
502 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
503 String neutronSubnetId = createNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
504 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
508 public void updateNetworkUpdatedTest() throws Exception {
509 UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse();
510 updateNetworkResponse.setNeutronNetworkId("testNeutronNetworkId");
511 HashMap<String, String> subnetMap = new HashMap<>();
512 subnetMap.put("testSubnetId", "testNeutronSubnetId");
513 updateNetworkResponse.setSubnetMap(subnetMap);
515 network.getSubnets().add(subnet);
517 execution.setVariable("updateNetworkResponse", updateNetworkResponse);
519 doNothing().when(aaiNetworkResources).updateNetwork(network);
520 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
522 aaiUpdateTasks.updateNetworkUpdated(execution);
523 verify(aaiNetworkResources, times(1)).updateNetwork(network);
524 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
526 String neutronSubnetId = updateNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
527 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
531 public void updateOrchestrationStatusNetworkTest() {
532 AAIUpdateTasks spy = Mockito.spy(new AAIUpdateTasks());
533 doNothing().when(spy).updateNetwork(eq(execution), any());
534 spy.updateOrchestrationStatusActiveNetwork(execution);
535 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ACTIVE);
536 spy.updateOrchestrationStatusAssignedNetwork(execution);
537 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ASSIGNED);
538 spy.updateOrchestrationStatusCreatedNetwork(execution);
539 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.CREATED);
543 public void updateNetworkAAITest() {
545 L3Network spy = spy(new L3Network());
546 L3Network shallowCopy = mock(L3Network.class);
547 Subnet mockSubnet = mock(Subnet.class);
548 Subnet shallowCopySubnet = mock(Subnet.class);
549 when(mockSubnet.shallowCopyId()).thenReturn(shallowCopySubnet);
550 doReturn(shallowCopy).when(spy).shallowCopyId();
552 doNothing().when(aaiNetworkResources).updateNetwork(network);
553 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
555 spy.getSubnets().add(mockSubnet);
556 aaiUpdateTasks.updateNetworkAAI(spy, OrchestrationStatus.CREATED);
558 verify(shallowCopy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
559 verify(spy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
560 verify(shallowCopySubnet, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
564 public void updateNetworkCreatedkExceptionTest() throws Exception {
565 expectedException.expect(BpmnError.class);
566 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
567 aaiUpdateTasks.updateNetworkCreated(execution);
571 public void updateObjectNetworkTest() {
572 doNothing().when(aaiNetworkResources).updateNetwork(network);
574 aaiUpdateTasks.updateObjectNetwork(execution);
576 verify(aaiNetworkResources, times(1)).updateNetwork(network);
580 public void updateObjectNetworkExceptionText() {
581 expectedException.expect(BpmnError.class);
583 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
585 aaiUpdateTasks.updateObjectNetwork(execution);
589 public void test_updateServiceInstance() {
590 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
591 aaiUpdateTasks.updateServiceInstance(execution);
592 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
596 public void test_updateServiceInstance_exception() {
597 expectedException.expect(BpmnError.class);
598 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
599 aaiUpdateTasks.updateServiceInstance(execution);
603 public void updateObjectVnfTest() {
604 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
606 aaiUpdateTasks.updateObjectVnf(execution);
608 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
612 public void updateObjectVnfExceptionTest() {
613 expectedException.expect(BpmnError.class);
614 doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
615 aaiUpdateTasks.updateObjectVnf(execution);
619 public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
620 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
621 OrchestrationStatus.ASSIGNED);
623 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
625 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
626 OrchestrationStatus.ASSIGNED);
627 assertEquals("", vfModule.getHeatStackId());
631 public void updateModelVfModuleTest() {
632 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
633 aaiUpdateTasks.updateModelVfModule(execution);
634 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
638 public void updateModelVfModuleExceptionTest() {
639 expectedException.expect(BpmnError.class);
640 doThrow(RuntimeException.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
641 aaiUpdateTasks.updateModelVfModule(execution);
645 public void updateOrchestrationStatusDeactivateFabricConfigurationTest() throws Exception {
646 gBBInput = execution.getGeneralBuildingBlock();
647 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
648 OrchestrationStatus.ASSIGNED);
650 aaiUpdateTasks.updateOrchestrationStatusDeactivateFabricConfiguration(execution);
652 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
653 OrchestrationStatus.ASSIGNED);
657 public void updateOrchestrationStatusActivateFabricConfigurationTest() throws Exception {
658 gBBInput = execution.getGeneralBuildingBlock();
659 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
660 OrchestrationStatus.ACTIVE);
662 aaiUpdateTasks.updateOrchestrationStatusActivateFabricConfiguration(execution);
664 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
665 OrchestrationStatus.ACTIVE);
669 public void updateOrchestrationStatusAssignedFabricConfigurationTest() throws Exception {
670 gBBInput = execution.getGeneralBuildingBlock();
671 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
672 OrchestrationStatus.ASSIGNED);
674 aaiUpdateTasks.updateOrchestrationStatusAssignFabricConfiguration(execution);
676 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
677 OrchestrationStatus.ASSIGNED);
681 public void updateContrailServiceInstanceFqdnVfModuleTest() throws Exception {
682 execution.setVariable("contrailServiceInstanceFqdn", "newContrailServiceInstanceFqdn");
683 doNothing().when(aaiVfModuleResources).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
685 aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
687 verify(aaiVfModuleResources, times(1)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
688 assertEquals("newContrailServiceInstanceFqdn", vfModule.getContrailServiceInstanceFqdn());
692 public void updateContrailServiceInstanceFqdnVfModuleNoUpdateTest() throws Exception {
693 aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
694 verify(aaiVfModuleResources, times(0)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
698 public void updateIpv4OamAddressVnfTest() throws Exception {
699 execution.setVariable("oamManagementV4Address", "newIpv4OamAddress");
700 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
702 aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
704 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
705 assertEquals("newIpv4OamAddress", genericVnf.getIpv4OamAddress());
709 public void updateIpv4OamAddressVnfNoUpdateTest() throws Exception {
710 aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
711 verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
715 public void updateManagementV6AddressVnfTest() throws Exception {
716 execution.setVariable("oamManagementV6Address", "newManagementV6Address");
717 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
719 aaiUpdateTasks.updateManagementV6AddressVnf(execution);
721 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
722 assertEquals("newManagementV6Address", genericVnf.getManagementV6Address());
726 public void updateManagementV6AddressVnfNoUpdateTest() throws Exception {
727 aaiUpdateTasks.updateManagementV6AddressVnf(execution);
728 verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
732 public void updateOrchestrationStatusVnfConfigureTest() throws Exception {
733 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
734 OrchestrationStatus.CONFIGURE);
736 aaiUpdateTasks.updateOrchestrationStausConfigDeployConfigureVnf(execution);
740 public void updateOrchestrationStatusVnfConfiguredTest() throws Exception {
741 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
742 OrchestrationStatus.CONFIGURED);
744 aaiUpdateTasks.updateOrchestrationStausConfigDeployConfiguredVnf(execution);