use of org.onap.aai.domain.yang.L3Networks in project so by onap.
the class BBInputSetupUtilsTest method getRelatedNetworkByNameFromServiceInstanceTest.
@Test
public void getRelatedNetworkByNameFromServiceInstanceTest() throws Exception {
final String networkId = "id123";
final String networkName = "name123";
Optional<L3Networks> expected = Optional.of(new L3Networks());
L3Network network = new L3Network();
network.setNetworkId(networkId);
network.setNetworkName(networkName);
expected.get().getL3Network().add(network);
doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(L3Networks.class), any(AAIPluralResourceUri.class));
Optional<L3Network> actual = bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance(networkId, networkName);
assertTrue(actual.isPresent());
assertEquals(networkId, actual.get().getNetworkId());
assertEquals(networkName, actual.get().getNetworkName());
assertEquals(expected.get().getL3Network().get(0).getNetworkId(), actual.get().getNetworkId());
}
use of org.onap.aai.domain.yang.L3Networks in project so by onap.
the class BBInputSetupUtils method getRelatedNetworkByNameFromServiceInstance.
public Optional<L3Network> getRelatedNetworkByNameFromServiceInstance(String serviceInstanceId, String networkName) throws MultipleObjectsFoundException {
AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId)).relatedTo(Types.L3_NETWORKS.getFragment()).queryParam("network-name", networkName);
Optional<L3Networks> networks = injectionHelper.getAaiClient().get(L3Networks.class, uri);
L3Network network = null;
if (!networks.isPresent()) {
logger.debug("No Networks matched by name");
return Optional.empty();
} else {
if (networks.get().getL3Network().size() > 1) {
String message = String.format("Multiple networks found for service-instance-id: %s and network-name: %s.", serviceInstanceId, networkName);
throw new MultipleObjectsFoundException(message);
} else {
network = networks.get().getL3Network().get(0);
}
return Optional.of(network);
}
}
Aggregations