diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java')
-rw-r--r-- | bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java | 633 |
1 files changed, 323 insertions, 310 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java index 4bdbd1a846..ccd677c80e 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java @@ -24,7 +24,6 @@ import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; - import java.io.UnsupportedEncodingException; import java.nio.file.Files; import java.nio.file.Paths; @@ -33,7 +32,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; - import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -62,314 +60,329 @@ import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork; import org.onap.so.entity.MsoRequest; import org.onap.so.openstack.beans.NetworkRollback; - import com.fasterxml.jackson.databind.ObjectMapper; -public class NetworkAdapterObjectMapperTest extends TestDataSetup{ - - private NetworkAdapterObjectMapper SPY_networkAdapterObjectMapper = Mockito.spy(NetworkAdapterObjectMapper.class); - - private L3Network l3Network; - private RequestContext requestContext; - private ServiceInstance serviceInstance; - private CloudRegion cloudRegion; - private OrchestrationContext orchestrationContext; - private Customer customer; - Map<String, String> userInput; - - private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/NetworkMapper/"; - - @Before - public void before() { - requestContext = setRequestContext(); - - customer = buildCustomer(); - - serviceInstance = setServiceInstance(); - - cloudRegion = setCloudRegion(); - - orchestrationContext = setOrchestrationContext(); - orchestrationContext.setIsRollbackEnabled(false); - - userInput = setUserInput(); - - l3Network = setL3Network(); - - customer.getServiceSubscription().getServiceInstances().add(serviceInstance); - } - - @Test - public void buildCreateNetworkRequestFromBbobjectTest() throws Exception { - - String cloudRegionPo = "cloudRegionPo"; - CreateNetworkRequest expectedCreateNetworkRequest = new CreateNetworkRequest(); - - expectedCreateNetworkRequest.setCloudSiteId(cloudRegionPo); - expectedCreateNetworkRequest.setTenantId(cloudRegion.getTenantId()); - expectedCreateNetworkRequest.setNetworkId(l3Network.getNetworkId()); - expectedCreateNetworkRequest.setNetworkName(l3Network.getNetworkName()); - expectedCreateNetworkRequest.setNetworkType(l3Network.getNetworkType()); - expectedCreateNetworkRequest.setBackout(false); - expectedCreateNetworkRequest.setFailIfExists(true); - expectedCreateNetworkRequest.setNetworkTechnology("CONTRAIL"); - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId(requestContext.getMsoRequestId()); - msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); - expectedCreateNetworkRequest.setMsoRequest(msoRequest); - expectedCreateNetworkRequest.setSkipAAI(true); - HashMap<String, String> networkParams = new HashMap<String, String>(); - networkParams.put("shared", "true"); - networkParams.put("external", "false"); - networkParams.put("testUserInputKey", "testUserInputValue"); - expectedCreateNetworkRequest.setNetworkParams(networkParams); - - expectedCreateNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId"); - - Subnet openstackSubnet = new Subnet(); - HostRoute hostRoute = new HostRoute(); - hostRoute.setHostRouteId("hostRouteId"); - hostRoute.setNextHop("nextHop"); - hostRoute.setRoutePrefix("routePrefix"); - openstackSubnet.getHostRoutes().add(hostRoute); - List<Subnet> subnetList = new ArrayList<Subnet>(); - subnetList.add(openstackSubnet); - l3Network.getSubnets().add(openstackSubnet); - l3Network.setNetworkTechnology("Contrail"); - l3Network.setIsSharedNetwork(true); - l3Network.setIsExternalNetwork(false); - - doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint(); - doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); - - CreateNetworkRequest createNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, customer); - - assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("contrailRequest").ignoring("contrailNetwork").ignoring("providerVlanNetwork").ignoring("subnets").ignoring("messageId")); - } - - @Test - public void createNetworkRollbackRequestMapperTest() throws Exception { - - String cloudRegionPo = "cloudRegionPo"; - RollbackNetworkRequest expectedRollbackNetworkRequest = new RollbackNetworkRequest(); - - expectedRollbackNetworkRequest.setMessageId(requestContext.getMsoRequestId()); - NetworkRollback networkRollback = new NetworkRollback(); - networkRollback.setCloudId(cloudRegionPo); - networkRollback.setNetworkCreated(true); - networkRollback.setNetworkId(l3Network.getNetworkId()); - networkRollback.setNetworkType(l3Network.getNetworkType()); - networkRollback.setTenantId(cloudRegion.getTenantId()); - expectedRollbackNetworkRequest.setNetworkRollback(networkRollback); - expectedRollbackNetworkRequest.setSkipAAI(true); - - CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse(); - createNetworkResponse.setNetworkCreated(true); - - RollbackNetworkRequest rollbackNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkRollbackRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, createNetworkResponse); - - assertThat(rollbackNetworkRequest, sameBeanAs(expectedRollbackNetworkRequest).ignoring("contrailNetwork").ignoring("providerVlanNetwork").ignoring("subnets").ignoring("networkParams").ignoring("messageId")); - } - - @Test - public void updateNetworkRequestMapperTest() throws UnsupportedEncodingException { - org.onap.so.openstack.beans.Subnet subnet = new org.onap.so.openstack.beans.Subnet(); - subnet.setSubnetId("subnetId"); - subnet.setHostRoutes(new ArrayList<org.onap.so.openstack.beans.HostRoute>()); - - List<org.onap.so.openstack.beans.Subnet> subnets = new ArrayList<>(); - subnets.add(subnet); - - ProviderVlanNetwork providerVlanNetwork = new ProviderVlanNetwork("physicalNetworkName", new ArrayList<Integer>()); - - List<String> policyFqdns = Arrays.asList("networkPolicyFqdn"); - - org.onap.so.openstack.beans.RouteTarget expectedRouteTarget = new org.onap.so.openstack.beans.RouteTarget(); - expectedRouteTarget.setRouteTarget("globalRouteTarget"); - - ContrailNetwork contrailNetwork = new ContrailNetwork(); - contrailNetwork.setPolicyFqdns(policyFqdns); - contrailNetwork.setRouteTableFqdns(new ArrayList<String>()); - contrailNetwork.setRouteTargets(new ArrayList<org.onap.so.openstack.beans.RouteTarget>()); - contrailNetwork.getRouteTargets().add(expectedRouteTarget); - contrailNetwork.getRouteTableFqdns().add("routeTableReferenceFqdn"); - - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setServiceInstanceId("testServiceInstanceId1"); - - ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); - modelInfoNetwork.setNetworkType("networkType"); - modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUuid"); - modelInfoNetwork.setModelVersion("modelVersion"); - - Subnet actualSubnet = new Subnet(); - actualSubnet.setSubnetId("subnetId"); - actualSubnet.setDhcpEnabled(false); - actualSubnet.setIpVersion("4"); - - RouteTarget routeTarget = new RouteTarget(); - routeTarget.setGlobalRouteTarget("globalRouteTarget"); - - VpnBinding vpnBinding = new VpnBinding(); - vpnBinding.setVpnId("vpnId"); - vpnBinding.getRouteTargets().add(routeTarget); - - Customer customer = new Customer(); - customer.getVpnBindings().add(vpnBinding); - ServiceSubscription serviceSubscription = new ServiceSubscription(); - customer.setServiceSubscription(serviceSubscription); - // set Customer on service instance - customer.getServiceSubscription().getServiceInstances().add(serviceInstance); - - NetworkPolicy networkPolicy = new NetworkPolicy(); - networkPolicy.setNetworkPolicyId("networkPolicyId"); - networkPolicy.setNetworkPolicyFqdn("networkPolicyFqdn"); - - RouteTableReference routeTableReference = new RouteTableReference(); - routeTableReference.setRouteTableReferenceFqdn("routeTableReferenceFqdn"); - - l3Network.setModelInfoNetwork(modelInfoNetwork); - l3Network.setPhysicalNetworkName("physicalNetworkName"); - l3Network.getSubnets().add(actualSubnet); - l3Network.getNetworkPolicies().add(networkPolicy); - l3Network.getContrailNetworkRouteTableReferences().add(routeTableReference); - l3Network.setIsSharedNetwork(false); - l3Network.setIsExternalNetwork(false); - HashMap<String, String> networkParams = new HashMap<String, String>(); - networkParams.put("shared", "false"); - networkParams.put("external", "false"); - networkParams.put("testUserInputKey", "testUserInputValue"); - - UpdateNetworkRequest expectedUpdateNetworkRequest = new UpdateNetworkRequest(); - expectedUpdateNetworkRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); - expectedUpdateNetworkRequest.setTenantId(cloudRegion.getTenantId()); - expectedUpdateNetworkRequest.setNetworkId(l3Network.getNetworkId()); - expectedUpdateNetworkRequest.setNetworkStackId(l3Network.getHeatStackId()); - expectedUpdateNetworkRequest.setNetworkName(l3Network.getNetworkName()); - expectedUpdateNetworkRequest.setNetworkType(l3Network.getModelInfoNetwork().getNetworkType()); - expectedUpdateNetworkRequest.setNetworkTypeVersion(l3Network.getModelInfoNetwork().getModelVersion()); - expectedUpdateNetworkRequest.setModelCustomizationUuid(l3Network.getModelInfoNetwork().getModelCustomizationUUID()); - expectedUpdateNetworkRequest.setSubnets(subnets); - expectedUpdateNetworkRequest.setProviderVlanNetwork(providerVlanNetwork); - expectedUpdateNetworkRequest.setContrailNetwork(contrailNetwork); - expectedUpdateNetworkRequest.setNetworkParams(networkParams); - expectedUpdateNetworkRequest.setMsoRequest(msoRequest); - expectedUpdateNetworkRequest.setSkipAAI(true); - expectedUpdateNetworkRequest.setBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled())); - expectedUpdateNetworkRequest.setMessageId("messageId"); - expectedUpdateNetworkRequest.setNotificationUrl("http://localhost:28080/mso/WorkflowMesssage/NetworkAResponse/messageId"); - - doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); - doReturn("http://localhost:28080/mso/WorkflowMesssage").when(SPY_networkAdapterObjectMapper).getEndpoint(); - UpdateNetworkRequest actualUpdateNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkUpdateRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, customer); - - assertThat(actualUpdateNetworkRequest, sameBeanAs(expectedUpdateNetworkRequest).ignoring("msoRequest.requestId")); - } - - @Test - public void deleteNetworkRequestMapperTest() throws Exception { - DeleteNetworkRequest expectedDeleteNetworkRequest = new DeleteNetworkRequest(); - - String messageId = "messageId"; - expectedDeleteNetworkRequest.setMessageId(messageId); - doReturn(messageId).when(SPY_networkAdapterObjectMapper).getRandomUuid(); - - ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); - l3Network.setModelInfoNetwork(modelInfoNetwork); - modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUuid"); - expectedDeleteNetworkRequest.setModelCustomizationUuid(modelInfoNetwork.getModelCustomizationUUID()); - - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId(requestContext.getMsoRequestId()); - msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); - expectedDeleteNetworkRequest.setMsoRequest(msoRequest); - - expectedDeleteNetworkRequest.setNetworkId(l3Network.getNetworkId()); - - l3Network.setHeatStackId("heatStackId"); - expectedDeleteNetworkRequest.setNetworkStackId(l3Network.getHeatStackId()); - - expectedDeleteNetworkRequest.setNetworkType(l3Network.getNetworkType()); - - expectedDeleteNetworkRequest.setSkipAAI(true); - - expectedDeleteNetworkRequest.setTenantId(cloudRegion.getTenantId()); - - expectedDeleteNetworkRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); - - expectedDeleteNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId"); - - doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint(); - doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); - - DeleteNetworkRequest deleteNetworkRequest = SPY_networkAdapterObjectMapper.deleteNetworkRequestMapper(requestContext, cloudRegion, serviceInstance, l3Network); - - assertThat(expectedDeleteNetworkRequest, sameBeanAs(deleteNetworkRequest)); - } - - @Test - public void deleteNetworkRequestNoHeatIdMapperTest() throws Exception { - DeleteNetworkRequest expectedDeleteNetworkRequest = new DeleteNetworkRequest(); - - String messageId = "messageId"; - expectedDeleteNetworkRequest.setMessageId(messageId); - doReturn(messageId).when(SPY_networkAdapterObjectMapper).getRandomUuid(); - - ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); - l3Network.setModelInfoNetwork(modelInfoNetwork); - modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUuid"); - expectedDeleteNetworkRequest.setModelCustomizationUuid(modelInfoNetwork.getModelCustomizationUUID()); - - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId(requestContext.getMsoRequestId()); - msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); - expectedDeleteNetworkRequest.setMsoRequest(msoRequest); - - expectedDeleteNetworkRequest.setNetworkId(l3Network.getNetworkId()); - - l3Network.setNetworkName("heatStackId"); - expectedDeleteNetworkRequest.setNetworkStackId("heatStackId"); - - expectedDeleteNetworkRequest.setNetworkType(l3Network.getNetworkType()); - - expectedDeleteNetworkRequest.setSkipAAI(true); - - expectedDeleteNetworkRequest.setTenantId(cloudRegion.getTenantId()); - - expectedDeleteNetworkRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); - - expectedDeleteNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId"); - - doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint(); - doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); - DeleteNetworkRequest deleteNetworkRequest = SPY_networkAdapterObjectMapper.deleteNetworkRequestMapper(requestContext, cloudRegion, serviceInstance, l3Network); - - assertThat(expectedDeleteNetworkRequest, sameBeanAs(deleteNetworkRequest)); - } - - @Test - public void buildOpenstackSubnetListTest() throws Exception { - - ObjectMapper omapper = new ObjectMapper(); - String bbJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "generalBB.json"))); - org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock gbb = omapper.readValue( - bbJson, - org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock.class); - L3Network myNetwork = gbb.getServiceInstance().getNetworks().get(0); - - String expectedCreateNetworkRequestJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "createNetworkRequest.json"))); - org.onap.so.adapters.nwrest.CreateNetworkRequest expectedCreateNetworkRequest = omapper.readValue( - expectedCreateNetworkRequestJson, - org.onap.so.adapters.nwrest.CreateNetworkRequest.class); - - String cloudRegionPo = "cloudRegionPo"; - - expectedCreateNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId"); - - doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint(); - doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); - CreateNetworkRequest createNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, myNetwork, userInput, cloudRegionPo, customer); - //ignoring dynamic fields and networkParams that throws parsing exception on json file load - assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("messageId").ignoring("msoRequest.requestId").ignoring("networkParams")); - } +public class NetworkAdapterObjectMapperTest extends TestDataSetup { + + private NetworkAdapterObjectMapper SPY_networkAdapterObjectMapper = Mockito.spy(NetworkAdapterObjectMapper.class); + + private L3Network l3Network; + private RequestContext requestContext; + private ServiceInstance serviceInstance; + private CloudRegion cloudRegion; + private OrchestrationContext orchestrationContext; + private Customer customer; + Map<String, String> userInput; + + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/NetworkMapper/"; + + @Before + public void before() { + requestContext = setRequestContext(); + + customer = buildCustomer(); + + serviceInstance = setServiceInstance(); + + cloudRegion = setCloudRegion(); + + orchestrationContext = setOrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(false); + + userInput = setUserInput(); + + l3Network = setL3Network(); + + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + } + + @Test + public void buildCreateNetworkRequestFromBbobjectTest() throws Exception { + + String cloudRegionPo = "cloudRegionPo"; + CreateNetworkRequest expectedCreateNetworkRequest = new CreateNetworkRequest(); + + expectedCreateNetworkRequest.setCloudSiteId(cloudRegionPo); + expectedCreateNetworkRequest.setTenantId(cloudRegion.getTenantId()); + expectedCreateNetworkRequest.setNetworkId(l3Network.getNetworkId()); + expectedCreateNetworkRequest.setNetworkName(l3Network.getNetworkName()); + expectedCreateNetworkRequest.setNetworkType(l3Network.getNetworkType()); + expectedCreateNetworkRequest.setBackout(false); + expectedCreateNetworkRequest.setFailIfExists(true); + expectedCreateNetworkRequest.setNetworkTechnology("CONTRAIL"); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId(requestContext.getMsoRequestId()); + msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); + expectedCreateNetworkRequest.setMsoRequest(msoRequest); + expectedCreateNetworkRequest.setSkipAAI(true); + HashMap<String, String> networkParams = new HashMap<String, String>(); + networkParams.put("shared", "true"); + networkParams.put("external", "false"); + networkParams.put("testUserInputKey", "testUserInputValue"); + expectedCreateNetworkRequest.setNetworkParams(networkParams); + + expectedCreateNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId"); + + Subnet openstackSubnet = new Subnet(); + HostRoute hostRoute = new HostRoute(); + hostRoute.setHostRouteId("hostRouteId"); + hostRoute.setNextHop("nextHop"); + hostRoute.setRoutePrefix("routePrefix"); + openstackSubnet.getHostRoutes().add(hostRoute); + List<Subnet> subnetList = new ArrayList<Subnet>(); + subnetList.add(openstackSubnet); + l3Network.getSubnets().add(openstackSubnet); + l3Network.setNetworkTechnology("Contrail"); + l3Network.setIsSharedNetwork(true); + l3Network.setIsExternalNetwork(false); + + doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint(); + doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); + + CreateNetworkRequest createNetworkRequest = + SPY_networkAdapterObjectMapper.createNetworkRequestMapper(requestContext, cloudRegion, + orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, customer); + + assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("contrailRequest") + .ignoring("contrailNetwork").ignoring("providerVlanNetwork").ignoring("subnets").ignoring("messageId")); + } + + @Test + public void createNetworkRollbackRequestMapperTest() throws Exception { + + String cloudRegionPo = "cloudRegionPo"; + RollbackNetworkRequest expectedRollbackNetworkRequest = new RollbackNetworkRequest(); + + expectedRollbackNetworkRequest.setMessageId(requestContext.getMsoRequestId()); + NetworkRollback networkRollback = new NetworkRollback(); + networkRollback.setCloudId(cloudRegionPo); + networkRollback.setNetworkCreated(true); + networkRollback.setNetworkId(l3Network.getNetworkId()); + networkRollback.setNetworkType(l3Network.getNetworkType()); + networkRollback.setTenantId(cloudRegion.getTenantId()); + expectedRollbackNetworkRequest.setNetworkRollback(networkRollback); + expectedRollbackNetworkRequest.setSkipAAI(true); + + CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse(); + createNetworkResponse.setNetworkCreated(true); + + RollbackNetworkRequest rollbackNetworkRequest = SPY_networkAdapterObjectMapper + .createNetworkRollbackRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, + l3Network, userInput, cloudRegionPo, createNetworkResponse); + + assertThat(rollbackNetworkRequest, sameBeanAs(expectedRollbackNetworkRequest).ignoring("contrailNetwork") + .ignoring("providerVlanNetwork").ignoring("subnets").ignoring("networkParams").ignoring("messageId")); + } + + @Test + public void updateNetworkRequestMapperTest() throws UnsupportedEncodingException { + org.onap.so.openstack.beans.Subnet subnet = new org.onap.so.openstack.beans.Subnet(); + subnet.setSubnetId("subnetId"); + subnet.setHostRoutes(new ArrayList<org.onap.so.openstack.beans.HostRoute>()); + + List<org.onap.so.openstack.beans.Subnet> subnets = new ArrayList<>(); + subnets.add(subnet); + + ProviderVlanNetwork providerVlanNetwork = + new ProviderVlanNetwork("physicalNetworkName", new ArrayList<Integer>()); + + List<String> policyFqdns = Arrays.asList("networkPolicyFqdn"); + + org.onap.so.openstack.beans.RouteTarget expectedRouteTarget = new org.onap.so.openstack.beans.RouteTarget(); + expectedRouteTarget.setRouteTarget("globalRouteTarget"); + + ContrailNetwork contrailNetwork = new ContrailNetwork(); + contrailNetwork.setPolicyFqdns(policyFqdns); + contrailNetwork.setRouteTableFqdns(new ArrayList<String>()); + contrailNetwork.setRouteTargets(new ArrayList<org.onap.so.openstack.beans.RouteTarget>()); + contrailNetwork.getRouteTargets().add(expectedRouteTarget); + contrailNetwork.getRouteTableFqdns().add("routeTableReferenceFqdn"); + + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setServiceInstanceId("testServiceInstanceId1"); + + ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); + modelInfoNetwork.setNetworkType("networkType"); + modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUuid"); + modelInfoNetwork.setModelVersion("modelVersion"); + + Subnet actualSubnet = new Subnet(); + actualSubnet.setSubnetId("subnetId"); + actualSubnet.setDhcpEnabled(false); + actualSubnet.setIpVersion("4"); + + RouteTarget routeTarget = new RouteTarget(); + routeTarget.setGlobalRouteTarget("globalRouteTarget"); + + VpnBinding vpnBinding = new VpnBinding(); + vpnBinding.setVpnId("vpnId"); + vpnBinding.getRouteTargets().add(routeTarget); + + Customer customer = new Customer(); + customer.getVpnBindings().add(vpnBinding); + ServiceSubscription serviceSubscription = new ServiceSubscription(); + customer.setServiceSubscription(serviceSubscription); + // set Customer on service instance + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + + NetworkPolicy networkPolicy = new NetworkPolicy(); + networkPolicy.setNetworkPolicyId("networkPolicyId"); + networkPolicy.setNetworkPolicyFqdn("networkPolicyFqdn"); + + RouteTableReference routeTableReference = new RouteTableReference(); + routeTableReference.setRouteTableReferenceFqdn("routeTableReferenceFqdn"); + + l3Network.setModelInfoNetwork(modelInfoNetwork); + l3Network.setPhysicalNetworkName("physicalNetworkName"); + l3Network.getSubnets().add(actualSubnet); + l3Network.getNetworkPolicies().add(networkPolicy); + l3Network.getContrailNetworkRouteTableReferences().add(routeTableReference); + l3Network.setIsSharedNetwork(false); + l3Network.setIsExternalNetwork(false); + HashMap<String, String> networkParams = new HashMap<String, String>(); + networkParams.put("shared", "false"); + networkParams.put("external", "false"); + networkParams.put("testUserInputKey", "testUserInputValue"); + + UpdateNetworkRequest expectedUpdateNetworkRequest = new UpdateNetworkRequest(); + expectedUpdateNetworkRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); + expectedUpdateNetworkRequest.setTenantId(cloudRegion.getTenantId()); + expectedUpdateNetworkRequest.setNetworkId(l3Network.getNetworkId()); + expectedUpdateNetworkRequest.setNetworkStackId(l3Network.getHeatStackId()); + expectedUpdateNetworkRequest.setNetworkName(l3Network.getNetworkName()); + expectedUpdateNetworkRequest.setNetworkType(l3Network.getModelInfoNetwork().getNetworkType()); + expectedUpdateNetworkRequest.setNetworkTypeVersion(l3Network.getModelInfoNetwork().getModelVersion()); + expectedUpdateNetworkRequest + .setModelCustomizationUuid(l3Network.getModelInfoNetwork().getModelCustomizationUUID()); + expectedUpdateNetworkRequest.setSubnets(subnets); + expectedUpdateNetworkRequest.setProviderVlanNetwork(providerVlanNetwork); + expectedUpdateNetworkRequest.setContrailNetwork(contrailNetwork); + expectedUpdateNetworkRequest.setNetworkParams(networkParams); + expectedUpdateNetworkRequest.setMsoRequest(msoRequest); + expectedUpdateNetworkRequest.setSkipAAI(true); + expectedUpdateNetworkRequest.setBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled())); + expectedUpdateNetworkRequest.setMessageId("messageId"); + expectedUpdateNetworkRequest + .setNotificationUrl("http://localhost:28080/mso/WorkflowMesssage/NetworkAResponse/messageId"); + + doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); + doReturn("http://localhost:28080/mso/WorkflowMesssage").when(SPY_networkAdapterObjectMapper).getEndpoint(); + UpdateNetworkRequest actualUpdateNetworkRequest = + SPY_networkAdapterObjectMapper.createNetworkUpdateRequestMapper(requestContext, cloudRegion, + orchestrationContext, serviceInstance, l3Network, userInput, customer); + + assertThat(actualUpdateNetworkRequest, + sameBeanAs(expectedUpdateNetworkRequest).ignoring("msoRequest.requestId")); + } + + @Test + public void deleteNetworkRequestMapperTest() throws Exception { + DeleteNetworkRequest expectedDeleteNetworkRequest = new DeleteNetworkRequest(); + + String messageId = "messageId"; + expectedDeleteNetworkRequest.setMessageId(messageId); + doReturn(messageId).when(SPY_networkAdapterObjectMapper).getRandomUuid(); + + ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); + l3Network.setModelInfoNetwork(modelInfoNetwork); + modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUuid"); + expectedDeleteNetworkRequest.setModelCustomizationUuid(modelInfoNetwork.getModelCustomizationUUID()); + + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId(requestContext.getMsoRequestId()); + msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); + expectedDeleteNetworkRequest.setMsoRequest(msoRequest); + + expectedDeleteNetworkRequest.setNetworkId(l3Network.getNetworkId()); + + l3Network.setHeatStackId("heatStackId"); + expectedDeleteNetworkRequest.setNetworkStackId(l3Network.getHeatStackId()); + + expectedDeleteNetworkRequest.setNetworkType(l3Network.getNetworkType()); + + expectedDeleteNetworkRequest.setSkipAAI(true); + + expectedDeleteNetworkRequest.setTenantId(cloudRegion.getTenantId()); + + expectedDeleteNetworkRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); + + expectedDeleteNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId"); + + doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint(); + doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); + + DeleteNetworkRequest deleteNetworkRequest = SPY_networkAdapterObjectMapper + .deleteNetworkRequestMapper(requestContext, cloudRegion, serviceInstance, l3Network); + + assertThat(expectedDeleteNetworkRequest, sameBeanAs(deleteNetworkRequest)); + } + + @Test + public void deleteNetworkRequestNoHeatIdMapperTest() throws Exception { + DeleteNetworkRequest expectedDeleteNetworkRequest = new DeleteNetworkRequest(); + + String messageId = "messageId"; + expectedDeleteNetworkRequest.setMessageId(messageId); + doReturn(messageId).when(SPY_networkAdapterObjectMapper).getRandomUuid(); + + ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); + l3Network.setModelInfoNetwork(modelInfoNetwork); + modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUuid"); + expectedDeleteNetworkRequest.setModelCustomizationUuid(modelInfoNetwork.getModelCustomizationUUID()); + + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId(requestContext.getMsoRequestId()); + msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); + expectedDeleteNetworkRequest.setMsoRequest(msoRequest); + + expectedDeleteNetworkRequest.setNetworkId(l3Network.getNetworkId()); + + l3Network.setNetworkName("heatStackId"); + expectedDeleteNetworkRequest.setNetworkStackId("heatStackId"); + + expectedDeleteNetworkRequest.setNetworkType(l3Network.getNetworkType()); + + expectedDeleteNetworkRequest.setSkipAAI(true); + + expectedDeleteNetworkRequest.setTenantId(cloudRegion.getTenantId()); + + expectedDeleteNetworkRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); + + expectedDeleteNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId"); + + doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint(); + doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); + DeleteNetworkRequest deleteNetworkRequest = SPY_networkAdapterObjectMapper + .deleteNetworkRequestMapper(requestContext, cloudRegion, serviceInstance, l3Network); + + assertThat(expectedDeleteNetworkRequest, sameBeanAs(deleteNetworkRequest)); + } + + @Test + public void buildOpenstackSubnetListTest() throws Exception { + + ObjectMapper omapper = new ObjectMapper(); + String bbJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "generalBB.json"))); + org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock gbb = + omapper.readValue(bbJson, org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock.class); + L3Network myNetwork = gbb.getServiceInstance().getNetworks().get(0); + + String expectedCreateNetworkRequestJson = + new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "createNetworkRequest.json"))); + org.onap.so.adapters.nwrest.CreateNetworkRequest expectedCreateNetworkRequest = omapper + .readValue(expectedCreateNetworkRequestJson, org.onap.so.adapters.nwrest.CreateNetworkRequest.class); + + String cloudRegionPo = "cloudRegionPo"; + + expectedCreateNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId"); + + doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint(); + doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); + CreateNetworkRequest createNetworkRequest = + SPY_networkAdapterObjectMapper.createNetworkRequestMapper(requestContext, cloudRegion, + orchestrationContext, serviceInstance, myNetwork, userInput, cloudRegionPo, customer); + // ignoring dynamic fields and networkParams that throws parsing exception on json file load + assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("messageId") + .ignoring("msoRequest.requestId").ignoring("networkParams")); + } } |