Search in sources :

Example 1 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class CypherQueriesIT method runningWithGeometryTypes.

@Test
public void runningWithGeometryTypes() throws JsonParseException {
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'RETURN point({latitude:1.2,longitude:2.3}) as point' } ] }")).post(getDataUri() + "transaction/commit");
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) Test(org.junit.Test)

Example 2 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class TransactionTest method execute_statements_in_an_open_transaction.

@Test
@Documented("Execute statements in an open transaction\n" + "\n" + "Given that you have an open transaction, you can make a number of requests, each of which executes additional\n" + "statements, and keeps the transaction open by resetting the transaction timeout.")
public void execute_statements_in_an_open_transaction() throws JsonParseException {
    // Given
    String location = POST(getDataUri() + "transaction").location();
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN n' } ] }")).post(location);
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertThat(result, hasKey("transaction"));
    assertNoErrors(result);
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 3 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class TransactionTest method handling_errors.

@Test
@Documented("Handling errors\n" + "\n" + "The result of any request against the transaction endpoint is streamed back to the client.\n" + "Therefore the server does not know whether the request will be successful or not when it sends the HTTP status\n" + "code.\n" + "\n" + "Because of this, all requests against the transactional endpoint will return 200 or 201 status code, regardless\n" + "of whether statements were successfully executed. At the end of the response payload, the server includes a list\n" + "of errors that occurred while executing statements. If this list is empty, the request completed successfully.\n" + "\n" + "If any errors occur while executing statements, the server will roll back the transaction.\n" + "\n" + "In this example, we send the server an invalid statement to demonstrate error handling.\n" + " \n" + "For more information on the status codes, see <<status-codes>>.")
public void handling_errors() throws JsonParseException {
    // Given
    String location = POST(getDataUri() + "transaction").location();
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'This is not a valid Cypher Statement.' } ] }")).post(location + "/commit");
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertErrors(result, Status.Statement.SyntaxError);
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 4 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class TransactionTest method include_query_statistics.

@Test
@Documented("Include query statistics\n" + "\n" + "By setting `includeStats` to `true` for a statement, query statistics will be returned for it.")
public void include_query_statistics() throws JsonParseException {
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)', 'includeStats': true } ] }")).post(getDataUri() + "transaction/commit");
    // Then
    Map<String, Object> entity = jsonToMap(response.entity());
    assertNoErrors(entity);
    Map<String, Object> firstResult = ((List<Map<String, Object>>) entity.get("results")).get(0);
    assertThat(firstResult, hasKey("stats"));
    Map<String, Object> stats = (Map<String, Object>) firstResult.get("stats");
    assertThat((Integer) stats.get("nodes_created"), equalTo(1));
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) ArrayList(java.util.ArrayList) List(java.util.List) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) JsonHelper.jsonToMap(org.neo4j.server.rest.domain.JsonHelper.jsonToMap) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 5 with ResponseEntity

use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.

the class TransactionTest method execute_multiple_statements.

@Test
@Documented("Execute multiple statements\n" + "\n" + "You can send multiple Cypher statements in the same request.\n" + "The response will contain the result of each statement.")
public void execute_multiple_statements() throws JsonParseException {
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' }, " + "{ 'statement': 'CREATE (n {props}) RETURN n', " + "'parameters': { 'props': { 'name': 'My Node' } } } ] }")).post(getDataUri() + "transaction/commit");
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
    Integer id = resultCell(result, 0, 0);
    assertThat(GET(getNodeUri(id)).status(), is(200));
    assertThat(response.entity(), containsString("My Node"));
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Aggregations

ResponseEntity (org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity)36 Test (org.junit.Test)22 Documented (org.neo4j.kernel.impl.annotations.Documented)20 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 Test (org.junit.jupiter.api.Test)12 Documented (org.neo4j.annotations.documented.Documented)12 ArrayList (java.util.ArrayList)6 List (java.util.List)5 HTTP (org.neo4j.test.server.HTTP)4 Node (org.neo4j.graphdb.Node)3 Transaction (org.neo4j.graphdb.Transaction)3 Map (java.util.Map)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1