Search in sources :

Example 1 with Error

use of uk.gov.gchq.gaffer.core.exception.Error in project Gaffer by gchq.

the class GraphConfigurationControllerIT method shouldReturn500WhenANonExistentClassIsProvidedEndingInClassForGetFilterFunctions.

@Test
public void shouldReturn500WhenANonExistentClassIsProvidedEndingInClassForGetFilterFunctions() {
    // Given
    Graph emptyGraph = new Graph.Builder().config(new GraphConfig.Builder().graphId("id").build()).storeProperties(new MapStoreProperties()).addSchema(new Schema()).build();
    when(graphFactory.getGraph()).thenReturn(emptyGraph);
    // When
    ResponseEntity<Error> response = get("/graph/config/filterFunctions/a.random.class", Error.class);
    // Then
    checkResponse(response, 500);
    assertThat(response.getBody().getSimpleMessage()).isEqualTo("Could not find input class: a.random.class");
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Error(uk.gov.gchq.gaffer.core.exception.Error) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) Test(org.junit.Test)

Example 2 with Error

use of uk.gov.gchq.gaffer.core.exception.Error in project Gaffer by gchq.

the class OperationControllerIT method shouldPropagateStatusInformationContainedInOperationExceptionsThrownByOperationHandlers.

@Test
public void shouldPropagateStatusInformationContainedInOperationExceptionsThrownByOperationHandlers() throws IOException {
    // Given
    final StoreProperties storeProperties = new MapStoreProperties();
    storeProperties.set(StoreProperties.JOB_TRACKER_ENABLED, Boolean.FALSE.toString());
    final Graph graph = new Graph.Builder().config(StreamUtil.graphConfig(this.getClass())).storeProperties(storeProperties).addSchema(new Schema()).build();
    when(getGraphFactory().getGraph()).thenReturn(graph);
    // When
    final ResponseEntity<Error> response = post("/graph/operations/execute", new GetAllJobDetails(), Error.class);
    // Then
    assertEquals(SERVICE_UNAVAILABLE.getStatusCode(), response.getStatusCode().value());
}
Also used : GetAllJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails) Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Error(uk.gov.gchq.gaffer.core.exception.Error) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) Test(org.junit.Test)

Example 3 with Error

use of uk.gov.gchq.gaffer.core.exception.Error in project Gaffer by gchq.

the class GraphConfigurationControllerIT method shouldReturn500WhenANonExistentClassIsProvidedForGetFilterFunctions.

@Test
public void shouldReturn500WhenANonExistentClassIsProvidedForGetFilterFunctions() {
    // Given
    Graph emptyGraph = new Graph.Builder().config(new GraphConfig.Builder().graphId("id").build()).storeProperties(new MapStoreProperties()).addSchema(new Schema()).build();
    when(graphFactory.getGraph()).thenReturn(emptyGraph);
    // When
    ResponseEntity<Error> response = get("/graph/config/filterFunctions/a.random.thing", Error.class);
    // Then
    checkResponse(response, 500);
    assertThat(response.getBody().getSimpleMessage()).isEqualTo("Could not find input class: a.random.thing");
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Error(uk.gov.gchq.gaffer.core.exception.Error) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) Test(org.junit.Test)

Example 4 with Error

use of uk.gov.gchq.gaffer.core.exception.Error in project Gaffer by gchq.

the class ProxyStore method handleResponse.

protected <O> O handleResponse(final Response response, final ResponseDeserialiser<O> responseDeserialiser) throws StoreException {
    final String outputJson = response.hasEntity() ? response.readEntity(String.class) : null;
    if (Family.SUCCESSFUL != response.getStatusInfo().getFamily()) {
        final Error error;
        try {
            error = JSONSerialiser.deserialise(StringUtil.toBytes(outputJson), Error.class);
        } catch (final Exception e) {
            LOGGER.warn("Gaffer bad status {}. Detail: {}", response.getStatus(), outputJson);
            throw new StoreException("Delegate Gaffer store returned status: " + response.getStatus() + ". Response content was: " + outputJson);
        }
        throw new GafferWrappedErrorRuntimeException(error);
    }
    O output = null;
    if (null != outputJson) {
        try {
            output = responseDeserialiser.deserialise(outputJson);
        } catch (final SerialisationException e) {
            throw new StoreException(e.getMessage(), e);
        }
    }
    return output;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Error(uk.gov.gchq.gaffer.core.exception.Error) GafferWrappedErrorRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferWrappedErrorRuntimeException) GafferWrappedErrorRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferWrappedErrorRuntimeException) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StoreException(uk.gov.gchq.gaffer.store.StoreException) GafferRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferRuntimeException) StoreException(uk.gov.gchq.gaffer.store.StoreException) OperationChainDAO(uk.gov.gchq.gaffer.operation.OperationChainDAO)

Example 5 with Error

use of uk.gov.gchq.gaffer.core.exception.Error in project Gaffer by gchq.

the class GraphConfigurationControllerIT method shouldReturn500WhenANonExistentClassIsProvidedForGetSerialiseFields.

@Test
public void shouldReturn500WhenANonExistentClassIsProvidedForGetSerialiseFields() {
    // Given
    Graph emptyGraph = new Graph.Builder().config(new GraphConfig.Builder().graphId("id").build()).storeProperties(new MapStoreProperties()).addSchema(new Schema()).build();
    when(graphFactory.getGraph()).thenReturn(emptyGraph);
    // When
    ResponseEntity<Error> response = get("/graph/config/serialisedFields/a.random.class", Error.class);
    // Then
    checkResponse(response, 500);
    assertThat(response.getBody().getSimpleMessage()).isEqualTo("Class name was not recognised: a.random.class");
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Error(uk.gov.gchq.gaffer.core.exception.Error) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) Test(org.junit.Test)

Aggregations

Error (uk.gov.gchq.gaffer.core.exception.Error)8 Test (org.junit.Test)7 Graph (uk.gov.gchq.gaffer.graph.Graph)7 MapStoreProperties (uk.gov.gchq.gaffer.mapstore.MapStoreProperties)7 Schema (uk.gov.gchq.gaffer.store.schema.Schema)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HttpEntity (org.springframework.http.HttpEntity)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1 GafferRuntimeException (uk.gov.gchq.gaffer.core.exception.GafferRuntimeException)1 GafferWrappedErrorRuntimeException (uk.gov.gchq.gaffer.core.exception.GafferWrappedErrorRuntimeException)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1 GetAllGraphIds (uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds)1 OperationChainDAO (uk.gov.gchq.gaffer.operation.OperationChainDAO)1 OperationException (uk.gov.gchq.gaffer.operation.OperationException)1 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)1 GetAllJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails)1 StoreException (uk.gov.gchq.gaffer.store.StoreException)1 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)1