Search in sources :

Example 6 with ServiceInstances

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

the class AaiResourceIdValidatorTest method validateServiceResourceIdInAAIDuplicateNameMultipleTest.

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

Example 7 with ServiceInstances

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

the class AaiResourceIdValidatorTest method validateServiceResourceIdInAAIDuplicateNameTest.

@Test
public void validateServiceResourceIdInAAIDuplicateNameTest() throws Exception {
    RequestDetails reqDetails = setupRequestDetails();
    ServiceInstance si = new ServiceInstance();
    si.setModelVersionId("1234567");
    ServiceInstances serviceInstances = new ServiceInstances();
    serviceInstances.getServiceInstance().add(si);
    when(bbInputSetupUtilsMock.getAAIServiceInstancesGloballyByName("siName")).thenReturn(serviceInstances);
    this.expectedException.expect(DuplicateNameException.class);
    this.expectedException.expectMessage(containsString("serviceInstance with name (siName) and global-customer-id (null), service-type (null), model-version-id (1234567) already exists. The name must be unique."));
    testedObject.validateServiceResourceIdInAAI("generatedId123", "siName", reqDetails);
}
Also used : ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) Test(org.junit.Test)

Example 8 with ServiceInstances

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

the class AaiResourceIdValidatorTest method validateResourceIdInAAISITest.

@Test
public void validateResourceIdInAAISITest() throws Exception {
    RequestDetails reqDetails = setupRequestDetails();
    reqDetails.getModelInfo().setModelVersionId("1234567");
    ServiceInstance si = new ServiceInstance();
    si.setServiceInstanceId("siId123");
    si.setModelVersionId("1234567");
    ServiceInstances serviceInstances = new ServiceInstances();
    serviceInstances.getServiceInstance().add(si);
    Optional<ServiceInstance> siOp = Optional.of(si);
    ServiceInstance si2 = new ServiceInstance();
    si2.setServiceInstanceId("siId222");
    si2.setModelVersionId("22222");
    si2.setServiceInstanceName("siName222");
    Optional<ServiceInstance> siOp2 = Optional.of(si2);
    ServiceInstances serviceInstances2 = new ServiceInstances();
    serviceInstances2.getServiceInstance().add(si2);
    when(bbInputSetupUtilsMock.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123")).thenReturn(siOp);
    when(bbInputSetupUtilsMock.getAAIServiceInstanceByName("id123", "subServiceType123", "siName222")).thenReturn(siOp2);
    String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", reqDetails, new WorkflowResourceIds());
    assertEquals("siId123", id);
    String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "111111", reqDetails, new WorkflowResourceIds());
    assertEquals("generatedId123", id2);
    this.expectedException.expect(DuplicateNameException.class);
    this.expectedException.expectMessage(containsString("serviceInstance with name (siName222) and different version id (1234567) already exists. The name must be unique."));
    testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName222", reqDetails, new WorkflowResourceIds());
}
Also used : ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) WorkflowResourceIds(org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds) Test(org.junit.Test)

Example 9 with ServiceInstances

use of org.onap.aai.domain.yang.ServiceInstances 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 10 with ServiceInstances

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

the class AaiResourceIdValidatorTest method validateResourceIdInAAISIExistsTest.

@Test
public void validateResourceIdInAAISIExistsTest() throws Exception {
    RequestDetails reqDetails = setupRequestDetails();
    reqDetails.getModelInfo().setModelVersionId("1234567");
    ServiceInstance si = new ServiceInstance();
    si.setServiceInstanceId("siId123");
    si.setModelVersionId("1234567");
    ServiceInstances serviceInstances = new ServiceInstances();
    serviceInstances.getServiceInstance().add(si);
    Map<String, String> uriKeys = new HashMap<>();
    uriKeys.put(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId, "globalCustomerId");
    uriKeys.put(AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType, "serviceType");
    when(bbInputSetupUtilsMock.getAAIServiceInstancesGloballyByName("siName123")).thenReturn(serviceInstances);
    when(bbInputSetupUtilsMock.getURIKeysFromServiceInstance("siId123")).thenReturn(uriKeys);
    this.expectedException.expect(DuplicateNameException.class);
    this.expectedException.expectMessage(containsString("serviceInstance with name (siName123) and global-customer-id (globalCustomerId), service-type (serviceType), model-version-id (1234567) 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) HashMap(java.util.HashMap) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) 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