Search in sources :

Example 46 with Response

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

the class TransactionIT method begin_and_execute_periodic_commit_that_returns_data_and_commit.

@ParameterizedTest
@MethodSource("argumentsProvider")
public void begin_and_execute_periodic_commit_that_returns_data_and_commit(String txUri) throws Exception {
    this.txUri = txUri;
    int nodes = 11;
    int batchSize = 2;
    // warm up the periodic commit
    withCSVFile(nodes, url -> {
        Response response = POST(transactionCommitUri(), quotedJson("{ 'statements': [ { 'statement': 'USING PERIODIC COMMIT " + batchSize + " LOAD CSV FROM " + "\\\"" + url + "\\\" AS line CREATE (n {id1: 23}) RETURN n' } ] }"));
    });
    withCSVFile(nodes, url -> {
        long nodesInDatabaseBeforeTransaction = countNodes();
        long txIdBefore = resolveDependency(TransactionIdStore.class).getLastClosedTransactionId();
        // begin and execute and commit
        Response response = POST(transactionCommitUri(), quotedJson("{ 'statements': [ { 'statement': 'USING PERIODIC COMMIT " + batchSize + " LOAD CSV FROM " + "\\\"" + url + "\\\" AS line CREATE (n {id1: 23}) RETURN n' } ] }"));
        long txIdAfter = resolveDependency(TransactionIdStore.class).getLastClosedTransactionId();
        assertThat(response.status()).isEqualTo(200);
        assertThat(response).satisfies(containsNoErrors());
        JsonNode columns = response.get("results").get(0).get("columns");
        assertThat(columns.toString()).isEqualTo("[\"n\"]");
        assertThat(countNodes()).isEqualTo(nodesInDatabaseBeforeTransaction + nodes);
        long expectedTxCount = (nodes / batchSize) + 1;
        assertThat(txIdAfter - txIdBefore).isEqualTo(expectedTxCount);
    });
}
Also used : Response(org.neo4j.test.server.HTTP.Response) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 47 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.

@ParameterizedTest
@MethodSource("argumentsProvider")
public void begin_and_execute_and_commit_with_badly_escaped_statement(String txUri) {
    this.txUri = txUri;
    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 = POST(transactionCommitUri(), quotedJson(json));
    assertThat(begin.status()).isEqualTo(200);
    assertThat(begin).satisfies(hasErrors(Status.Request.InvalidFormat));
    assertThat(countNodes()).isEqualTo(nodesInDatabaseBeforeTransaction);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 48 with Response

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

the class TransactionIT method restFormattedNodesShouldHaveSensibleUrisWhenUsingXForwardHeader.

@ParameterizedTest
@MethodSource("argumentsProvider")
public void restFormattedNodesShouldHaveSensibleUrisWhenUsingXForwardHeader(String txUri) throws Exception {
    this.txUri = txUri;
    // given
    final String hostname = "dummy.example.org";
    // when
    Response rs = http.withHeaders(XForwardUtil.X_FORWARD_HOST_HEADER_KEY, hostname).POST(transactionCommitUri(), 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);
    assertPath(restNode.get("outgoing_relationships"), "/node/\\d+/relationships/out", hostname);
    assertPath(restNode.get("traverse"), "/node/\\d+/traverse/\\{returnType\\}", hostname);
    assertPath(restNode.get("all_typed_relationships"), "/node/\\d+/relationships/all/\\{-list\\|&\\|types\\}", hostname);
    assertPath(restNode.get("self"), "/node/\\d+", hostname);
    assertPath(restNode.get("property"), "/node/\\d+/properties/\\{key\\}", hostname);
    assertPath(restNode.get("properties"), "/node/\\d+/properties", hostname);
    assertPath(restNode.get("outgoing_typed_relationships"), "/node/\\d+/relationships/out/\\{-list\\|&\\|types\\}", hostname);
    assertPath(restNode.get("incoming_relationships"), "/node/\\d+/relationships/in", hostname);
    assertPath(restNode.get("create_relationship"), "/node/\\d+/relationships", hostname);
    assertPath(restNode.get("paged_traverse"), "/node/\\d+/paged/traverse/\\{returnType\\}\\{\\?pageSize," + "leaseTime\\}", hostname);
    assertPath(restNode.get("all_relationships"), "/node/\\d+/relationships/all", hostname);
    assertPath(restNode.get("incoming_typed_relationships"), "/node/\\d+/relationships/in/\\{-list\\|&\\|types\\}", hostname);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 49 with Response

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

the class TransactionIT method begin_create_two_nodes_delete_one.

@ParameterizedTest
@MethodSource("argumentsProvider")
public void begin_create_two_nodes_delete_one(String txUri) throws Exception {
    this.txUri = txUri;
    /*
         * This issue was reported from the community. It resulted in a refactoring of the interaction
         * between TxManager and TransactionContexts.
         */
    // GIVEN
    long nodesInDatabaseBeforeTransaction = countNodes();
    Response response1 = POST(transactionCommitUri(), rawPayload("{ \"statements\" : [{\"statement\" : \"CREATE (n0:DecibelEntity :AlbumGroup{DecibelID : " + "'34a2201b-f4a9-420f-87ae-00a9c691cc5c', Title : 'Dance With Me', " + "ArtistString : 'Ra Ra Riot', MainArtistAlias : 'Ra Ra Riot', " + "OriginalReleaseDate : '2013-01-08', IsCanon : 'False'}) return id(n0)\"}, " + "{\"statement\" : \"CREATE (n1:DecibelEntity :AlbumRelease{DecibelID : " + "'9ed529fa-7c19-11e2-be78-bcaec5bea3c3', Title : 'Dance With Me', " + "ArtistString : 'Ra Ra Riot', MainArtistAlias : 'Ra Ra Riot', LabelName : 'Barsuk " + "Records', " + "FormatNames : 'File', TrackCount : '3', MediaCount : '1', Duration : '460.000000', " + "ReleaseDate : '2013-01-08', ReleaseYear : '2013', ReleaseRegion : 'USA', " + "Cline : 'Barsuk Records', Pline : 'Barsuk Records', CYear : '2013', PYear : '2013', " + "ParentalAdvisory : 'False', IsLimitedEdition : 'False'}) return id(n1)\"}]}"));
    assertEquals(200, response1.status());
    JsonNode everything = jsonNode(response1.rawContent());
    JsonNode result = everything.get("results").get(0);
    long id = result.get("data").get(0).get("row").get(0).asLong();
    // WHEN
    Response response2 = POST(transactionCommitUri(), rawPayload("{ \"statements\" : [{\"statement\":\"match (n) where id(n) = " + id + " delete n\"}]}"));
    assertEquals(200, response2.status());
    // THEN
    assertThat(countNodes()).isEqualTo(nodesInDatabaseBeforeTransaction + 1);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 50 with Response

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

the class TransactionIT method begin_and_execute_invalid_query_and_commit.

@ParameterizedTest
@MethodSource("argumentsProvider")
public void begin_and_execute_invalid_query_and_commit(String txUri) {
    this.txUri = txUri;
    // begin and execute and commit
    Response response = POST(transactionCommitUri(), quotedJson("{ 'statements': [ { 'statement': 'MATCH n RETURN m' } ] }"));
    assertThat(response.status()).isEqualTo(200);
    assertThat(response).satisfies(hasErrors(Status.Statement.SyntaxError));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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