use of org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes in project so by onap.
the class ContrailSubnetMappersTest method createContrailSubnetHostRoutesMissingFieldTest.
@Test
public void createContrailSubnetHostRoutesMissingFieldTest() {
List<HostRoute> hostRoutes = new ArrayList<>();
HostRoute hostRoute1 = new HostRoute();
hostRoute1.setNextHop("next-hop1");
HostRoute hostRoute2 = new HostRoute();
hostRoute2.setNextHop("next-hop2");
hostRoute2.setPrefix("prefix2");
hostRoutes.add(hostRoute1);
hostRoutes.add(hostRoute2);
Subnet subnet = new Subnet();
subnet.setHostRoutes(hostRoutes);
ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
ContrailSubnet result = mapper.map();
ContrailSubnetHostRoutes routes = result.getHostRoutes();
assertEquals(2, routes.getHostRoutes().size());
assertEquals("next-hop1", routes.getHostRoutes().get(0).getNextHop());
assertEquals("prefix2", routes.getHostRoutes().get(1).getPrefix());
}
use of org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes in project so by onap.
the class ContrailSubnetMappersTest method createContrailSubnetHostRoutesEmptyTest.
@Test
public void createContrailSubnetHostRoutesEmptyTest() {
List<HostRoute> hostRoutes = new ArrayList<>();
Subnet subnet = new Subnet();
subnet.setHostRoutes(hostRoutes);
ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
ContrailSubnet result = mapper.map();
ContrailSubnetHostRoutes routes = result.getHostRoutes();
assertEquals(true, routes.getHostRoutes().isEmpty());
}
use of org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes in project so by onap.
the class ContrailSubnetMappersTest method createContrailSubnetHostRoutesTest.
@Test
public void createContrailSubnetHostRoutesTest() {
List<HostRoute> hostRoutes = new ArrayList<>();
HostRoute hostRoute1 = new HostRoute();
hostRoute1.setNextHop("next-hop1");
hostRoute1.setPrefix("prefix1");
HostRoute hostRoute2 = new HostRoute();
hostRoute2.setNextHop("next-hop2");
hostRoute2.setPrefix("prefix2");
hostRoutes.add(hostRoute1);
hostRoutes.add(hostRoute2);
Subnet subnet = new Subnet();
subnet.setHostRoutes(hostRoutes);
ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
ContrailSubnet result = mapper.map();
ContrailSubnetHostRoutes routes = result.getHostRoutes();
assertEquals(2, routes.getHostRoutes().size());
assertEquals("next-hop2", routes.getHostRoutes().get(1).getNextHop());
assertEquals("prefix2", routes.getHostRoutes().get(1).getPrefix());
}
use of org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes in project so by onap.
the class ContrailSubnetMapper method map.
public ContrailSubnet map() {
final ContrailSubnet result = new ContrailSubnet();
if (inputSubnet != null) {
final String subnetname = this.getSubnetName(inputSubnet);
result.setSubnetName(subnetname);
result.setEnableDhcp(inputSubnet.getEnableDHCP());
result.setDefaultGateway(inputSubnet.getGatewayIp());
Optional<ContrailSubnetIp> csIp = createSubnet(inputSubnet);
if (csIp.isPresent()) {
result.setSubnet(csIp.get());
}
Optional<List<ContrailSubnetPool>> pools = this.createContrailSubnetPool(inputSubnet);
if (pools.isPresent()) {
result.setAllocationPools(pools.get());
}
Optional<ContrailSubnetHostRoutes> routes = this.createContrailSubnetHostRoutes(inputSubnet);
if (routes.isPresent()) {
result.setHostRoutes(routes.get());
}
}
return result;
}
use of org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes in project so by onap.
the class ContrailSubnetMapper method createContrailSubnetHostRoutes.
protected Optional<ContrailSubnetHostRoutes> createContrailSubnetHostRoutes(final Subnet subnet) {
Optional<ContrailSubnetHostRoutes> result = Optional.empty();
if (subnet.getHostRoutes() != null) {
ContrailSubnetHostRoutes hostRoutesObj = new ContrailSubnetHostRoutes();
List<ContrailSubnetHostRoute> hrList = new ArrayList<>();
for (HostRoute hr : subnet.getHostRoutes()) {
if (!isNullOrEmpty(hr.getPrefix()) || !isNullOrEmpty(hr.getNextHop())) {
hrList.add(new ContrailSubnetHostRouteMapper(hr).map());
}
}
if (!hrList.isEmpty()) {
hostRoutesObj.setHostRoutes(hrList);
result = Optional.of(hostRoutesObj);
}
}
return result;
}
Aggregations