Search in sources :

Example 11 with Documented

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));
}
Also used : JavaTestDocsGenerator(org.neo4j.doc.tools.JavaTestDocsGenerator) Graph(org.neo4j.doc.test.GraphDescription.Graph) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Example 12 with Documented

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);
}
Also used : JavaTestDocsGenerator(org.neo4j.doc.tools.JavaTestDocsGenerator) Graph(org.neo4j.doc.test.GraphDescription.Graph) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Example 13 with Documented

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();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Graph(org.neo4j.doc.test.GraphDescription.Graph) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Example 14 with Documented

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."));
}
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 15 with Documented

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

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