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.");
}
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);
}
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);
}
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");
}
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);
}
Aggregations