Search in sources :

Example 11 with PrettyJSON

use of org.neo4j.doc.server.rest.PrettyJSON in project neo4j-documentation by neo4j.

the class StreamingBatchOperationDocIT method shouldHandleUnicodeGetCorrectly.

@Test
@SuppressWarnings("unchecked")
public void shouldHandleUnicodeGetCorrectly() throws Exception {
    String asianText = "\u4f8b\u5b50";
    String germanText = "öäüÖÄÜß";
    String complicatedString = asianText + germanText;
    String jsonString = new PrettyJSON().array().object().key("method").value("POST").key("to").value("/node").key("body").object().key(complicatedString).value(complicatedString).endObject().endObject().endArray().toString();
    String entity = gen.get().expectedType(APPLICATION_JSON_TYPE).withHeader(StreamingFormat.STREAM_HEADER, "true").expectedStatus(200).payload(jsonString).post(batchUri()).entity();
    // Pull out the property value from the depths of the response
    Map<String, Object> response = (Map<String, Object>) JsonHelper.jsonToList(entity).get(0).get("body");
    String returnedValue = (String) ((Map<String, Object>) response.get("data")).get(complicatedString);
    // Ensure nothing was borked.
    assertThat(returnedValue, is(complicatedString));
}
Also used : PrettyJSON(org.neo4j.doc.server.rest.PrettyJSON) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) Test(org.junit.Test)

Example 12 with PrettyJSON

use of org.neo4j.doc.server.rest.PrettyJSON in project neo4j-documentation by neo4j.

the class StreamingBatchOperationDocIT 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.doc.server.rest.PrettyJSON) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Aggregations

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