use of org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException in project so by onap.
the class HttpLookupUri method getObjectById.
protected String getObjectById(Object id) throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
if (!this.getCachedValue().isPresent()) {
AAIResourceUri serviceInstanceUri = AAIUriFactory.createNodesUri(aaiType, id).format(Format.PATHED);
String resultJson;
try {
resultJson = this.getResourcesClient().get(serviceInstanceUri, NotFoundException.class).getJson();
} catch (BadRequestException e) {
throw new GraphInventoryUriNotFoundException(aaiType.typeName() + " " + id + " not found at: " + serviceInstanceUri.build());
}
try {
cachedValue = extractRelatedLink(resultJson);
if (!cachedValue.isPresent()) {
throw new GraphInventoryUriNotFoundException(aaiType.typeName() + " " + id + " not found at: " + serviceInstanceUri.build());
}
} catch (IOException e) {
throw new GraphInventoryPayloadException("could not map payload: " + resultJson, e);
}
}
return cachedValue.get();
}
use of org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException in project so by onap.
the class HttpLookupUri method build.
@Override
public URI build() {
try {
if (this.values.length == 1) {
String uri = getObjectById(this.values[0]);
Map<String, String> map = super.getURIKeys(uri);
this.values = map.values().toArray(values);
return super.build(values);
}
} catch (GraphInventoryUriNotFoundException | GraphInventoryPayloadException e) {
throw new GraphInventoryUriComputationException(e);
}
return super.build();
}
use of org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException in project so by onap.
the class HttpLookupUri method locateAndBuild.
@Override
public URI locateAndBuild() {
try {
if (this.values.length == 1) {
String uri = getObjectById(this.values[0]);
Map<String, String> map = super.getURIKeys(uri);
this.values = map.values().toArray(values);
return super.build(values);
}
} catch (GraphInventoryUriNotFoundException | GraphInventoryPayloadException e) {
throw new GraphInventoryUriComputationException(e);
}
return super.build();
}
use of org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException in project so by onap.
the class ServiceInstanceUriTest method serializeTest.
@Test
public void serializeTest() throws IOException, ClassNotFoundException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key3"));
final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json")));
ServiceInstanceUri spy = spy(instance);
AAIResourcesClient mockResourcesClient = mock(AAIResourcesClient.class);
AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
when(mockResourcesClient.get(ArgumentMatchers.<AAIResourceUri>any(AAIResourceUri.class), ArgumentMatchers.<Class<NotFoundException>>any())).thenReturn(wrapper);
when(wrapper.getJson()).thenReturn(content);
when(spy.getResourcesClient()).thenReturn(mockResourcesClient);
spy.locateAndBuild();
instance = spy.clone();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos);
objectOutputStream.writeObject(instance);
objectOutputStream.flush();
objectOutputStream.close();
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream objectInputStream = new ObjectInputStream(bis);
ServiceInstanceUri e2 = (ServiceInstanceUri) objectInputStream.readObject();
objectInputStream.close();
ServiceInstanceUri spy2 = spy(e2);
assertEquals(spy2.build().toString(), instance.build().toString());
// use the cached value do not call out to external system
verify(spy2, times(0)).getResourcesClient();
}
use of org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException in project so by onap.
the class ServiceInstanceUriTest method notfound.
@Test
public void notfound() throws IOException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "empty-query-result.json")));
ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key3"));
ServiceInstanceUri spy = spy(instance);
AAIResourcesClient mockResourcesClient = mock(AAIResourcesClient.class);
AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
when(mockResourcesClient.get(ArgumentMatchers.<AAIResourceUri>any(AAIResourceUri.class), ArgumentMatchers.<Class<NotFoundException>>any())).thenReturn(wrapper);
when(wrapper.getJson()).thenReturn(content);
when(spy.getResourcesClient()).thenReturn(mockResourcesClient);
exception.expect(GraphInventoryUriComputationException.class);
spy.locateAndBuild();
}
Aggregations