Search in sources :

Example 1 with GraphInventoryUriNotFoundException

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();
}
Also used : GraphInventoryUriNotFoundException(org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException) BadRequestException(javax.ws.rs.BadRequestException) IOException(java.io.IOException) GraphInventoryPayloadException(org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryPayloadException)

Example 2 with GraphInventoryUriNotFoundException

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();
}
Also used : GraphInventoryUriNotFoundException(org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException) GraphInventoryUriComputationException(org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriComputationException) GraphInventoryPayloadException(org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryPayloadException)

Example 3 with GraphInventoryUriNotFoundException

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();
}
Also used : GraphInventoryUriNotFoundException(org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException) GraphInventoryUriComputationException(org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriComputationException) GraphInventoryPayloadException(org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryPayloadException)

Example 4 with GraphInventoryUriNotFoundException

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();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) GraphInventoryUriNotFoundException(org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) ObjectOutputStream(java.io.ObjectOutputStream) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 5 with GraphInventoryUriNotFoundException

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();
}
Also used : GraphInventoryUriNotFoundException(org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Test(org.junit.Test)

Aggregations

GraphInventoryUriNotFoundException (org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException)5 GraphInventoryPayloadException (org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryPayloadException)3 NotFoundException (javax.ws.rs.NotFoundException)2 Test (org.junit.Test)2 AAIResourcesClient (org.onap.aaiclient.client.aai.AAIResourcesClient)2 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)2 GraphInventoryUriComputationException (org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriComputationException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 BadRequestException (javax.ws.rs.BadRequestException)1