Search in sources :

Example 56 with JaxRsResponse

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"));
}
Also used : PrettyJSON(org.neo4j.server.rest.PrettyJSON) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 57 with JaxRsResponse

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());
}
Also used : BadInputException(org.neo4j.server.rest.repr.BadInputException) PrettyJSON(org.neo4j.server.rest.PrettyJSON) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Map(java.util.Map) Test(org.junit.Test)

Example 58 with JaxRsResponse

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);
}
Also used : PrettyJSON(org.neo4j.server.rest.PrettyJSON) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Map(java.util.Map) Test(org.junit.Test)

Aggregations

JaxRsResponse (org.neo4j.server.rest.JaxRsResponse)58 Test (org.junit.Test)52 RestRequest (org.neo4j.server.rest.RestRequest)29 Matchers.containsString (org.hamcrest.Matchers.containsString)19 FunctionalTestHelper (org.neo4j.server.helpers.FunctionalTestHelper)13 PrettyJSON (org.neo4j.server.rest.PrettyJSON)8 URI (java.net.URI)7 Documented (org.neo4j.kernel.impl.annotations.Documented)6 Map (java.util.Map)4 Client (com.sun.jersey.api.client.Client)3 Title (org.neo4j.test.TestData.Title)3 File (java.io.File)2 FileUtils.readTextFile (org.neo4j.io.fs.FileUtils.readTextFile)2 NeoServer (org.neo4j.server.NeoServer)2 HashMap (java.util.HashMap)1 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)1 CommunityServerBuilder (org.neo4j.server.helpers.CommunityServerBuilder)1 BadInputException (org.neo4j.server.rest.repr.BadInputException)1 NodeRepresentationTest (org.neo4j.server.rest.repr.NodeRepresentationTest)1 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)1