Search in sources :

Example 11 with Response

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

the class TransactionIT method shouldSerializeMapsCorrectlyInRowsFormat.

@Test
public void shouldSerializeMapsCorrectlyInRowsFormat() throws Exception {
    Response response = http.POST("/db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'RETURN {one:{two:[true, {three: 42}]}}' } ] }"));
    // then
    assertThat(response.status(), equalTo(200));
    JsonNode data = response.get("results").get(0);
    JsonNode row = data.get("data").get(0).get("row");
    assertThat(row.size(), equalTo(1));
    JsonNode firstCell = row.get(0);
    assertThat(firstCell.get("one").get("two").size(), is(2));
    assertThat(firstCell.get("one").get("two").get(0).asBoolean(), is(true));
    assertThat(firstCell.get("one").get("two").get(1).get("three").asInt(), is(42));
    assertThat(response.get("errors").size(), equalTo(0));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Example 12 with Response

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

the class TransactionIT method transaction_not_in_response_on_failure.

@Test
public void transaction_not_in_response_on_failure() throws Exception {
    // begin
    Response begin = http.POST("/db/data/transaction");
    String commitResource = begin.stringFromContent("commit");
    // execute valid statement
    Response valid = http.POST(begin.location(), quotedJson("{ 'statements': [ { 'statement': 'RETURN 42' } ] }"));
    assertThat(valid.status(), equalTo(200));
    assertThat(valid.get("transaction"), notNullValue());
    // execute invalid statement
    Response invalid = http.POST(begin.location(), quotedJson("{ 'statements': [ { 'statement': 'RETRUN 42' } ] }"));
    assertThat(invalid.status(), equalTo(200));
    //transaction has been closed and rolled back
    assertThat(invalid.get("transaction"), nullValue());
    // commit
    Response commit = http.POST(commitResource);
    //no transaction open anymore, we have failed
    assertThat(commit.status(), equalTo(404));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.Test)

Example 13 with Response

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

the class TransactionIT method begin__execute__rollback.

@Test
public void begin__execute__rollback() throws Exception {
    long nodesInDatabaseBeforeTransaction = countNodes();
    // begin
    Response begin = http.POST("/db/data/transaction");
    assertThat(begin.status(), equalTo(201));
    assertHasTxLocation(begin);
    // execute
    http.POST(begin.location(), quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
    // rollback
    Response commit = http.DELETE(begin.location());
    assertThat(commit.status(), equalTo(200));
    assertThat(countNodes(), equalTo(nodesInDatabaseBeforeTransaction));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.Test)

Example 14 with Response

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

the class TransactionIT method restFormattedNodesShouldHaveSensibleUrisWhenUsingXForwardHeader.

@Test
public void restFormattedNodesShouldHaveSensibleUrisWhenUsingXForwardHeader() throws Throwable {
    // given
    final String hostname = "dummy.example.org";
    final String scheme = "http";
    // when
    Response rs = http.withHeaders(XForwardUtil.X_FORWARD_HOST_HEADER_KEY, hostname).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\\}", hostname, 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)

Example 15 with Response

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

the class TransactionIT method begin_and_execute_and_commit_with_badly_escaped_statement.

@Test
public void begin_and_execute_and_commit_with_badly_escaped_statement() throws Exception {
    long nodesInDatabaseBeforeTransaction = countNodes();
    String json = "{ \"statements\": [ { \"statement\": \"LOAD CSV WITH HEADERS FROM " + "\\\"xx file://C:/countries.csvxxx\\\\\" as csvLine MERGE (c:Country { Code: csvLine.Code })\" " + "} ] }";
    // begin and execute and commit
    Response begin = http.POST("/db/data/transaction/commit", quotedJson(json));
    assertThat(begin.status(), equalTo(200));
    assertThat(begin, hasErrors(Status.Request.InvalidFormat));
    assertThat(countNodes(), equalTo(nodesInDatabaseBeforeTransaction));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) 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