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);
}
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);
}
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);
}
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));
}
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"));
}
Aggregations