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;
}
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");
}
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());
}
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);
}
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());
}
Aggregations