use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.
the class TestJavaTestDocsGenerator method canCreateDocsFromSnippetsInAnnotations.
@Documented("Title2.\n" + "\n" + "@@snippet1\n" + "\n" + " more stuff\n" + "\n" + "\n" + "@@snippet2")
@Test
@Graph("I know you")
public void canCreateDocsFromSnippetsInAnnotations() throws Exception {
data.get();
JavaTestDocsGenerator doc = gen.get();
doc.setGraph(graphdb);
assertNotNull(data.get().get("I"));
String snippet1 = "snippet1-value";
String snippet2 = "snippet2-value";
doc.addSnippet("snippet1", snippet1);
doc.addSnippet("snippet2", snippet2);
doc.document(directory.toAbsolutePath().toString(), sectionName);
String result = readFileAsString(sectionDirectory.resolve("title2.asciidoc"));
assertTrue(result.contains("include::includes/title2-snippet1.asciidoc[]"));
assertTrue(result.contains("include::includes/title2-snippet2.asciidoc[]"));
result = readFileAsString(sectionDirectory.resolve("includes").resolve("title2-snippet1.asciidoc"));
assertTrue(result.contains(snippet1));
result = readFileAsString(sectionDirectory.resolve("includes").resolve("title2-snippet2.asciidoc"));
assertTrue(result.contains(snippet2));
}
use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.
the class TestJavaTestDocsGenerator method will_not_complain_about_missing_snippets.
@Documented(value = "@@snippet1\n")
@Test
@Graph("I know you")
public void will_not_complain_about_missing_snippets() throws Exception {
data.get();
JavaTestDocsGenerator doc = gen.get();
doc.document(directory.toAbsolutePath().toString(), sectionName);
}
use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.
the class AclExampleDocTest method ACL_structures_in_graphs.
@Documented(ACL_DOCUMENTATION)
@Graph(value = { "Root has Role", "Role subRole SUDOers", "Role subRole User", "User member User1", "User member User2", "Root has FileRoot", "FileRoot contains Home", "Home contains HomeU1", "Home contains HomeU2", "HomeU1 leaf File1", "HomeU2 contains Desktop", "Desktop leaf File2", "FileRoot contains etc", "etc contains init.d", "SUDOers member Admin1", "SUDOers member Admin2", "User1 owns File1", "User2 owns File2", "SUDOers canRead FileRoot" })
@Test
public void ACL_structures_in_graphs() {
data.get();
// TODO: can we do open ended?
try (Transaction transaction = graphdb().beginTx()) {
String query = "match ({name: 'FileRoot'})-[:contains*0..]->(parentDir)-[:leaf]->(file) return file";
gen.get().addSnippet("query1", createCypherSnippet(query));
String result = transaction.execute(query).resultAsString();
assertTrue(result.contains("File1"));
gen.get().addSnippet("result1", createQueryResultSnippet(result));
// Ownership
query = "match ({name: 'FileRoot'})-[:contains*0..]->()-[:leaf]->(file)<-[:owns]-(user) return file, user";
gen.get().addSnippet("query2", createCypherSnippet(query));
result = transaction.execute(query).resultAsString();
assertTrue(result.contains("File1"));
assertTrue(result.contains("User1"));
assertTrue(result.contains("User2"));
assertTrue(result.contains("File2"));
assertFalse(result.contains("Admin1"));
assertFalse(result.contains("Admin2"));
gen.get().addSnippet("result2", createQueryResultSnippet(result));
// ACL
query = "MATCH (file)<-[:leaf]-()<-[:contains*0..]-(dir) " + "OPTIONAL MATCH (dir)<-[:canRead]-(role)-[:member]->(readUser) " + "WHERE file.name =~ 'File.*' " + "RETURN file.name, dir.name, role.name, readUser.name";
gen.get().addSnippet("query3", createCypherSnippet(query));
result = transaction.execute(query).resultAsString();
assertTrue(result.contains("File1"));
assertTrue(result.contains("File2"));
assertTrue(result.contains("Admin1"));
assertTrue(result.contains("Admin2"));
gen.get().addSnippet("result3", createQueryResultSnippet(result));
transaction.commit();
}
}
use of org.neo4j.annotations.documented.Documented in project neo4j-documentation by neo4j.
the class AuthenticationDocIT 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
RESTDocsGenerator.ResponseEntity response = gen.get().noGraph().expectedStatus(401).withHeader(HttpHeaders.AUTHORIZATION, challengeResponse("neo4j", "incorrect")).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("Invalid username or password."));
}
use of org.neo4j.annotations.documented.Documented 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(txUri());
// 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"));
}
Aggregations