Search in sources :

Example 1 with MultipleObjectsFoundException

use of org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException in project so by onap.

the class MultipleObjectsFoundExceptionTest method messageAndCauseConstructorTest.

@Test
public void messageAndCauseConstructorTest() {
    MultipleObjectsFoundException = new MultipleObjectsFoundException(MESSAGE, CAUSE);
    assertEquals(MESSAGE, MultipleObjectsFoundException.getMessage());
    assertEquals(CAUSE, MultipleObjectsFoundException.getCause());
}
Also used : MultipleObjectsFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException) Test(org.junit.Test)

Example 2 with MultipleObjectsFoundException

use of org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException in project so by onap.

the class MultipleObjectsFoundExceptionTest method causeConstructorTest.

@Test
public void causeConstructorTest() {
    MultipleObjectsFoundException = new MultipleObjectsFoundException(CAUSE);
    assertEquals(CAUSE.toString(), MultipleObjectsFoundException.getMessage());
    assertEquals(CAUSE, MultipleObjectsFoundException.getCause());
}
Also used : MultipleObjectsFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException) Test(org.junit.Test)

Example 3 with MultipleObjectsFoundException

use of org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException in project so by onap.

the class MultipleObjectsFoundExceptionTest method messageConstructorTest.

@Test
public void messageConstructorTest() {
    MultipleObjectsFoundException = new MultipleObjectsFoundException(MESSAGE);
    assertEquals(MESSAGE, MultipleObjectsFoundException.getMessage());
    assertEquals(null, MultipleObjectsFoundException.getCause());
}
Also used : MultipleObjectsFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException) Test(org.junit.Test)

Example 4 with MultipleObjectsFoundException

use of org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException in project so by onap.

the class BBInputSetupUtils method getRelatedServiceInstanceFromInstanceGroup.

public Optional<ServiceInstance> getRelatedServiceInstanceFromInstanceGroup(String instanceGroupId) throws Exception {
    AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().instanceGroup(instanceGroupId)).relatedTo(Types.SERVICE_INSTANCES.getFragment());
    Optional<ServiceInstances> serviceInstances = injectionHelper.getAaiClient().get(ServiceInstances.class, uri);
    ServiceInstance serviceInstance = null;
    if (!serviceInstances.isPresent()) {
        logger.debug("No ServiceInstances were found");
        return Optional.empty();
    } else {
        if (serviceInstances.get().getServiceInstance().isEmpty()) {
            throw new NoServiceInstanceFoundException("No ServiceInstances Returned");
        } else if (serviceInstances.get().getServiceInstance().size() > 1) {
            String message = String.format("Mulitple service instances were found for instance-group-id: %s.", instanceGroupId);
            throw new MultipleObjectsFoundException(message);
        } else {
            serviceInstance = serviceInstances.get().getServiceInstance().get(0);
        }
        return Optional.of(serviceInstance);
    }
}
Also used : MultipleObjectsFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException) ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) NoServiceInstanceFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException)

Example 5 with MultipleObjectsFoundException

use of org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException 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

MultipleObjectsFoundException (org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException)7 Test (org.junit.Test)5 AAIPluralResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri)2 L3Network (org.onap.aai.domain.yang.L3Network)1 L3Networks (org.onap.aai.domain.yang.L3Networks)1 ServiceInstance (org.onap.aai.domain.yang.ServiceInstance)1 ServiceInstances (org.onap.aai.domain.yang.ServiceInstances)1 NoServiceInstanceFoundException (org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException)1