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