Search in sources :

Example 21 with Documented

use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.

the class AuthenticationDocIT method missing_authorization.

@Test
@Documented("Missing authorization\n" + "\n" + "If an +Authorization+ header is not supplied, the server will reply with an error.")
public void missing_authorization() throws JsonParseException, IOException {
    // Given
    startServerWithConfiguredUser();
    // Document
    RESTDocsGenerator.ResponseEntity response = gen.get().noGraph().expectedStatus(401).expectedHeader("WWW-Authenticate", "Basic realm=\"Neo4j\"").payload(simpleCypherRequestBody()).post(txCommitURL());
    // Then
    JsonNode data = JsonHelper.jsonNode(response.entity());
    JsonNode firstError = data.get("errors").get(0);
    assertThat(firstError.get("code").asText(), equalTo("Neo.ClientError.Security.Unauthorized"));
    assertThat(firstError.get("message").asText(), equalTo("No authentication header supplied."));
}
Also used : RESTDocsGenerator(org.neo4j.doc.server.rest.RESTDocsGenerator) JsonNode(com.fasterxml.jackson.databind.JsonNode) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Example 22 with Documented

use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.

the class TransactionDocIT method execute_statements_in_an_open_transaction.

@Test
@Documented("Execute statements in an open transaction\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.")
public void execute_statements_in_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 n' } ] }")).post(location);
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertThat(result, hasKey("transaction"));
    assertNoErrors(result);
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Example 23 with Documented

use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.

the class TransactionDocIT 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(txUri()).location();
    // Document
    ResponseEntity response = gen.get().noGraph().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);
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) JsonHelper.jsonToMap(org.neo4j.server.rest.domain.JsonHelper.jsonToMap) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Example 24 with Documented

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

Example 25 with Documented

use of org.neo4j.annotations.documented.Documented 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));
}
Also used : ResponseEntity(org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity) ArrayList(java.util.ArrayList) List(java.util.List) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) JsonHelper.jsonToMap(org.neo4j.server.rest.domain.JsonHelper.jsonToMap) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Aggregations

Documented (org.neo4j.annotations.documented.Documented)43 Test (org.junit.Test)23 Test (org.junit.jupiter.api.Test)15 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 ResponseEntity (org.neo4j.doc.server.rest.RESTDocsGenerator.ResponseEntity)13 ResponseEntity (org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity)12 Graph (org.neo4j.doc.test.GraphDescription.Graph)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ArrayList (java.util.ArrayList)6 List (java.util.List)5 Transaction (org.neo4j.graphdb.Transaction)4 Map (java.util.Map)3 HTTP (org.neo4j.doc.server.HTTP)3 JavaTestDocsGenerator (org.neo4j.doc.tools.JavaTestDocsGenerator)3 Node (org.neo4j.graphdb.Node)3 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)3 JsonHelper.jsonToMap (org.neo4j.server.rest.domain.JsonHelper.jsonToMap)3 HTTP (org.neo4j.test.server.HTTP)3 Statement (org.junit.runners.model.Statement)2 RESTDocsGenerator (org.neo4j.doc.server.rest.RESTDocsGenerator)2