Search in sources :

Example 1 with Documented

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

the class AuthenticationIT method incorrect_authentication.

@Test
@Documented("Incorrect authentication\n" + "\n" + "If an incorrect username or password is provided, the server replies with an error.")
public void incorrect_authentication() throws JsonParseException, IOException {
    // Given
    startServerWithConfiguredUser();
    // Document
    RESTRequestGenerator.ResponseEntity response = gen.get().expectedStatus(401).withHeader(HttpHeaders.AUTHORIZATION, HTTP.basicAuthHeader("neo4j", "incorrect")).expectedHeader("WWW-Authenticate", "Basic realm=\"Neo4j\"").post(databaseURL());
    // Then
    JsonNode data = JsonHelper.jsonNode(response.entity());
    JsonNode firstError = data.get("errors").get(0);
    assertThat(firstError.get("code").asText()).isEqualTo(Status.Security.Unauthorized.code().serialize());
    assertThat(firstError.get("message").asText()).isEqualTo("Invalid username or password.");
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) RESTRequestGenerator(org.neo4j.server.rest.RESTRequestGenerator) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.jupiter.api.Test)

Example 2 with Documented

use of org.neo4j.annotations.documented.Documented 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);
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) HTTP(org.neo4j.test.server.HTTP) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.jupiter.api.Test)

Example 3 with Documented

use of org.neo4j.annotations.documented.Documented 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);
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.jupiter.api.Test)

Example 4 with Documented

use of org.neo4j.annotations.documented.Documented 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");
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.jupiter.api.Test)

Example 5 with Documented

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