Search in sources :

Example 1 with ServiceInstances

use of org.onap.aai.domain.yang.ServiceInstances in project so by onap.

the class AaiResourceIdValidator method validateServiceResourceIdInAAI.

protected String validateServiceResourceIdInAAI(String generatedResourceId, String instanceName, RequestDetails reqDetails) throws DuplicateNameException {
    String globalCustomerId = reqDetails.getSubscriberInfo().getGlobalSubscriberId();
    String serviceType = reqDetails.getRequestParameters().getSubscriptionServiceType();
    if (instanceName != null) {
        Optional<ServiceInstance> serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceByName(globalCustomerId, serviceType, instanceName);
        if (serviceInstanceAAI.isPresent()) {
            if (serviceInstanceAAI.get().getModelVersionId().equalsIgnoreCase(reqDetails.getModelInfo().getModelVersionId())) {
                return serviceInstanceAAI.get().getServiceInstanceId();
            } else {
                throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_WITH_DIFF_VERSION_ID, instanceName, reqDetails.getModelInfo().getModelVersionId()));
            }
        } else {
            ServiceInstances aaiServiceInstances = bbInputSetupUtils.getAAIServiceInstancesGloballyByName(instanceName);
            if (aaiServiceInstances != null) {
                if (aaiServiceInstances.getServiceInstance() != null && !aaiServiceInstances.getServiceInstance().isEmpty()) {
                    if (aaiServiceInstances.getServiceInstance().size() > 1) {
                        throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_MULTIPLE, instanceName));
                    } else {
                        ServiceInstance si = aaiServiceInstances.getServiceInstance().stream().findFirst().get();
                        Map<String, String> keys = bbInputSetupUtils.getURIKeysFromServiceInstance(si.getServiceInstanceId());
                        throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_WITH_DIFF_COMBINATION, instanceName, keys.get(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId), keys.get(AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType), si.getModelVersionId()));
                    }
                }
            }
        }
    }
    return generatedResourceId;
}
Also used : ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) DuplicateNameException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance)

Example 2 with ServiceInstances

use of org.onap.aai.domain.yang.ServiceInstances in project so by onap.

the class BBInputSetupUtilsTest method getRelatedServiceInstanceFromInstanceGroupNotFoundExceptionTest.

@Test
public void getRelatedServiceInstanceFromInstanceGroupNotFoundExceptionTest() throws Exception {
    expectedException.expect(NoServiceInstanceFoundException.class);
    Optional<ServiceInstances> serviceInstances = Optional.of(new ServiceInstances());
    doReturn(serviceInstances).when(MOCK_aaiResourcesClient).get(eq(ServiceInstances.class), any(AAIPluralResourceUri.class));
    this.bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup("ig-001");
}
Also used : ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) Test(org.junit.Test)

Example 3 with ServiceInstances

use of org.onap.aai.domain.yang.ServiceInstances in project so by onap.

the class BBInputSetupUtilsTest method getRelatedServiceInstanceFromInstanceGroupTest.

@Test
public void getRelatedServiceInstanceFromInstanceGroupTest() throws Exception {
    Optional<ServiceInstances> expected = Optional.of(new ServiceInstances());
    ServiceInstance serviceInstance = new ServiceInstance();
    serviceInstance.setServiceInstanceId("serviceInstanceId");
    serviceInstance.setServiceInstanceName("serviceInstanceName");
    expected.get().getServiceInstance().add(serviceInstance);
    doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(ServiceInstances.class), any(AAIPluralResourceUri.class));
    Optional<ServiceInstance> actual = this.bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup("ig-001");
    assertTrue(actual.isPresent());
    assertEquals(expected.get().getServiceInstance().get(0).getServiceInstanceId(), actual.get().getServiceInstanceId());
}
Also used : ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) Test(org.junit.Test)

Example 4 with ServiceInstances

use of org.onap.aai.domain.yang.ServiceInstances in project so by onap.

the class BBInputSetupUtilsTest method getAAIServiceInstanceByNameTest.

@Test
public void getAAIServiceInstanceByNameTest() throws Exception {
    final String serviceInstanceName = "serviceInstanceName";
    ServiceInstance expectedServiceInstance = new ServiceInstance();
    expectedServiceInstance.setServiceInstanceId("serviceInstanceId");
    ServiceSubscription serviceSubscription = new ServiceSubscription();
    serviceSubscription.setServiceType("serviceType");
    Customer customer = new Customer();
    customer.setGlobalCustomerId("globalCustomerId");
    customer.setServiceSubscription(serviceSubscription);
    ServiceInstances serviceInstances = new ServiceInstances();
    serviceInstances.getServiceInstance().add(expectedServiceInstance);
    AAIPluralResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(customer.getGlobalCustomerId()).serviceSubscription(customer.getServiceSubscription().getServiceType()).serviceInstances()).queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO);
    bbInputSetupUtils.getAAIServiceInstanceByName(serviceInstanceName, customer);
    verify(MOCK_aaiResourcesClient, times(1)).getOne(org.onap.aai.domain.yang.ServiceInstances.class, org.onap.aai.domain.yang.ServiceInstance.class, expectedUri);
}
Also used : ServiceSubscription(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription) ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) Customer(org.onap.so.bpmn.servicedecomposition.bbobjects.Customer) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 5 with ServiceInstances

use of org.onap.aai.domain.yang.ServiceInstances in project so by onap.

the class AaiResourceIdValidatorTest method validateResourceIdInAAIMultipleSITest.

@Test
public void validateResourceIdInAAIMultipleSITest() throws Exception {
    RequestDetails reqDetails = setupRequestDetails();
    reqDetails.getModelInfo().setModelVersionId("1234567");
    ServiceInstance si = new ServiceInstance();
    ServiceInstances serviceInstances = new ServiceInstances();
    serviceInstances.getServiceInstance().add(si);
    ServiceInstance si2 = new ServiceInstance();
    serviceInstances.getServiceInstance().add(si2);
    when(bbInputSetupUtilsMock.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(serviceInstances);
    this.expectedException.expect(DuplicateNameException.class);
    this.expectedException.expectMessage(containsString("serviceInstance with name (siName123) and multiple combination of model-version-id + service-type + global-customer-id already exists. The name must be unique."));
    testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", reqDetails, new WorkflowResourceIds());
}
Also used : ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) WorkflowResourceIds(org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds) Test(org.junit.Test)

Aggregations

ServiceInstances (org.onap.aai.domain.yang.ServiceInstances)13 Test (org.junit.Test)11 ServiceInstance (org.onap.aai.domain.yang.ServiceInstance)11 AAIPluralResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri)6 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 WorkflowResourceIds (org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds)3 HashMap (java.util.HashMap)1 Customer (org.onap.so.bpmn.servicedecomposition.bbobjects.Customer)1 ServiceSubscription (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription)1 DuplicateNameException (org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException)1 MultipleObjectsFoundException (org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException)1 NoServiceInstanceFoundException (org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException)1