From 296786770ef898b573ad425e12c50e737f5d9a62 Mon Sep 17 00:00:00 2001 From: "Mcblain, Thomas" Date: Fri, 31 May 2019 11:52:36 -0400 Subject: Handle multiple host routes correctly for networks unit test for the method that creates subnets Remove project name from junit test data Handle multiple host routes correctly for networks Change-Id: I537b9bbb68c11901c06ed2366591cedeb3b29acd Issue-ID: SO-1961 Signed-off-by: Benjamin, Max (mb388a) --- .../network/mapper/NetworkAdapterObjectMapper.java | 6 +-- .../mapper/NetworkAdapterObjectMapperTest.java | 19 ++++++-- .../NetworkMapper/l3-network-multiple-subnets.json | 53 ++++++++++++++++++++++ 3 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/NetworkMapper/l3-network-multiple-subnets.json (limited to 'bpmn/so-bpmn-tasks') diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java index 4fee1f909b..173e776af9 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java @@ -34,7 +34,6 @@ import org.onap.so.adapters.nwrest.ContrailNetwork; import org.onap.so.adapters.nwrest.CreateNetworkRequest; import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.adapters.nwrest.DeleteNetworkRequest; -import org.onap.so.adapters.nwrest.NetworkTechnology; import org.onap.so.adapters.nwrest.ProviderVlanNetwork; import org.onap.so.adapters.nwrest.RollbackNetworkRequest; import org.onap.so.adapters.nwrest.UpdateNetworkRequest; @@ -261,7 +260,7 @@ public class NetworkAdapterObjectMapper { * @param L3Network * @return List */ - private List buildOpenstackSubnetList(L3Network l3Network) { + protected List buildOpenstackSubnetList(L3Network l3Network) { List subnets = l3Network.getSubnets(); List subnetList = new ArrayList(); @@ -292,9 +291,10 @@ public class NetworkAdapterObjectMapper { .setCidr(subnet.getNetworkStartAddress().concat(FORWARD_SLASH).concat(subnet.getCidrMask())); List hostRouteList = subnet.getHostRoutes(); List openstackHostRouteList = new ArrayList<>(); - org.onap.so.openstack.beans.HostRoute openstackHostRoute = new org.onap.so.openstack.beans.HostRoute(); + org.onap.so.openstack.beans.HostRoute openstackHostRoute = null; // TODO only 2 fields available on openstack object. Confirm it is sufficient or add as needed for (org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute hostRoute : hostRouteList) { + openstackHostRoute = new org.onap.so.openstack.beans.HostRoute(); openstackHostRoute.setNextHop(hostRoute.getNextHop()); openstackHostRoute.setPrefix(hostRoute.getRoutePrefix()); // add host route to the list 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 ccd677c80e..d6485bd57f 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 @@ -21,8 +21,7 @@ package org.onap.so.client.adapter.network.mapper; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; -import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.isA; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.doReturn; import java.io.UnsupportedEncodingException; import java.nio.file.Files; @@ -39,7 +38,6 @@ import org.onap.so.adapters.nwrest.ContrailNetwork; import org.onap.so.adapters.nwrest.CreateNetworkRequest; import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.adapters.nwrest.DeleteNetworkRequest; -import org.onap.so.adapters.nwrest.NetworkTechnology; import org.onap.so.adapters.nwrest.ProviderVlanNetwork; import org.onap.so.adapters.nwrest.RollbackNetworkRequest; import org.onap.so.adapters.nwrest.UpdateNetworkRequest; @@ -385,4 +383,19 @@ public class NetworkAdapterObjectMapperTest extends TestDataSetup { assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("messageId") .ignoring("msoRequest.requestId").ignoring("networkParams")); } + + @Test + public void buildOpenstackSubnetListMultipleHostRoutesTest() throws Exception { + + ObjectMapper omapper = new ObjectMapper(); + String l3NetworkJson = + new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "l3-network-multiple-subnets.json"))); + L3Network l3Network = omapper.readValue(l3NetworkJson, L3Network.class); + + List subnets = + SPY_networkAdapterObjectMapper.buildOpenstackSubnetList(l3Network); + assertEquals("192.168.0.0/16", subnets.get(0).getHostRoutes().get(0).getPrefix()); + assertEquals("192.168.1.5/16", subnets.get(0).getHostRoutes().get(1).getPrefix()); + + } } diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/NetworkMapper/l3-network-multiple-subnets.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/NetworkMapper/l3-network-multiple-subnets.json new file mode 100644 index 0000000000..e9b25ff266 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/NetworkMapper/l3-network-multiple-subnets.json @@ -0,0 +1,53 @@ +{ + "network-id" : "aNetworkId", + "cascaded" : false, + "cloud-params" : { }, + "network-name" : "aNetworkName", + "neutron-network-id" : null, + "network-type" : "aNetworkType", + "network-technology" : "aNetworkTechnology", + "network-role" : "", + "is-bound-to-vpn" : false, + "service-id" : "aServiceId", + "network-role-instance" : 0, + "orchestration-status" : "ACTIVE", + "heat-stack-id" : null, + "contrail-network-fqdn" : null, + "network-policies" : [ ], + "contrail-network-route-table-references" : [ ], + "widget-model-id" : null, + "widget-model-version" : null, + "physical-network-name" : "pNetworkName", + "is-provider-network" : false, + "is-shared-network" : false, + "is-external-network" : false, + "self-link" : "/", + "operational-status" : null, + "subnets" : [ { + "subnet-id" : "subnetId1", + "subnet-name" : "aSubnetName1", + "neutron-subnet-id" : null, + "gateway-address" : "192.168.1.1", + "network-start-address" : "192.168.1.2", + "cidr-mask" : "10", + "ip-version" : "4", + "orchestration-status" : "ACTIVE", + "dhcp-enabled" : true, + "dhcp-start" : "192.168.1.2", + "dhcp-end" : "192.168.1.16", + "subnet-role" : "", + "ip-assignment-direction" : "true", + "subnet-sequence" : null, + "host-routes": [{ + "host-route-id": "hrId1", + "route-prefix": "192.168.0.0/16", + "next-hop": "192.168.1.1", + "next-hop-type": null + }, { + "host-route-id": "hrId2", + "route-prefix": "192.168.1.5/16", + "next-hop": "192.168.1.1", + "next-hop-type": null + }] + }] +} \ No newline at end of file -- cgit 1.2.3-korg