Search in sources :

Example 36 with Response

use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.

the class QueryResultsSerializationTest method shouldFailIfTryingToReturnLabelsOfDeletedNodeGraph.

@Test
public void shouldFailIfTryingToReturnLabelsOfDeletedNodeGraph() {
    // given
    graphdb().execute("CREATE (:NodeToDelete)");
    // execute and commit
    Response commit = http.POST(commitResource, queryAsJsonGraph("MATCH (n:NodeToDelete) DELETE n RETURN labels(n)"));
    assertThat(commit, hasErrors(Status.Statement.EntityNotFound));
    assertThat(commit.status(), equalTo(200));
    assertThat(nodesInDatabase(), equalTo(1L));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.Test)

Example 37 with Response

use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.

the class BatchEndpointIT method requestsShouldNotFailWhenHttpLoggingIsOn.

@Test
public void requestsShouldNotFailWhenHttpLoggingIsOn() {
    // Given
    String body = "[" + "{'method': 'POST', 'to': '/node', 'body': {'age': 1}, 'id': 1} ]";
    // When
    Response response = withBaseUri(neo4j.httpURI().toString()).withHeaders("Content-Type", "application/json").POST("db/data/batch", quotedJson(body));
    // Then
    assertEquals(200, response.status());
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.Test)

Example 38 with Response

use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.

the class TransactionIT method should_include_graph_format_when_requested.

@Test
public void should_include_graph_format_when_requested() throws Exception {
    long initialData = countNodes("Foo");
    // given
    http.POST("/db/data/transaction/commit", singleStatement("CREATE (n:Foo:Bar)"));
    // when
    Response response = http.POST("/db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'MATCH (n:Foo) RETURN n', 'resultDataContents':['row'," + "'graph'] } ] }"));
    // then
    assertThat(response.status(), equalTo(200));
    JsonNode data = response.get("results").get(0).get("data");
    assertTrue("data is a list", data.isArray());
    assertEquals("one entry", initialData + 1, data.size());
    JsonNode entry = data.get(0);
    assertTrue("entry has row", entry.has("row"));
    assertTrue("entry has graph", entry.has("graph"));
    JsonNode nodes = entry.get("graph").get("nodes"), rels = entry.get("graph").get("relationships");
    assertTrue("nodes is a list", nodes.isArray());
    assertTrue("relationships is a list", rels.isArray());
    assertEquals("one node", 1, nodes.size());
    assertEquals("no relationships", 0, rels.size());
    Set<String> labels = new HashSet<>();
    for (JsonNode node : nodes.get(0).get("labels")) {
        labels.add(node.getTextValue());
    }
    assertEquals("labels", asSet("Foo", "Bar"), labels);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) JsonNode(org.codehaus.jackson.JsonNode) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 39 with Response

use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.

the class TransactionIT method begin__execute__execute__commit.

@Test
public void begin__execute__execute__commit() throws Exception {
    long nodesInDatabaseBeforeTransaction = countNodes();
    // begin
    Response begin = http.POST("/db/data/transaction");
    String commitResource = begin.stringFromContent("commit");
    // execute
    http.POST(begin.location(), quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ]" + " }"));
    // execute
    http.POST(begin.location(), quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ]" + " }"));
    // commit
    http.POST(commitResource);
    assertThat(countNodes(), equalTo(nodesInDatabaseBeforeTransaction + 2));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.Test)

Example 40 with Response

use of org.neo4j.test.server.HTTP.Response in project neo4j by neo4j.

the class TransactionIT method restFormatNodesShouldHaveSensibleUris.

@Test
public void restFormatNodesShouldHaveSensibleUris() throws Throwable {
    // given
    final String hostname = "localhost";
    final String scheme = "http";
    // when
    Response rs = http.POST("/db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'CREATE (n:Foo:Bar) RETURN n', 'resultDataContents':['rest'] } ] }"));
    // then
    JsonNode restNode = rs.get("results").get(0).get("data").get(0).get("rest").get(0);
    assertPath(restNode.get("labels"), "/node/\\d+/labels", hostname, scheme);
    assertPath(restNode.get("outgoing_relationships"), "/node/\\d+/relationships/out", hostname, scheme);
    assertPath(restNode.get("traverse"), "/node/\\d+/traverse/\\{returnType\\}", hostname, scheme);
    assertPath(restNode.get("all_typed_relationships"), "/node/\\d+/relationships/all/\\{-list\\|&\\|types\\}", hostname, scheme);
    assertPath(restNode.get("self"), "/node/\\d+", hostname, scheme);
    assertPath(restNode.get("property"), "/node/\\d+/properties/\\{key\\}", hostname, scheme);
    assertPath(restNode.get("properties"), "/node/\\d+/properties", hostname, scheme);
    assertPath(restNode.get("outgoing_typed_relationships"), "/node/\\d+/relationships/out/\\{-list\\|&\\|types\\}", hostname, scheme);
    assertPath(restNode.get("incoming_relationships"), "/node/\\d+/relationships/in", hostname, scheme);
    assertPath(restNode.get("create_relationship"), "/node/\\d+/relationships", hostname, scheme);
    assertPath(restNode.get("paged_traverse"), "/node/\\d+/paged/traverse/\\{returnType\\}\\{\\?pageSize," + "leaseTime\\}", "localhost", scheme);
    assertPath(restNode.get("all_relationships"), "/node/\\d+/relationships/all", hostname, scheme);
    assertPath(restNode.get("incoming_typed_relationships"), "/node/\\d+/relationships/in/\\{-list\\|&\\|types\\}", hostname, scheme);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Aggregations

Response (org.neo4j.test.server.HTTP.Response)73 Test (org.junit.Test)69 JsonNode (org.codehaus.jackson.JsonNode)12 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)3 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Before (org.junit.Before)2 HTTP (org.neo4j.test.server.HTTP)2 HashSet (java.util.HashSet)1 Description (org.hamcrest.Description)1 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Node (org.neo4j.graphdb.Node)1 Transaction (org.neo4j.graphdb.Transaction)1 ServerControls (org.neo4j.harness.ServerControls)1 JsonHelper.jsonNode (org.neo4j.server.rest.domain.JsonHelper.jsonNode)1