Search in sources :

Example 1 with PrettyJSON

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

the class StreamingBatchOperationIT method shouldRollbackAllWhenInsertingIllegalData.

@Test
public void shouldRollbackAllWhenInsertingIllegalData() 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").object().key("age").object().key("age").value(1).endObject().endObject().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(400, singleResult(response, 1).get("status"));
    assertEquals(originalNodeCount, countNodes());
}
Also used : PrettyJSON(org.neo4j.server.rest.PrettyJSON) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 2 with PrettyJSON

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

the class StreamingBatchOperationIT method refer_to_items_created_earlier_in_the_same_batch_job_streaming.

/**
     * The batch operation API allows you to refer to the URI returned from a
     * created resource in subsequent job descriptions, within the same batch
     * call.
     *
     * Use the +{[JOB ID]}+ special syntax to inject URIs from created resources
     * into JSON strings in subsequent job descriptions.
     */
@Test
public void refer_to_items_created_earlier_in_the_same_batch_job_streaming() throws Exception {
    String jsonString = new PrettyJSON().array().object().key("method").value("POST").key("to").value("/node").key("id").value(0).key("body").object().key("name").value("bob").endObject().endObject().object().key("method").value("POST").key("to").value("/node").key("id").value(1).key("body").object().key("age").value(12).endObject().endObject().object().key("method").value("POST").key("to").value("{0}/relationships").key("id").value(3).key("body").object().key("to").value("{1}").key("data").object().key("since").value("2010").endObject().key("type").value("KNOWS").endObject().endObject().object().key("method").value("POST").key("to").value("/index/relationship/my_rels").key("id").value(4).key("body").object().key("key").value("since").key("value").value("2010").key("uri").value("{3}").endObject().endObject().endArray().toString();
    String entity = gen.get().expectedType(APPLICATION_JSON_TYPE).withHeader(StreamingFormat.STREAM_HEADER, "true").expectedStatus(200).payload(jsonString).post(batchUri()).entity();
    List<Map<String, Object>> results = JsonHelper.jsonToList(entity);
    assertEquals(4, results.size());
//        String rels = gen.get()
//                .expectedStatus( 200 ).get( getRelationshipIndexUri( "my_rels", "since", "2010")).entity();
//        assertEquals(1, JsonHelper.jsonToList(  rels ).size());
}
Also used : PrettyJSON(org.neo4j.server.rest.PrettyJSON) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) Test(org.junit.Test)

Example 3 with PrettyJSON

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

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

Example 4 with PrettyJSON

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

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

Example 5 with PrettyJSON

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

the class StreamingBatchOperationIT 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.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