use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.
the class StreamingBatchOperationIT method shouldForwardUnderlyingErrors.
@Test
public void shouldForwardUnderlyingErrors() throws Exception {
JaxRsResponse response = RestRequest.req().accept(APPLICATION_JSON_TYPE).header(StreamingFormat.STREAM_HEADER, "true").post(batchUri(), new PrettyJSON().array().object().key("method").value("POST").key("to").value("/node").key("body").object().key("age").array().value(true).value("hello").endArray().endObject().endObject().endArray().toString());
Map<String, Object> res = singleResult(response, 0);
assertTrue(((String) res.get("message")).startsWith("Invalid JSON array in POST body"));
assertEquals(400, res.get("status"));
}
use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.
the class StreamingBatchOperationIT method shouldRollbackAllWhenGivenIncorrectRequest.
@Test
public void shouldRollbackAllWhenGivenIncorrectRequest() throws JsonParseException, ClientHandlerException, UniformInterfaceException, JSONException {
String jsonString = new PrettyJSON().array().object().key("method").value("POST").key("to").value("/node").key("body").object().key("age").value("1").endObject().endObject().object().key("method").value("POST").key("to").value("/node").key("body").array().value("a_list").value("this_makes_no_sense").endArray().endObject().endArray().toString();
long originalNodeCount = countNodes();
JaxRsResponse response = RestRequest.req().accept(APPLICATION_JSON_TYPE).header(StreamingFormat.STREAM_HEADER, "true").post(batchUri(), jsonString);
assertEquals(200, response.getStatus());
// Message of the ClassCastException differs in Oracle JDK [typeX cannot be cast to typeY]
// and IBM JDK [typeX incompatible with typeY]. That is why we check parts of the message and exception class.
Map<String, String> body = (Map) singleResult(response, 1).get("body");
assertEquals(BadInputException.class.getSimpleName(), body.get("exception"));
assertThat(body.get("message"), containsString("java.util.ArrayList"));
assertThat(body.get("message"), containsString("java.util.Map"));
assertEquals(400, singleResult(response, 1).get("status"));
assertEquals(originalNodeCount, countNodes());
}
use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.
the class StreamingBatchOperationIT method shouldGetLocationHeadersWhenCreatingThings.
@Test
public void shouldGetLocationHeadersWhenCreatingThings() throws Exception {
long originalNodeCount = countNodes();
final String jsonString = new PrettyJSON().array().object().key("method").value("POST").key("to").value("/node").key("body").object().key("age").value(1).endObject().endObject().endArray().toString();
JaxRsResponse response = RestRequest.req().accept(APPLICATION_JSON_TYPE).header(StreamingFormat.STREAM_HEADER, "true").post(batchUri(), jsonString);
assertEquals(200, response.getStatus());
final String entity = response.getEntity();
List<Map<String, Object>> results = JsonHelper.jsonToList(entity);
assertEquals(originalNodeCount + 1, countNodes());
assertEquals(1, results.size());
Map<String, Object> result = results.get(0);
assertTrue(((String) result.get("location")).length() > 0);
}
Aggregations