use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class TransactionDocIT 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(txUri()).location();
// Document
ResponseEntity response = gen.get().noGraph().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.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class TransactionDocIT 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().noGraph().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.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class TransactionDocIT method begin_and_commit_a_transaction_in_one_request.
@Test
@Documented("Begin and commit a 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_transaction_in_one_request() throws JsonParseException {
// Document
ResponseEntity response = gen.get().noGraph().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.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class TransactionDocIT method reset_transaction_timeout_of_an_open_transaction.
@Test
@Documented("Reset transaction timeout of an open transaction\n" + "\n" + "Every orphaned transaction is automatically expired after a period of inactivity. This may be prevented\n" + "by resetting the transaction timeout.\n" + "\n" + "The timeout may be reset by sending a keep-alive request to the server that executes an empty list of statements.\n" + "This request will reset the transaction timeout and return the new time at which the transaction will\n" + "expire as an RFC1123 formatted timestamp value in the ``transaction'' section of the response.")
public void reset_transaction_timeout_of_an_open_transaction() throws JsonParseException, InterruptedException {
// Given
HTTP.Response initialResponse = POST(txUri());
String location = initialResponse.location();
long initialExpirationTime = expirationTime(jsonToMap(initialResponse.rawContent()));
// This generous wait time is necessary to compensate for limited resolution of RFC 1123 timestamps
// and the fact that the system clock is allowed to run "backwards" between threads
// (cf. http://stackoverflow.com/questions/2978598)
//
Thread.sleep(3000);
// Document
ResponseEntity response = gen.get().noGraph().expectedStatus(200).payload(quotedJson("{ 'statements': [ ] }")).post(location);
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertNoErrors(result);
long newExpirationTime = expirationTime(result);
assertTrue("Expiration time was not increased", newExpirationTime > initialExpirationTime);
}
use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.
the class TransactionDocIT 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
Assert.assertThat(response.entity(), Matchers.containsString("node"));
}
Aggregations