use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.
the class TransactionTestIT method rollback_an_open_transaction.
@Test
@Documented("Rollback an open transaction\n" + "\n" + "Given that you have an open transaction, you can send a rollback request. The server will rollback the\n" + "transaction. Any further statements trying to run in this transaction will fail immediately.")
public void rollback_an_open_transaction() throws JsonParseException {
// Given
HTTP.Response firstReq = POST(txUri(), HTTP.RawPayload.quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' } ] }"));
String location = firstReq.location();
// Document
ResponseEntity response = gen.get().expectedStatus(200).delete(location);
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertNoErrors(result);
Integer id = resultCell(firstReq, 0, 0);
verifyNodeDoesNotExist(id);
}
use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.
the class TransactionTestIT method verifyNodeExists.
private void verifyNodeExists(long nodeId) {
ResponseEntity response = getNodeById(nodeId);
// if at least one node is returned, there will be "node" in the metadata part od the the row
assertThat(response.entity()).contains("node");
}
use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.
the class TransactionTestIT 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().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' } ] }")).post(txCommitUri());
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertNoErrors(result);
Integer id = resultCell(result, 0, 0);
verifyNodeExists(id);
}
use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.
the class TransactionTestIT 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().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).doesNotContainKey("transaction");
}
use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.
the class TransactionTestIT 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(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).containsKey("stats");
Map<String, Object> stats = (Map<String, Object>) firstResult.get("stats");
assertThat(stats.get("nodes_created")).isEqualTo(1);
assertThat(stats.get("contains_updates")).isEqualTo(true);
assertThat(stats.get("contains_system_updates")).isEqualTo(false);
assertThat(stats.get("system_updates")).isEqualTo(0);
}
Aggregations