Search in sources :

Example 51 with Response

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

the class TransactionIT method begin__execute__commit.

@ParameterizedTest
@MethodSource("argumentsProvider")
public void begin__execute__commit(String txUri) throws Exception {
    this.txUri = txUri;
    long nodesInDatabaseBeforeTransaction = countNodes();
    // begin
    Response begin = POST(txUri);
    assertThat(begin.status()).isEqualTo(201);
    assertHasTxLocation(begin, txUri);
    String commitResource = begin.stringFromContent("commit");
    assertThat(commitResource).matches(format("http://localhost:\\d+/%s/\\d+/commit", txUri));
    assertThat(begin.get("transaction").get("expires").asText()).satisfies(validRFCTimestamp());
    // execute
    Response execute = POST(begin.location(), quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
    assertThat(execute.status()).isEqualTo(200);
    assertThat(execute.get("transaction").get("expires").asText()).satisfies(validRFCTimestamp());
    // commit
    Response commit = POST(commitResource);
    assertThat(commit.status()).isEqualTo(200);
    assertThat(countNodes()).isEqualTo(nodesInDatabaseBeforeTransaction + 1);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 52 with Response

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

the class TransactionIT method begin__execute_and_commit.

@ParameterizedTest
@MethodSource("argumentsProvider")
public void begin__execute_and_commit(String txUri) throws Exception {
    this.txUri = txUri;
    long nodesInDatabaseBeforeTransaction = countNodes();
    // begin
    Response begin = POST(txUri);
    assertThat(begin.status()).isEqualTo(201);
    assertHasTxLocation(begin, txUri);
    String commitResource = begin.stringFromContent("commit");
    assertThat(commitResource).isEqualTo(begin.location() + "/commit");
    // execute and commit
    Response commit = POST(commitResource, quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
    assertThat(commit).satisfies(containsNoErrors());
    assertThat(commit.status()).isEqualTo(200);
    assertThat(countNodes()).isEqualTo(nodesInDatabaseBeforeTransaction + 1);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 53 with Response

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

the class JoltResultFormatIT method setUp.

@BeforeEach
void setUp() {
    // begin
    Response begin = http.POST(txUri());
    assertThat(begin.status()).isEqualTo(201);
    assertHasTxLocation(begin);
    try {
        commitResource = begin.get("info").get("commit").asText();
    } catch (JsonParseException e) {
        fail("Exception caught when setting up test: " + e.getMessage());
    }
    assertThat(commitResource).isEqualTo(begin.location() + "/commit");
}
Also used : Response(org.neo4j.test.server.HTTP.Response) JsonParseException(org.neo4j.server.rest.domain.JsonParseException) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 54 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
    executeTransactionally("CREATE (:NodeToDelete)");
    // execute and commit
    Response commit = http.POST(commitResource, queryAsJsonGraph("MATCH (n:NodeToDelete) DELETE n RETURN labels(n)"));
    assertThat(commit).satisfies(hasErrors(Status.Statement.EntityNotFound));
    assertThat(commit.status()).isEqualTo(200);
    assertThat(nodesInDatabase()).isEqualTo(1L);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.jupiter.api.Test)

Example 55 with Response

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

the class QueryResultsSerializationTest method returningAPartiallyDeletedPathRow.

@Test
public void returningAPartiallyDeletedPathRow() {
    // given
    String query = "CREATE (:Start)-[:R]->(:End)";
    executeTransactionally(query);
    // execute and commit
    Response commit = http.POST(commitResource, queryAsJsonRow("MATCH p=(s)-[r:R]->(e) DELETE s,r RETURN p"));
    assertThat(commit).satisfies(containsNoErrors());
    assertThat(commit).satisfies(rowContainsDeletedEntitiesInPath(1, 1));
    assertThat(commit.status()).isEqualTo(200);
    assertThat(nodesInDatabase()).isEqualTo(1L);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.jupiter.api.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