Search in sources :

Example 1 with ResponseEntity

use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.

the class PagedTraverserDocIT method shouldPostATraverserWithDefaultOptionsAndReceiveTheFirstPageOfResults.

@Documented("Creating a paged traverser.\n\n" + "Paged traversers are created by ++POST++-ing a\n" + "traversal description to the link identified by the +paged_traverser+ key\n" + "in a node representation. When creating a paged traverser, the same\n" + "options apply as for a regular traverser, meaning that +node+, +path+,\n" + "or +fullpath+, can be targeted.")
@Test
public void shouldPostATraverserWithDefaultOptionsAndReceiveTheFirstPageOfResults() throws Exception {
    theStartNode = createLinkedList(SHORT_LIST_LENGTH, server.getDatabase());
    ResponseEntity entity = gen.get().expectedType(MediaType.valueOf("application/json; charset=UTF-8")).expectedHeader("Location").expectedStatus(201).payload(traverserDescription()).payloadType(MediaType.APPLICATION_JSON_TYPE).post(functionalTestHelper.nodeUri(theStartNode.getId()) + "/paged/traverse/node");
    assertEquals(201, entity.response().getStatus());
    assertThat(entity.response().getLocation().toString(), containsString("/db/data/node/" + theStartNode.getId() + "/paged/traverse/node/"));
    assertEquals("application/json; charset=utf-8", entity.response().getType().toString().toLowerCase());
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 2 with ResponseEntity

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(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));
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 3 with ResponseEntity

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, 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().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);
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) HTTP(org.neo4j.doc.server.HTTP) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 4 with ResponseEntity

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(getDataUri() + "transaction").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);
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 5 with ResponseEntity

use of org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity in project neo4j-documentation by neo4j.

the class TransactionDocIT 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().noGraph().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"));
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)21 ResponseEntity (org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity)21 Documented (org.neo4j.kernel.impl.annotations.Documented)20 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 ArrayList (java.util.ArrayList)3 Node (org.neo4j.graphdb.Node)3 Transaction (org.neo4j.graphdb.Transaction)3 List (java.util.List)2 Map (java.util.Map)2 HTTP (org.neo4j.doc.server.HTTP)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1