Search in sources :

Example 11 with PrettyJSON

use of org.neo4j.server.rest.PrettyJSON in project neo4j by neo4j.

the class StreamingBatchOperationIT method shouldHandleEscapedStrings.

@Test
@Graph("Peter likes Jazz")
public void shouldHandleEscapedStrings() throws ClientHandlerException, UniformInterfaceException, JSONException, JsonParseException {
    String string = "Jazz";
    Node gnode = getNode(string);
    assertThat(gnode, inTx(graphdb(), Neo4jMatchers.hasProperty("name").withValue(string)));
    String name = "string\\ and \"test\"";
    String jsonString = new PrettyJSON().array().object().key("method").value("PUT").key("to").value("/node/" + gnode.getId() + "/properties").key("body").object().key("name").value(name).endObject().endObject().endArray().toString();
    gen.get().expectedType(APPLICATION_JSON_TYPE).withHeader(StreamingFormat.STREAM_HEADER, "true").expectedStatus(200).payload(jsonString).post(batchUri()).entity();
    jsonString = new PrettyJSON().array().object().key("method").value("GET").key("to").value("/node/" + gnode.getId() + "/properties/name").endObject().endArray().toString();
    String entity = gen.get().expectedStatus(200).payload(jsonString).post(batchUri()).entity();
    List<Map<String, Object>> results = JsonHelper.jsonToList(entity);
    assertEquals(results.get(0).get("body"), name);
}
Also used : Node(org.neo4j.graphdb.Node) PrettyJSON(org.neo4j.server.rest.PrettyJSON) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 12 with PrettyJSON

use of org.neo4j.server.rest.PrettyJSON 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

Test (org.junit.Test)12 PrettyJSON (org.neo4j.server.rest.PrettyJSON)12 Matchers.containsString (org.hamcrest.Matchers.containsString)11 Map (java.util.Map)8 JaxRsResponse (org.neo4j.server.rest.JaxRsResponse)8 Graph (org.neo4j.test.GraphDescription.Graph)2 Node (org.neo4j.graphdb.Node)1 RestRequest (org.neo4j.server.rest.RestRequest)1 BadInputException (org.neo4j.server.rest.repr.BadInputException)1