use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.
the class TransactionTest 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, ParseException, InterruptedException {
// Given
HTTP.Response initialResponse = POST(getDataUri() + "transaction");
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().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.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.
the class TransactionTest method begin_a_transaction.
@Test
@Documented("Begin a transaction\n" + "\n" + "You begin a new transaction by posting zero or more Cypher statements\n" + "to the transaction endpoint. The server will respond with the result of\n" + "your statements, as well as the location of your open transaction.")
public void begin_a_transaction() throws JsonParseException {
// Document
ResponseEntity response = gen.get().expectedStatus(201).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n {props}) RETURN n', " + "'parameters': { 'props': { 'name': 'My Node' } } } ] }")).post(getDataUri() + "transaction");
// Then
Map<String, Object> result = jsonToMap(response.entity());
assertNoErrors(result);
Map<String, Object> node = resultCell(result, 0, 0);
assertThat((String) node.get("name"), equalTo("My Node"));
}
use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.
the class TransactionTest 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().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' } ] }")).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));
}
use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.
the class TransactionTest 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(getDataUri() + "transaction").location();
// Document
ResponseEntity response = gen.get().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);
assertThat(GET(getNodeUri(id)).status(), is(200));
}
use of org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity in project neo4j by neo4j.
the class TransactionTest method execute_statements_in_an_open_transaction_using_REST.
@Test
@Documented("Execute statements in an open transaction in REST format for the return.\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. Specifying the `REST` format will\n" + "give back full Neo4j Rest API representations of the Neo4j Nodes, Relationships and Paths, if returned.")
public void execute_statements_in_an_open_transaction_using_REST() throws JsonParseException {
// Given
String location = POST(getDataUri() + "transaction").location();
// Document
ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN n','resultDataContents':['REST'] } ] }")).post(location);
// Then
Map<String, Object> result = jsonToMap(response.entity());
ArrayList rest = (ArrayList) ((Map) ((ArrayList) ((Map) ((ArrayList) result.get("results")).get(0)).get("data")).get(0)).get("rest");
String selfUri = (String) ((Map) rest.get(0)).get("self");
assertTrue(selfUri.startsWith(getDatabaseUri()));
assertNoErrors(result);
}
Aggregations