Search in sources :

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

@Test
public void begin_and_execute_periodic_commit_that_returns_data_and_commit() throws Exception {
    int nodes = 11;
    int batch = 2;
    ServerTestUtils.withCSVFile(nodes, url -> {
        long nodesInDatabaseBeforeTransaction = countNodes();
        long txIdBefore = resolveDependency(TransactionIdStore.class).getLastClosedTransactionId();
        Response response = http.POST("/db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'USING PERIODIC COMMIT " + batch + " LOAD CSV FROM \\\"" + url + "\\\" AS line CREATE (n {id: 23}) RETURN n' } ] }"));
        long txIdAfter = resolveDependency(TransactionIdStore.class).getLastClosedTransactionId();
        assertThat(response.status(), equalTo(200));
        assertThat(response, containsNoErrors());
        JsonNode columns = response.get("results").get(0).get("columns");
        assertThat(columns.toString(), equalTo("[\"n\"]"));
        assertThat(countNodes(), equalTo(nodesInDatabaseBeforeTransaction + nodes));
        assertThat(txIdAfter, equalTo(txIdBefore + ((nodes / batch) + 1)));
    });
}
Also used : Response(org.neo4j.test.server.HTTP.Response) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Example 22 with Response

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

the class QueryResultsSerializationTest method shouldFailIfTryingToReturnPropsOfDeletedNodeGraph.

@Test
public void shouldFailIfTryingToReturnPropsOfDeletedNodeGraph() {
    // given
    graphdb().execute("CREATE (:NodeToDelete {p: 'a property'})");
    // execute and commit
    Response commit = http.POST(commitResource, queryAsJsonGraph("MATCH (n:NodeToDelete) DELETE n RETURN n.p"));
    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 23 with Response

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

the class RowFormatMetaFieldTest method metaFieldShouldGetCorrectIndex.

@Test
public void metaFieldShouldGetCorrectIndex() {
    // given
    graphdb().execute("CREATE (:Start)-[:R]->(:End)");
    // execute and commit
    Response commit = http.POST(commitResource, queryAsJsonRow("MATCH (s:Start)-[r:R]->(e:End) RETURN s, r, 1, e"));
    assertThat(commit, containsNoErrors());
    assertThat(commit, rowContainsMetaNodesAtIndex(0, 3));
    assertThat(commit, rowContainsMetaRelsAtIndex(1));
    assertThat(commit.status(), equalTo(200));
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.Test)

Example 24 with Response

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

the class TransactionIT method begin_and_execute_and_commit.

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

Example 25 with Response

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

the class TransactionIT method begin_and_execute_periodic_commit_followed_by_another_statement_and_commit.

@Test
public void begin_and_execute_periodic_commit_followed_by_another_statement_and_commit() throws Exception {
    ServerTestUtils.withCSVFile(1, url -> {
        Response response = http.POST("/db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'USING PERIODIC COMMIT LOAD CSV FROM \\\"" + url + "\\\" AS line CREATE (n {id: 23}) RETURN n' }, { 'statement': 'RETURN 1' } ] }"));
        assertThat(response.status(), equalTo(200));
        assertThat(response, hasErrors(Status.Statement.SemanticError));
    });
}
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