X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=bpmn%2Fso-bpmn-tasks%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fso%2Fbpmn%2Finfrastructure%2Faai%2Ftasks%2FAAIUpdateTasksTest.java;h=560f2a91bfb1ce0ab3250a72389c98fc3ac780a7;hb=6cf9ff1f1f2360a406f68f3147d86fd864d31910;hp=b45752957e2e60a10fd47944854145eb3103e886;hpb=777c1269be6e6bb4b3457cf47e4ec87924cb8fc7;p=so.git diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java index b45752957e..560f2a91bf 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java @@ -21,22 +21,35 @@ package org.onap.so.bpmn.infrastructure.aai.tasks; import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.HashMap; import org.camunda.bpm.engine.delegate.BpmnError; +import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; import org.onap.so.db.catalog.beans.OrchestrationStatus; import org.springframework.beans.factory.annotation.Autowired; @@ -50,6 +63,8 @@ public class AAIUpdateTasksTest extends BaseTaskTest{ private GenericVnf genericVnf; private VolumeGroup volumeGroup; private CloudRegion cloudRegion; + private Configuration configuration; + private Subnet subnet; @Before public void before() { @@ -59,6 +74,8 @@ public class AAIUpdateTasksTest extends BaseTaskTest{ volumeGroup = setVolumeGroup(); cloudRegion = setCloudRegion(); network = setL3Network(); + configuration = setConfiguration(); + subnet = buildSubnet(); } @Test @@ -150,6 +167,37 @@ public class AAIUpdateTasksTest extends BaseTaskTest{ aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution); } + @Test + public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleNoMultiStageTest() throws Exception { + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setMultiStageDesign("false"); + genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); + doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); + aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution); + verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); + assertEquals("", vfModule.getHeatStackId()); + } + + @Test + public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleWithMultiStageTest() throws Exception { + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setMultiStageDesign("true"); + genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); + doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION); + aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution); + verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION); + assertEquals("", vfModule.getHeatStackId()); + } + + @Test + public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleExceptionTest() throws Exception { + doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); + + expectedException.expect(BpmnError.class); + + aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution); + } + @Test public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception { doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED); @@ -287,51 +335,14 @@ public class AAIUpdateTasksTest extends BaseTaskTest{ doThrow(Exception.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion); aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution); } - - @Test - public void updateOstatusAssignedNetworkTest() throws Exception { - doNothing().when(aaiNetworkResources).updateNetwork(network); - - aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution); - - verify(aaiNetworkResources, times(1)).updateNetwork(network); - assertEquals("", network.getHeatStackId()); - } @Test - public void updateOstatusAssignedNetworkExceptionTest() throws Exception { - expectedException.expect(BpmnError.class); - - doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network); - - aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution); - } - - @Test - public void updateOstatusActivedNetworkTest() throws Exception { - doNothing().when(aaiNetworkResources).updateNetwork(network); - - aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution); - - verify(aaiNetworkResources, times(1)).updateNetwork(network); - } - - @Test - public void updateOstatusCreatedNetworkTest() throws Exception { - doNothing().when(aaiNetworkResources).updateNetwork(network); - - aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution); - - verify(aaiNetworkResources, times(1)).updateNetwork(network); - } - - @Test - public void updateOstatusActiveNetworkExceptionTest() throws Exception { + public void updateNetworkExceptionTest() throws Exception { expectedException.expect(BpmnError.class); doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network); - aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution); + aaiUpdateTasks.updateNetwork(execution, OrchestrationStatus.ACTIVE); } @Test @@ -371,19 +382,61 @@ public class AAIUpdateTasksTest extends BaseTaskTest{ CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse(); createNetworkResponse.setNetworkFqdn("testNetworkFqdn"); createNetworkResponse.setNetworkStackId("testNetworkStackId"); + HashMap subnetMap = new HashMap(); + subnetMap.put("testSubnetId", "testNeutronSubnetId"); + createNetworkResponse.setSubnetMap(subnetMap); + + network.getSubnets().add(subnet); execution.setVariable("createNetworkResponse", createNetworkResponse); doNothing().when(aaiNetworkResources).updateNetwork(network); + doNothing().when(aaiNetworkResources).updateSubnet(network, subnet); + aaiUpdateTasks.updateNetworkCreated(execution); verify(aaiNetworkResources, times(1)).updateNetwork(network); + verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet); assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn()); assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus()); assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId()); assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId()); + String neutronSubnetId = createNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue(); + assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId()); } + @Test + public void updateOrchestrationStatusNetworkTest() { + AAIUpdateTasks spy = Mockito.spy(new AAIUpdateTasks()); + doNothing().when(spy).updateNetwork(eq(execution), any()); + spy.updateOrchestrationStatusActiveNetwork(execution); + verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ACTIVE); + spy.updateOrchestrationStatusAssignedNetwork(execution); + verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ASSIGNED); + spy.updateOrchestrationStatusCreatedNetwork(execution); + verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.CREATED); + } + + @Test + public void updateNetworkAAITest() { + + L3Network spy = spy(new L3Network()); + L3Network shallowCopy = mock(L3Network.class); + Subnet mockSubnet = mock(Subnet.class); + Subnet shallowCopySubnet = mock(Subnet.class); + when(mockSubnet.shallowCopyId()).thenReturn(shallowCopySubnet); + doReturn(shallowCopy).when(spy).shallowCopyId(); + + doNothing().when(aaiNetworkResources).updateNetwork(network); + doNothing().when(aaiNetworkResources).updateSubnet(network, subnet); + + spy.getSubnets().add(mockSubnet); + aaiUpdateTasks.updateNetworkAAI(spy, OrchestrationStatus.CREATED); + + verify(shallowCopy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED); + verify(spy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED); + verify(shallowCopySubnet, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED); + } @Test public void updateNetworkCreatedkExceptionTest() throws Exception { expectedException.expect(BpmnError.class); @@ -462,4 +515,23 @@ public class AAIUpdateTasksTest extends BaseTaskTest{ doThrow(Exception.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf); aaiUpdateTasks.updateModelVfModule(execution); } + + @Test + public void updateOrchestrationStatusDeactivateFabricConfigurationTest() throws Exception { + gBBInput = execution.getGeneralBuildingBlock(); + doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ASSIGNED); + + aaiUpdateTasks.updateOrchestrationStatusDeactivateFabricConfiguration(execution); + + verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ASSIGNED); + } + @Test + public void updateOrchestrationStatusActivateFabricConfigurationTest() throws Exception { + gBBInput = execution.getGeneralBuildingBlock(); + doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ACTIVE); + + aaiUpdateTasks.updateOrchestrationStatusActivateFabricConfiguration(execution); + + verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ACTIVE); + } }