Search in sources :

Example 66 with Response

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

the class QueryResultsSerializationTest method shouldHandleTemporalUsingRestResultDataContent.

@Test
public void shouldHandleTemporalUsingRestResultDataContent() throws Exception {
    // Given
    var db = getDefaultDatabase();
    ZonedDateTime date = ZonedDateTime.of(1980, 3, 11, 0, 0, 0, 0, ZoneId.of("Europe/Stockholm"));
    try (Transaction tx = db.beginTx()) {
        Node node = tx.createNode(label("N"));
        node.setProperty("date", date);
        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("date");
    assertEquals("\"1980-03-11T00:00+01:00[Europe/Stockholm]\"", row.toString());
}
Also used : Transaction(org.neo4j.graphdb.Transaction) ZonedDateTime(java.time.ZonedDateTime) Node(org.neo4j.graphdb.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) Response(org.neo4j.test.server.HTTP.Response) HTTP(org.neo4j.test.server.HTTP) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test)

Example 67 with Response

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

the class QueryResultsSerializationTest method shouldBeAbleToReturnDeletedNodesRest.

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

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

the class QueryResultsSerializationTest method shouldNotMarkNormalEntitiesAsDeletedRow.

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

Example 69 with Response

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

the class QueryResultsSerializationTest method shouldHandleDurationUsingRestResultDataContent.

@Test
public void shouldHandleDurationUsingRestResultDataContent() throws Exception {
    // Given
    var db = getDefaultDatabase();
    Duration duration = Duration.ofSeconds(73);
    try (Transaction tx = db.beginTx()) {
        Node node = tx.createNode(label("N"));
        node.setProperty("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("duration");
    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 70 with Response

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

the class QueryResultsSerializationTest method shouldBeAbleToReturnDeletedRelationshipsRest.

@Test
public void shouldBeAbleToReturnDeletedRelationshipsRest() {
    // given
    executeTransactionally("CREATE (:Start)-[:R {p: 'a property'}]->(:End)");
    // execute and commit
    Response commit = http.POST(commitResource, queryAsJsonRest("MATCH (s)-[r:R]->(e) DELETE r RETURN r"));
    assertThat(commit).satisfies(containsNoErrors());
    assertThat(commit).satisfies(restContainsDeletedEntities(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)

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