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 org.camunda.bpm.engine.delegate.BpmnError;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.ArgumentMatchers;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mockito;
29 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
30 import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
31 import org.onap.so.bpmn.BaseTaskTest;
32 import org.onap.so.bpmn.common.BuildingBlockExecution;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
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.Pnf;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
42 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
43 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
44 import org.onap.so.client.exception.BBObjectNotFoundException;
45 import org.onap.so.db.catalog.beans.OrchestrationStatus;
46 import java.util.HashMap;
47 import static org.junit.Assert.assertEquals;
48 import static org.mockito.ArgumentMatchers.any;
49 import static org.mockito.ArgumentMatchers.eq;
50 import static org.mockito.Mockito.doNothing;
51 import static org.mockito.Mockito.doReturn;
52 import static org.mockito.Mockito.doThrow;
53 import static org.mockito.Mockito.mock;
54 import static org.mockito.Mockito.spy;
55 import static org.mockito.Mockito.times;
56 import static org.mockito.Mockito.verify;
57 import static org.mockito.Mockito.when;
59 public class AAIUpdateTasksTest extends BaseTaskTest {
62 private AAIUpdateTasks aaiUpdateTasks = new AAIUpdateTasks();
64 private L3Network network;
65 private ServiceInstance serviceInstance;
66 private VfModule vfModule;
67 private GenericVnf genericVnf;
68 private VolumeGroup volumeGroup;
69 private CloudRegion cloudRegion;
70 private Configuration configuration;
71 private Subnet subnet;
74 public void before() throws BBObjectNotFoundException {
75 serviceInstance = setServiceInstance();
76 genericVnf = setGenericVnf();
77 vfModule = setVfModule();
78 volumeGroup = setVolumeGroup();
79 cloudRegion = setCloudRegion();
80 network = setL3Network();
81 configuration = setConfiguration();
82 subnet = buildSubnet();
84 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
85 .thenReturn(genericVnf);
86 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
87 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
88 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID)))
89 .thenReturn(volumeGroup);
90 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
91 .thenReturn(serviceInstance);
92 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID)))
93 .thenReturn(configuration);
96 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
97 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
101 public void updateOrchestrationStatusAssignedServiceTest() throws Exception {
102 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance,
103 OrchestrationStatus.ASSIGNED);
105 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
107 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance,
108 OrchestrationStatus.ASSIGNED);
112 public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception {
113 expectedException.expect(BpmnError.class);
115 doThrow(RuntimeException.class).when(aaiServiceInstanceResources)
116 .updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
118 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
122 public void updateOrchestrationStatusActiveServiceTest() throws Exception {
123 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance,
124 OrchestrationStatus.ACTIVE);
126 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
128 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance,
129 OrchestrationStatus.ACTIVE);
133 public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception {
134 expectedException.expect(BpmnError.class);
136 doThrow(RuntimeException.class).when(aaiServiceInstanceResources)
137 .updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
139 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
144 public void updateOrchestrationStatusActivePnfTest() throws Exception {
145 Pnf pnf = preparePnfAndExtractForPnf();
146 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
148 aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
150 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
154 public void updateOrchestrationStatusActivePnfExceptionTest() throws Exception {
155 Pnf pnf = preparePnfAndExtractForPnf();
156 doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
157 OrchestrationStatus.ACTIVE);
159 expectedException.expect(BpmnError.class);
160 aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
164 public void updateOrchestrationStatusAssignedVnfTest() throws Exception {
165 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
167 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
169 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
173 public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception {
174 expectedException.expect(BpmnError.class);
176 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
177 OrchestrationStatus.ASSIGNED);
179 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
183 public void updateOrchestrationStatusActiveVnfTest() throws Exception {
184 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
186 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
188 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
192 public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception {
193 expectedException.expect(BpmnError.class);
195 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
196 OrchestrationStatus.ACTIVE);
198 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
202 public void updateOrchestrationStatusAssignVfModuleTest() throws Exception {
203 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
204 OrchestrationStatus.ASSIGNED);
205 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
206 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
207 OrchestrationStatus.ASSIGNED);
208 assertEquals("", vfModule.getHeatStackId());
212 public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception {
213 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
214 genericVnf, OrchestrationStatus.ASSIGNED);
216 expectedException.expect(BpmnError.class);
218 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
222 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleNoMultiStageTest() throws Exception {
223 execution.setVariable("aLaCarte", true);
224 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
225 modelInfoGenericVnf.setMultiStageDesign("false");
226 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
227 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
228 OrchestrationStatus.ASSIGNED);
229 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
230 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
231 OrchestrationStatus.ASSIGNED);
232 assertEquals("", vfModule.getHeatStackId());
236 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleMultiStageButNotAlacarteTest()
238 execution.setVariable("aLaCarte", false);
239 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
240 modelInfoGenericVnf.setMultiStageDesign("true");
241 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
242 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
243 OrchestrationStatus.ASSIGNED);
244 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
245 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
246 OrchestrationStatus.ASSIGNED);
247 assertEquals("", vfModule.getHeatStackId());
251 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleWithMultiStageTest() throws Exception {
252 execution.setVariable("aLaCarte", true);
253 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
254 modelInfoGenericVnf.setMultiStageDesign("true");
255 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
256 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
257 OrchestrationStatus.PENDING_ACTIVATION);
258 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
259 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
260 OrchestrationStatus.PENDING_ACTIVATION);
261 assertEquals("", vfModule.getHeatStackId());
265 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleExceptionTest() throws Exception {
266 execution.setVariable("aLaCarte", true);
267 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
268 genericVnf, OrchestrationStatus.ASSIGNED);
270 expectedException.expect(BpmnError.class);
272 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
276 public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception {
277 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
278 OrchestrationStatus.CREATED);
279 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
280 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
281 OrchestrationStatus.CREATED);
285 public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
286 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
287 genericVnf, OrchestrationStatus.CREATED);
289 expectedException.expect(BpmnError.class);
291 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
295 public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception {
296 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
297 OrchestrationStatus.PENDING_ACTIVATION);
299 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
301 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
302 OrchestrationStatus.PENDING_ACTIVATION);
306 public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
307 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
308 genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
310 expectedException.expect(BpmnError.class);
312 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
316 public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception {
317 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
318 OrchestrationStatus.CREATED);
320 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
322 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
323 OrchestrationStatus.CREATED);
327 public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
328 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
329 genericVnf, OrchestrationStatus.CREATED);
331 expectedException.expect(BpmnError.class);
333 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
337 public void updateHeatStackIdVfModuleTest() throws Exception {
338 execution.setVariable("heatStackId", "newHeatStackId");
339 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
341 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
343 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
344 assertEquals("newHeatStackId", vfModule.getHeatStackId());
348 public void updateHeatStackIdVfModuleToNullTest() throws Exception {
349 execution.setVariable("heatStackId", null);
350 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
352 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
354 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
355 assertEquals(vfModule.getHeatStackId(), "");
359 public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
360 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
362 expectedException.expect(BpmnError.class);
364 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
368 public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
369 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
370 OrchestrationStatus.ACTIVE);
372 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
374 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
375 OrchestrationStatus.ACTIVE);
379 public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
380 expectedException.expect(BpmnError.class);
381 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
382 cloudRegion, OrchestrationStatus.ACTIVE);
383 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
387 public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
388 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
389 OrchestrationStatus.CREATED);
391 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
393 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
394 OrchestrationStatus.CREATED);
398 public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
399 expectedException.expect(BpmnError.class);
400 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
401 cloudRegion, OrchestrationStatus.CREATED);
402 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
406 public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
407 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
408 OrchestrationStatus.ASSIGNED);
410 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
412 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
413 OrchestrationStatus.ASSIGNED);
414 assertEquals("", volumeGroup.getHeatStackId());
418 public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
419 expectedException.expect(BpmnError.class);
420 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
421 cloudRegion, OrchestrationStatus.ASSIGNED);
422 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
426 public void updateHeatStackIdVolumeGroupTest() throws Exception {
427 execution.setVariable("heatStackId", "newHeatStackId");
428 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
430 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
432 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
433 assertEquals("newHeatStackId", volumeGroup.getHeatStackId());
437 public void updateHeatStackIdVolumeGroupToNullTest() throws Exception {
438 execution.setVariable("heatStackId", null);
439 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
441 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
443 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
444 assertEquals(volumeGroup.getHeatStackId(), "");
448 public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
449 expectedException.expect(BpmnError.class);
450 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup,
452 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
456 public void updateNetworkExceptionTest() throws Exception {
457 expectedException.expect(BpmnError.class);
459 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
461 aaiUpdateTasks.updateNetwork(execution, OrchestrationStatus.ACTIVE);
465 public void updateOstatusActivedNetworkCollectionTest() throws Exception {
466 doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
467 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
468 verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
472 public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
473 expectedException.expect(BpmnError.class);
474 doThrow(RuntimeException.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
475 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
479 public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
480 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
481 OrchestrationStatus.ACTIVE);
483 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
485 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
486 OrchestrationStatus.ACTIVE);
490 public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
491 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
492 genericVnf, OrchestrationStatus.ACTIVE);
494 expectedException.expect(BpmnError.class);
496 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
500 public void updateNetworkCreatedTest() throws Exception {
501 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
502 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
503 createNetworkResponse.setNetworkStackId("testNetworkStackId");
504 HashMap<String, String> subnetMap = new HashMap<>();
505 subnetMap.put("testSubnetId", "testNeutronSubnetId");
506 createNetworkResponse.setSubnetMap(subnetMap);
508 network.getSubnets().add(subnet);
510 execution.setVariable("createNetworkResponse", createNetworkResponse);
512 doNothing().when(aaiNetworkResources).updateNetwork(network);
513 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
515 aaiUpdateTasks.updateNetworkCreated(execution);
516 verify(aaiNetworkResources, times(1)).updateNetwork(network);
517 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
519 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
520 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
521 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
522 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
523 String neutronSubnetId = createNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
524 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
528 public void updateNetworkUpdatedTest() throws Exception {
529 UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse();
530 updateNetworkResponse.setNeutronNetworkId("testNeutronNetworkId");
531 HashMap<String, String> subnetMap = new HashMap<>();
532 subnetMap.put("testSubnetId", "testNeutronSubnetId");
533 updateNetworkResponse.setSubnetMap(subnetMap);
535 network.getSubnets().add(subnet);
537 execution.setVariable("updateNetworkResponse", updateNetworkResponse);
539 doNothing().when(aaiNetworkResources).updateNetwork(network);
540 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
542 aaiUpdateTasks.updateNetworkUpdated(execution);
543 verify(aaiNetworkResources, times(1)).updateNetwork(network);
544 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
546 String neutronSubnetId = updateNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
547 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
551 public void updateOrchestrationStatusNetworkTest() {
552 AAIUpdateTasks spy = Mockito.spy(new AAIUpdateTasks());
553 doNothing().when(spy).updateNetwork(eq(execution), any());
554 spy.updateOrchestrationStatusActiveNetwork(execution);
555 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ACTIVE);
556 spy.updateOrchestrationStatusAssignedNetwork(execution);
557 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ASSIGNED);
558 spy.updateOrchestrationStatusCreatedNetwork(execution);
559 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.CREATED);
563 public void updateNetworkAAITest() {
565 L3Network spy = spy(new L3Network());
566 L3Network shallowCopy = mock(L3Network.class);
567 Subnet mockSubnet = mock(Subnet.class);
568 Subnet shallowCopySubnet = mock(Subnet.class);
569 when(mockSubnet.shallowCopyId()).thenReturn(shallowCopySubnet);
570 doReturn(shallowCopy).when(spy).shallowCopyId();
572 doNothing().when(aaiNetworkResources).updateNetwork(network);
573 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
575 spy.getSubnets().add(mockSubnet);
576 aaiUpdateTasks.updateNetworkAAI(spy, OrchestrationStatus.CREATED);
578 verify(shallowCopy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
579 verify(spy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
580 verify(shallowCopySubnet, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
584 public void updateNetworkCreatedkExceptionTest() throws Exception {
585 expectedException.expect(BpmnError.class);
586 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
587 aaiUpdateTasks.updateNetworkCreated(execution);
591 public void updateObjectNetworkTest() {
592 doNothing().when(aaiNetworkResources).updateNetwork(network);
594 aaiUpdateTasks.updateObjectNetwork(execution);
596 verify(aaiNetworkResources, times(1)).updateNetwork(network);
600 public void updateObjectNetworkExceptionText() {
601 expectedException.expect(BpmnError.class);
603 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
605 aaiUpdateTasks.updateObjectNetwork(execution);
609 public void test_updateServiceInstance() {
610 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
611 aaiUpdateTasks.updateServiceInstance(execution);
612 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
616 public void test_updateServiceInstance_exception() {
617 expectedException.expect(BpmnError.class);
618 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
619 aaiUpdateTasks.updateServiceInstance(execution);
623 public void updateObjectVnfTest() {
624 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
626 aaiUpdateTasks.updateObjectVnf(execution);
628 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
632 public void updateObjectVnfExceptionTest() {
633 expectedException.expect(BpmnError.class);
634 doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
635 aaiUpdateTasks.updateObjectVnf(execution);
639 public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
640 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
641 OrchestrationStatus.ASSIGNED);
643 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
645 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
646 OrchestrationStatus.ASSIGNED);
647 assertEquals("", vfModule.getHeatStackId());
651 public void updateModelVfModuleTest() {
652 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
653 aaiUpdateTasks.updateModelVfModule(execution);
654 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
658 public void updateModelVfModuleExceptionTest() {
659 expectedException.expect(BpmnError.class);
660 doThrow(RuntimeException.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
661 aaiUpdateTasks.updateModelVfModule(execution);
665 public void updateOrchestrationStatusDeactivateFabricConfigurationTest() throws Exception {
666 gBBInput = execution.getGeneralBuildingBlock();
667 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
668 OrchestrationStatus.ASSIGNED);
670 aaiUpdateTasks.updateOrchestrationStatusDeactivateFabricConfiguration(execution);
672 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
673 OrchestrationStatus.ASSIGNED);
677 public void updateOrchestrationStatusActivateFabricConfigurationTest() throws Exception {
678 gBBInput = execution.getGeneralBuildingBlock();
679 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
680 OrchestrationStatus.ACTIVE);
682 aaiUpdateTasks.updateOrchestrationStatusActivateFabricConfiguration(execution);
684 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
685 OrchestrationStatus.ACTIVE);
689 public void updateOrchestrationStatusAssignedFabricConfigurationTest() throws Exception {
690 gBBInput = execution.getGeneralBuildingBlock();
691 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
692 OrchestrationStatus.ASSIGNED);
694 aaiUpdateTasks.updateOrchestrationStatusAssignFabricConfiguration(execution);
696 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
697 OrchestrationStatus.ASSIGNED);
701 public void updateContrailServiceInstanceFqdnVfModuleTest() throws Exception {
702 execution.setVariable("contrailServiceInstanceFqdn", "newContrailServiceInstanceFqdn");
703 doNothing().when(aaiVfModuleResources).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
705 aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
707 verify(aaiVfModuleResources, times(1)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
708 assertEquals("newContrailServiceInstanceFqdn", vfModule.getContrailServiceInstanceFqdn());
712 public void updateContrailServiceInstanceFqdnVfModuleNoUpdateTest() throws Exception {
713 aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
714 verify(aaiVfModuleResources, times(0)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
718 public void updateIpv4OamAddressVnfTest() throws Exception {
719 execution.setVariable("oamManagementV4Address", "newIpv4OamAddress");
720 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
722 aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
724 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
725 assertEquals("newIpv4OamAddress", genericVnf.getIpv4OamAddress());
729 public void updateIpv4OamAddressVnfNoUpdateTest() throws Exception {
730 aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
731 verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
735 public void updateManagementV6AddressVnfTest() throws Exception {
736 execution.setVariable("oamManagementV6Address", "newManagementV6Address");
737 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
739 aaiUpdateTasks.updateManagementV6AddressVnf(execution);
741 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
742 assertEquals("newManagementV6Address", genericVnf.getManagementV6Address());
746 public void updateManagementV6AddressVnfNoUpdateTest() throws Exception {
747 aaiUpdateTasks.updateManagementV6AddressVnf(execution);
748 verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
752 public void updateOrchestrationStatusVnfConfigureTest() throws Exception {
753 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
754 OrchestrationStatus.CONFIGURE);
756 aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfigureVnf(execution);
760 public void updateOrchestrationStatusVnfConfiguredTest() throws Exception {
761 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
762 OrchestrationStatus.CONFIGURED);
764 aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfiguredVnf(execution);
767 private Pnf preparePnfAndExtractForPnf() throws BBObjectNotFoundException {
768 Pnf pnf = buildPnf();
769 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf);