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]")));
}
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());
}
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);
}
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);
}
Aggregations