Search in sources :

Example 6 with Error

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

the class OperationControllerIT method shouldReturnHelpfulErrorMessageIfOperationIsUnsupported.

@Test
public void shouldReturnHelpfulErrorMessageIfOperationIsUnsupported() {
    // Given
    Graph graph = new Graph.Builder().config(StreamUtil.graphConfig(this.getClass())).storeProperties(new MapStoreProperties()).addSchema(new Schema()).build();
    when(getGraphFactory().getGraph()).thenReturn(graph);
    // When
    final ResponseEntity<Error> response = post("/graph/operations/execute", new GetAllGraphIds(), Error.class);
    // Then
    assertNotNull(response.getBody().getSimpleMessage());
    assertTrue(response.getBody().getSimpleMessage().contains("GetAllGraphIds is not supported by the MapStore"));
}
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) GetAllGraphIds(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) Test(org.junit.Test)

Example 7 with Error

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

the class OperationControllerIT method shouldReturnHelpfulErrorMessageIfJsonIsIncorrect.

@Test
public void shouldReturnHelpfulErrorMessageIfJsonIsIncorrect() {
    // Given
    Graph graph = new Graph.Builder().config(StreamUtil.graphConfig(this.getClass())).storeProperties(new MapStoreProperties()).addSchema(new Schema()).build();
    when(getGraphFactory().getGraph()).thenReturn(graph);
    // When
    String request = "{\"class\"\"GetAllElements\"}";
    LinkedMultiValueMap headers = new LinkedMultiValueMap();
    headers.add("Content-Type", "application/json;charset=utf-8");
    final ResponseEntity<Error> response = post("/graph/operations/execute", new HttpEntity(request, headers), Error.class);
    // Then
    assertEquals(400, response.getStatusCode().value());
    assertEquals(400, response.getBody().getStatusCode());
    assertTrue(response.getBody().getSimpleMessage().contains("was expecting a colon to separate field name and value"));
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) 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 8 with Error

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

the class OperationControllerIT method shouldReturn403WhenUnauthorised.

@Test
public void shouldReturn403WhenUnauthorised() throws IOException {
    // Given
    Graph graph = new Graph.Builder().config(StreamUtil.graphConfig(this.getClass())).storeProperties(new MapStoreProperties()).addSchema(new Schema()).build();
    when(getGraphFactory().getGraph()).thenReturn(graph);
    // When
    final ResponseEntity<Error> response = post("/graph/operations/execute", new GetAllElements(), Error.class);
    // Then
    assertEquals(403, response.getStatusCode().value());
    assertEquals(403, response.getBody().getStatusCode());
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) 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