Search in sources :

Example 81 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 82 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)

Example 83 with Response

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

the class TransactionIT method begin__execute__execute_and_periodic_commit.

@Test
public void begin__execute__execute_and_periodic_commit() throws Exception {
    ServerTestUtils.withCSVFile(1, url -> {
        Response begin = http.POST("/db/data/transaction");
        http.POST(begin.location(), quotedJson("{ 'statements': [ { 'statement': 'CREATE ()' } ] }"));
        Response response = http.POST(begin.location(), quotedJson("{ 'statements': [ { 'statement': 'USING" + " PERIODIC COMMIT LOAD CSV FROM \\\"" + url + "\\\" AS line CREATE ()' } ] }"));
        assertThat(response, hasErrors(Status.Statement.SemanticError));
    });
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.Test)

Example 84 with Response

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

the class TransactionIT method correctStatusCodeWhenUsingHintWithoutAnyIndex.

@Test
public void correctStatusCodeWhenUsingHintWithoutAnyIndex() throws Exception {
    // begin and execute and commit
    Response begin = http.POST("/db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': " + "'MATCH (n:Test) USING INDEX n:Test(foo) WHERE n.foo = 42 RETURN n.foo' } ] }"));
    assertThat(begin, hasErrors(Status.Request.Schema.IndexNotFound));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.Test)

Example 85 with Response

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

the class TransactionIT method begin__execute_and_commit.

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

Aggregations

Response (org.neo4j.test.server.HTTP.Response)151 Test (org.junit.Test)69 Test (org.junit.jupiter.api.Test)43 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)30 MethodSource (org.junit.jupiter.params.provider.MethodSource)30 JsonNode (com.fasterxml.jackson.databind.JsonNode)19 HTTP (org.neo4j.test.server.HTTP)13 JsonNode (org.codehaus.jackson.JsonNode)12 Node (org.neo4j.graphdb.Node)11 Transaction (org.neo4j.graphdb.Transaction)11 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)6 Duration (java.time.Duration)5 ZonedDateTime (java.time.ZonedDateTime)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)3 HttpResponse (java.net.http.HttpResponse)2 HashSet (java.util.HashSet)2 Before (org.junit.Before)2 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)2