Search in sources :

Example 1 with L3Networks

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());
}
Also used : L3Network(org.onap.aai.domain.yang.L3Network) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) L3Networks(org.onap.aai.domain.yang.L3Networks) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with L3Networks

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);
    }
}
Also used : L3Network(org.onap.aai.domain.yang.L3Network) MultipleObjectsFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) L3Networks(org.onap.aai.domain.yang.L3Networks)

Aggregations

L3Network (org.onap.aai.domain.yang.L3Network)2 L3Networks (org.onap.aai.domain.yang.L3Networks)2 AAIPluralResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri)2 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 MultipleObjectsFoundException (org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException)1