Search in sources :

Example 11 with Neo4jError

use of org.neo4j.server.rest.transactional.error.Neo4jError in project neo4j by neo4j.

the class StatementDeserializerTest method shouldNotThrowButReportErrorOnInvalidInput.

@Test
public void shouldNotThrowButReportErrorOnInvalidInput() throws Exception {
    assertYieldsErrors("{}", new Neo4jError(Status.Request.InvalidFormat, new DeserializationException("Unable to " + "deserialize request. " + "Expected [START_OBJECT, FIELD_NAME, START_ARRAY], " + "found [START_OBJECT, END_OBJECT, null].")));
    assertYieldsErrors("{ \"statements\":\"WAIT WAT A STRING NOO11!\" }", new Neo4jError(Status.Request.InvalidFormat, new DeserializationException("Unable to " + "deserialize request. Expected [START_OBJECT, FIELD_NAME, START_ARRAY], found [START_OBJECT, " + "FIELD_NAME, VALUE_STRING].")));
    assertYieldsErrors("[{]}", new Neo4jError(Status.Request.InvalidFormat, new DeserializationException("Unable to deserialize request: Unexpected close marker ']': " + "expected '}' " + "(for OBJECT starting at [Source: TestInputStream; line: 1, column: 1])\n " + "at [Source: TestInputStream; line: 1, column: 4]")));
    assertYieldsErrors("{ \"statements\" : \"ITS A STRING\" }", new Neo4jError(Status.Request.InvalidFormat, new DeserializationException("Unable to deserialize request. " + "Expected [START_OBJECT, FIELD_NAME, START_ARRAY], " + "found [START_OBJECT, FIELD_NAME, VALUE_STRING].")));
    assertYieldsErrors("{ \"statements\" : [ { \"statement\" : [\"dd\"] } ] }", new Neo4jError(Status.Request.InvalidFormat, new DeserializationException("Unable to deserialize request: Can not deserialize instance of" + " java.lang.String out of START_ARRAY token\n at [Source: TestInputStream; line: 1, " + "column: 22]")));
    assertYieldsErrors("{ \"statements\" : [ { \"statement\" : \"stmt\", \"parameters\" : [\"AN ARRAY!!\"] } ] }", new Neo4jError(Status.Request.InvalidFormat, new DeserializationException("Unable to deserialize request: Can not deserialize instance of" + " java.util.LinkedHashMap out of START_ARRAY token\n at [Source: TestInputStream; " + "line: 1, column: 42]")));
}
Also used : Neo4jError(org.neo4j.server.rest.transactional.error.Neo4jError) Test(org.junit.Test)

Example 12 with Neo4jError

use of org.neo4j.server.rest.transactional.error.Neo4jError in project neo4j by neo4j.

the class StatementDeserializerTest method assertYieldsErrors.

private void assertYieldsErrors(String json, Neo4jError... expectedErrors) throws UnsupportedEncodingException {
    StatementDeserializer de = new StatementDeserializer(new ByteArrayInputStream(UTF8.encode(json)) {

        @Override
        public String toString() {
            return "TestInputStream";
        }
    });
    while (de.hasNext()) {
        de.next();
    }
    Iterator<Neo4jError> actual = de.errors();
    Iterator<Neo4jError> expected = asList(expectedErrors).iterator();
    while (actual.hasNext()) {
        assertTrue(expected.hasNext());
        Neo4jError error = actual.next();
        Neo4jError expectedError = expected.next();
        assertThat(error.getMessage(), equalTo(expectedError.getMessage()));
        assertThat(error.status(), equalTo(expectedError.status()));
    }
    assertFalse(expected.hasNext());
}
Also used : Neo4jError(org.neo4j.server.rest.transactional.error.Neo4jError) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 13 with Neo4jError

use of org.neo4j.server.rest.transactional.error.Neo4jError in project neo4j by neo4j.

the class ExecutionResultSerializerTest method shouldSerializeResponseWithCommitUriAndErrors.

@Test
public void shouldSerializeResponseWithCommitUriAndErrors() throws Exception {
    // given
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ExecutionResultSerializer serializer = getSerializerWith(output);
    // when
    serializer.transactionCommitUri(URI.create("commit/uri/1"));
    serializer.errors(asList(new Neo4jError(Status.Request.InvalidFormat, new Exception("cause1"))));
    serializer.finish();
    // then
    String result = output.toString(UTF_8.name());
    assertEquals("{\"commit\":\"commit/uri/1\",\"results\":[],\"errors\":[{\"code\":\"Neo.ClientError.Request.InvalidFormat\"," + "\"message\":\"cause1\"}]}", result);
}
Also used : Neo4jError(org.neo4j.server.rest.transactional.error.Neo4jError) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsonParseException(org.neo4j.server.rest.domain.JsonParseException) IOException(java.io.IOException) Test(org.junit.Test) Neo4jJsonCodecTest(org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)

Example 14 with Neo4jError

use of org.neo4j.server.rest.transactional.error.Neo4jError in project neo4j by neo4j.

the class ExecutionResultSerializerTest method shouldSerializeResponseWithResultsAndErrors.

@Test
public void shouldSerializeResponseWithResultsAndErrors() throws Exception {
    // given
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ExecutionResultSerializer serializer = getSerializerWith(output);
    Result executionResult = mockExecutionResult(map("column1", "value1", "column2", "value2"));
    // when
    serializer.statementResult(executionResult, false);
    serializer.errors(asList(new Neo4jError(Status.Request.InvalidFormat, new Exception("cause1"))));
    serializer.finish();
    // then
    String result = output.toString(UTF_8.name());
    assertEquals("{\"results\":[{\"columns\":[\"column1\",\"column2\"]," + "\"data\":[{\"row\":[\"value1\",\"value2\"],\"meta\":[null,null]}]}]," + "\"errors\":[{\"code\":\"Neo.ClientError.Request.InvalidFormat\",\"message\":\"cause1\"}]}", result);
}
Also used : Neo4jError(org.neo4j.server.rest.transactional.error.Neo4jError) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ThrowsException(org.mockito.internal.stubbing.answers.ThrowsException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsonParseException(org.neo4j.server.rest.domain.JsonParseException) IOException(java.io.IOException) Result(org.neo4j.graphdb.Result) Test(org.junit.Test) Neo4jJsonCodecTest(org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)

Aggregations

Neo4jError (org.neo4j.server.rest.transactional.error.Neo4jError)14 IOException (java.io.IOException)8 Test (org.junit.Test)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Neo4jJsonCodecTest (org.neo4j.server.rest.transactional.Neo4jJsonCodecTest)6 Result (org.neo4j.graphdb.Result)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ThrowsException (org.mockito.internal.stubbing.answers.ThrowsException)4 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)4 JsonToken (org.codehaus.jackson.JsonToken)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 JsonParseException (org.codehaus.jackson.JsonParseException)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1 CypherException (org.neo4j.cypher.CypherException)1 InvalidSemanticsException (org.neo4j.cypher.InvalidSemanticsException)1 AuthorizationViolationException (org.neo4j.graphdb.security.AuthorizationViolationException)1