Search in sources :

Example 1 with PrettyJSON

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

the class StreamingBatchOperationDocIT 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.doc.server.rest.PrettyJSON) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 2 with PrettyJSON

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

the class StreamingBatchOperationDocIT method shouldRollbackAllOnSingle404.

@Test
public void shouldRollbackAllOnSingle404() 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("www.google.com").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());
    assertEquals(404, singleResult(response, 1).get("status"));
    assertEquals(originalNodeCount, countNodes());
}
Also used : PrettyJSON(org.neo4j.doc.server.rest.PrettyJSON) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 3 with PrettyJSON

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

the class StreamingBatchOperationDocIT method shouldBeAbleToReferToUniquelyCreatedEntities.

@Test
public void shouldBeAbleToReferToUniquelyCreatedEntities() throws Exception {
    String jsonString = new PrettyJSON().array().object().key("method").value("POST").key("to").value("/index/node/Cultures?unique").key("body").object().key("key").value("ID").key("value").value("fra").key("properties").object().key("ID").value("fra").endObject().endObject().key("id").value(0).endObject().object().key("method").value("POST").key("to").value("/node").key("id").value(1).endObject().object().key("method").value("POST").key("to").value("{1}/relationships").key("body").object().key("to").value("{0}").key("type").value("has").endObject().key("id").value(2).endObject().endArray().toString();
    JaxRsResponse response = RestRequest.req().accept(APPLICATION_JSON_TYPE).header(StreamingFormat.STREAM_HEADER, "true").post(batchUri(), jsonString);
    assertEquals(200, response.getStatus());
}
Also used : PrettyJSON(org.neo4j.doc.server.rest.PrettyJSON) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 4 with PrettyJSON

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

the class BatchOperationHeaderDocIT method shouldPassHeaders.

@Test
public void shouldPassHeaders() throws Exception {
    String jsonData = new PrettyJSON().array().object().key("method").value("GET").key("to").value("../.." + DUMMY_WEB_SERVICE_MOUNT_POINT + "/needs-auth-header").key("body").object().endObject().endObject().endArray().toString();
    JaxRsResponse response = new RestRequest(null, "user", "pass").post("http://localhost:7474/db/data/batch", jsonData);
    assertEquals(200, response.getStatus());
    final List<Map<String, Object>> responseData = jsonToList(response.getEntity());
    Map<String, Object> res = (Map<String, Object>) responseData.get(0).get("body");
    /*
         * {
         *   Accept=[application/json],
         *   Content-Type=[application/json],
         *   Authorization=[Basic dXNlcjpwYXNz],
         *   User-Agent=[Java/1.6.0_27] <-- ignore that, it changes often
         *   Host=[localhost:7474],
         *   Connection=[keep-alive],
         *   Content-Length=[86]
         * }
         */
    assertEquals("Basic dXNlcjpwYXNz", res.get("Authorization"));
    assertEquals("application/json", res.get("Accept"));
    assertEquals("application/json", res.get("Content-Type"));
    assertEquals("localhost:7474", res.get("Host"));
    assertEquals("keep-alive", res.get("Connection"));
}
Also used : RestRequest(org.neo4j.doc.server.rest.RestRequest) PrettyJSON(org.neo4j.doc.server.rest.PrettyJSON) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Map(java.util.Map) Test(org.junit.Test)

Example 5 with PrettyJSON

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

the class StreamingBatchOperationDocIT method shouldBeAbleToReferToNotCreatedUniqueEntities.

// It has to be possible to create relationships among created and not-created nodes
// in batch operation.  Tests the fix for issue #690.
@Test
public void shouldBeAbleToReferToNotCreatedUniqueEntities() throws Exception {
    String jsonString = new PrettyJSON().array().object().key("method").value("POST").key("to").value("/index/node/Cultures?unique").key("body").object().key("key").value("name").key("value").value("tobias").key("properties").object().key("name").value("Tobias Tester").endObject().endObject().key("id").value(0).endObject().object().key("method").value("POST").key("to").value("/index/node/Cultures?unique").key("body").object().key("key").value("name").key("value").value("andres").key("properties").object().key("name").value("Andres Tester").endObject().endObject().key("id").value(1).endObject().object().key("method").value("POST").key("to").value("/index/node/Cultures?unique").key("body").object().key("key").value("name").key("value").value("andres").key("properties").object().key("name").value("Andres Tester").endObject().endObject().key("id").value(2).endObject().object().key("method").value("POST").key("to").value("/index/relationship/my_rels/?unique").key("body").object().key("key").value("name").key("value").value("tobias-andres").key("start").value("{0}").key("end").value("{1}").key("type").value("FRIENDS").endObject().key("id").value(3).endObject().object().key("method").value("POST").key("to").value("/index/relationship/my_rels/?unique").key("body").object().key("key").value("name").key("value").value("andres-tobias").key("start").value(// Not-created entity here
    "{2}").key("end").value("{0}").key("type").value("FRIENDS").endObject().key("id").value(4).endObject().object().key("method").value("POST").key("to").value("/index/relationship/my_rels/?unique").key("body").object().key("key").value("name").key("value").value("andres-tobias").key("start").value(// Relationship should not be created
    "{1}").key("end").value("{0}").key("type").value("FRIENDS").endObject().key("id").value(5).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(6, results.size());
    Map<String, Object> andresResult1 = results.get(1);
    Map<String, Object> andresResult2 = results.get(2);
    Map<String, Object> secondRelationship = results.get(4);
    Map<String, Object> thirdRelationship = results.get(5);
    // Same people
    Map<String, Object> body1 = (Map<String, Object>) andresResult1.get("body");
    Map<String, Object> body2 = (Map<String, Object>) andresResult2.get("body");
    assertEquals(body1.get("id"), body2.get("id"));
    // Same relationship
    body1 = (Map<String, Object>) secondRelationship.get("body");
    body2 = (Map<String, Object>) thirdRelationship.get("body");
    assertEquals(body1.get("self"), body2.get("self"));
    // Created for {2} {0}
    assertTrue(((String) secondRelationship.get("location")).length() > 0);
    // {2} = {1} = Andres
    body1 = (Map<String, Object>) secondRelationship.get("body");
    body2 = (Map<String, Object>) andresResult1.get("body");
    assertEquals(body1.get("start"), body2.get("self"));
}
Also used : PrettyJSON(org.neo4j.doc.server.rest.PrettyJSON) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Map(java.util.Map) 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