Search in sources :

Example 61 with Response

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

the class QueryResultsSerializationTest method shouldFailIfTryingToReturnPropsOfDeletedNodeRest.

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

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

the class QueryResultsSerializationTest method shouldHandleDurationArraysUsingRestResultDataContent.

@Test
public void shouldHandleDurationArraysUsingRestResultDataContent() throws Exception {
    // Given
    var db = getDefaultDatabase();
    Duration duration = Duration.ofSeconds(73);
    try (Transaction tx = db.beginTx()) {
        Node node = tx.createNode(label("N"));
        node.setProperty("durations", new Duration[] { duration });
        tx.commit();
    }
    // When
    HTTP.Response response = runQuery("MATCH (n:N) RETURN n", "rest");
    // Then
    assertEquals(200, response.status());
    assertNoErrors(response);
    JsonNode row = response.get("results").get(0).get("data").get(0).get("rest").get(0).get("data").get("durations").get(0);
    assertEquals("\"PT1M13S\"", row.toString());
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) Response(org.neo4j.test.server.HTTP.Response) Duration(java.time.Duration) HTTP(org.neo4j.test.server.HTTP) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test)

Example 63 with Response

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

the class QueryResultsSerializationTest method shouldBeAbleToReturnDeletedRelationshipsRow.

@Test
public void shouldBeAbleToReturnDeletedRelationshipsRow() {
    // given
    executeTransactionally("CREATE (:Start)-[:R {p: 'a property'}]->(:End)");
    // execute and commit
    Response commit = http.POST(commitResource, queryAsJsonRow("MATCH (s)-[r:R]->(e) DELETE r RETURN r"));
    assertThat(commit).satisfies(containsNoErrors());
    assertThat(commit).satisfies(rowContainsDeletedEntities(0, 1));
    assertThat(commit.status()).isEqualTo(200);
    assertThat(nodesInDatabase()).isEqualTo(2L);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) Test(org.junit.jupiter.api.Test)

Example 64 with Response

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

the class QueryResultsSerializationTest method returningADeletedPathRow.

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

Example 65 with Response

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

the class QueryResultsSerializationTest method setUp.

@BeforeEach
public void setUp() {
    // begin
    Response begin = http.POST(txUri());
    assertThat(begin.status()).isEqualTo(201);
    assertHasTxLocation(begin);
    try {
        commitResource = begin.stringFromContent("commit");
    } 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)

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