use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class TransactionDocIT method begin_and_commit_a_legacy_transaction_in_one_request.
@Test
@Documented("Begin and commit a legacy transaction in one request\n" + "\n" + "If there is no need to keep a transaction open across multiple HTTP requests, you can begin a transaction,\n" + "execute statements, and commit with just a single HTTP request.")
public void begin_and_commit_a_legacy_transaction_in_one_request() throws JsonParseException {
// Document
ResponseEntity response = gen.get().noGraph().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' } ] }")).post(getDatabaseUri() + "data/transaction/commit");
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertNoErrors(result);
Integer id = resultCell(result, 0, 0);
verifyNodeExists(id);
}
use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class TransactionDocIT 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().noGraph().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)', 'includeStats': true } ] }")).post(txCommitUri());
// 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.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class TransactionDocIT method errors_in_open_transaction.
@Test
@Documented("Handling errors in an open transaction\n" + "\n" + "Whenever there is an error in a request the server will rollback the transaction.\n" + "By inspecting the response for the presence/absence of the `transaction` key you can tell if the " + "transaction is still open")
public void errors_in_open_transaction() throws JsonParseException {
// Given
String location = POST(txUri()).location();
// Document
ResponseEntity response = gen.get().noGraph().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'This is not a valid Cypher Statement.' } ] }")).post(location);
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertThat(result, not(hasKey("transaction")));
}
use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class TransactionDocIT 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().noGraph().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' }, " + "{ 'statement': 'CREATE (n $props) RETURN n', " + "'parameters': { 'props': { 'name': 'My Node' } } } ] }")).post(txCommitUri());
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertNoErrors(result);
Integer id = resultCell(result, 0, 0);
verifyNodeExists(id);
assertThat(response.entity(), containsString("My Node"));
}
use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class TransactionDocIT method commit_an_open_transaction.
@Test
@Documented("Commit an open transaction\n" + "\n" + "Given you have an open transaction, you can send a commit request. Optionally, you submit additional statements\n" + "along with the request that will be executed before committing the transaction.")
public void commit_an_open_transaction() throws JsonParseException {
// Given
String location = POST(txUri()).location();
// Document
ResponseEntity response = gen.get().noGraph().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' } ] }")).post(location + "/commit");
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertNoErrors(result);
Integer id = resultCell(result, 0, 0);
verifyNodeExists(id);
}
Aggregations