Search in sources :

Example 6 with Documented

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

the class TestData method beforeEach.

@Override
public void beforeEach(ExtensionContext context) {
    var method = context.getRequiredTestMethod();
    final Title title = method.getAnnotation(Title.class);
    final Documented doc = method.getAnnotation(Documented.class);
    GraphDescription.Graph g = method.getAnnotation(GraphDescription.Graph.class);
    if (g == null) {
        g = context.getRequiredTestClass().getAnnotation(GraphDescription.Graph.class);
    }
    final GraphDescription graph = GraphDescription.create(g);
    product.set(create(graph, title == null ? null : title.value(), doc == null ? null : doc.value(), method.getName()));
}
Also used : Documented(org.neo4j.annotations.documented.Documented)

Example 7 with Documented

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

the class MetricsAsciiDocGenerator method documentField.

private void documentField(StringBuilder builder, Metrics metricsClass, Class<? extends Metrics> clazz, Field field) {
    Documented documented = field.getAnnotation(Documented.class);
    field.setAccessible(true);
    if (documented != null) {
        String fieldValue = getStaticFieldValue(clazz, field);
        String documentedValue = escapeHtml4("<prefix>." + metricsClass.modifyDocumentedMetricName(fieldValue));
        builder.append("|").append(documentedValue).append("|").append(documented.value()).append(NEW_LINE);
    }
}
Also used : Documented(org.neo4j.annotations.documented.Documented)

Example 8 with Documented

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

the class MetricsAsciiDocGenerator method generateDocsFor.

public void generateDocsFor(Metrics metricsClass, StringBuilder builder) {
    Class<? extends Metrics> clazz = metricsClass.getClass();
    Documented documented = clazz.getAnnotation(Documented.class);
    if (documented == null) {
        throw new IllegalStateException("Missing Documented annotation on the class: " + metricsClass);
    }
    builder.append(documented.value()).append(NEW_LINE).append(NEW_LINE);
    Field[] fields = clazz.getDeclaredFields();
    Class superclass = clazz.getSuperclass();
    while (superclass != null) {
        fields = ArrayUtil.concat(fields, superclass.getDeclaredFields());
        superclass = superclass.getSuperclass();
    }
    if (existsDocumentedFields(fields)) {
        builder.append("[options=\"header\",cols=\"<1m,<4\"]").append(NEW_LINE);
        builder.append("|===").append(NEW_LINE);
        builder.append("|Name |Description").append(NEW_LINE);
        for (Field field : fields) {
            documentField(builder, metricsClass, clazz, field);
        }
        builder.append("|===").append(NEW_LINE);
        builder.append(NEW_LINE);
    }
}
Also used : Field(java.lang.reflect.Field) Documented(org.neo4j.annotations.documented.Documented)

Example 9 with Documented

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

the class Roles method user_roles_in_graphs.

@Test
@Documented(ROLES_DOC)
@Graph({ "Admins ROOT Reference_Node", "Users ROOT Reference_Node", "HelpDesk PART_OF Admins", "Managers PART_OF Users", "Technicians PART_OF Users", "ABCTechnicians PART_OF Technicians", "Ali MEMBER_OF Users", "Ali MEMBER_OF Admins", "Engin MEMBER_OF Users", "Engin MEMBER_OF HelpDesk", "Demet MEMBER_OF HelpDesk", "Burcu MEMBER_OF Users", "Can MEMBER_OF Users", "Gul MEMBER_OF Managers", "Fuat MEMBER_OF Managers", "Hakan MEMBER_OF Technicians", "Irmak MEMBER_OF Technicians", "Jale MEMBER_OF ABCTechnicians" })
public void user_roles_in_graphs() {
    // get Admins
    gen.get().addTestSourceSnippets(this.getClass(), "get-admins", "get-user-memberships", "get-groups", "get-members", "read-traverser");
    System.out.println("All admins:");
    // tag::get-admins[]
    Node admins = getNodeByName("Admins");
    GraphDatabaseService db = graphdb();
    try (Transaction transaction = db.beginTx()) {
        TraversalDescription traversal = transaction.traversalDescription().breadthFirst().evaluator(excludeStartPosition()).relationships(RoleRels.PART_OF, INCOMING).relationships(RoleRels.MEMBER_OF, INCOMING);
        // end::get-admins[]
        gen.get().addSnippet("o-get-admins", createOutputSnippet(traverserToString(traversal.traverse(admins))));
        String query = "start admins=node(" + admins.getId() + ") match (admins)<-[:PART_OF*0..]-(group)<-[:MEMBER_OF]-(user) return user.name, group.name";
        gen.get().addSnippet("query-get-admins", createCypherSnippet(query));
        String result = transaction.execute(query).resultAsString();
        assertTrue(result.contains("Engin"));
        gen.get().addSnippet("o-query-get-admins", createQueryResultSnippet(result));
        // Jale's memberships
        // tag::get-user-memberships[]
        Node jale = getNodeByName("Jale");
        traversal = transaction.traversalDescription().depthFirst().evaluator(excludeStartPosition()).relationships(RoleRels.MEMBER_OF, OUTGOING).relationships(RoleRels.PART_OF, OUTGOING);
        // end::get-user-memberships[]
        gen.get().addSnippet("o-get-user-memberships", createOutputSnippet(traverserToString(traversal.traverse(jale))));
        query = "start jale=node(" + jale.getId() + ") match (jale)-[:MEMBER_OF]->()-[:PART_OF*0..]->(group) return group.name";
        gen.get().addSnippet("query-get-user-memberships", createCypherSnippet(query));
        result = transaction.execute(query).resultAsString();
        assertTrue(result.contains("Users"));
        gen.get().addSnippet("o-query-get-user-memberships", createQueryResultSnippet(result));
        // get all groups
        // tag::get-groups[]
        Node referenceNode = getNodeByName("Reference_Node");
        traversal = transaction.traversalDescription().breadthFirst().evaluator(excludeStartPosition()).relationships(RoleRels.ROOT, INCOMING).relationships(RoleRels.PART_OF, INCOMING);
        // end::get-groups[]
        gen.get().addSnippet("o-get-groups", createOutputSnippet(traverserToString(traversal.traverse(referenceNode))));
        query = "start refNode=node(" + referenceNode.getId() + ") match (refNode)<-[:ROOT]->()<-[:PART_OF*0..]-(group) return group.name";
        gen.get().addSnippet("query-get-groups", createCypherSnippet(query));
        result = transaction.execute(query).resultAsString();
        assertTrue(result.contains("Users"));
        gen.get().addSnippet("o-query-get-groups", createQueryResultSnippet(result));
        // get all members
        // tag::get-members[]
        traversal = transaction.traversalDescription().breadthFirst().evaluator(Evaluators.includeWhereLastRelationshipTypeIs(RoleRels.MEMBER_OF)).relationships(RoleRels.ROOT, INCOMING).relationships(RoleRels.PART_OF, INCOMING).relationships(RoleRels.MEMBER_OF, INCOMING);
        // end::get-members[]
        gen.get().addSnippet("o-get-members", createOutputSnippet(traverserToString(traversal.traverse(referenceNode))));
        query = "start refNode=node(" + referenceNode.getId() + ") " + "match (refNode)<-[:ROOT]->(root), p=(root)<-[PART_OF*0..]-()<-[:MEMBER_OF]-(user) " + "return user.name, min(length(p)) " + "order by min(length(p)), user.name";
        gen.get().addSnippet("query-get-members", createCypherSnippet(query));
        result = transaction.execute(query).resultAsString();
        assertTrue(result.contains("Engin"));
        gen.get().addSnippet("o-query-get-members", createQueryResultSnippet(result));
        transaction.commit();
    }
/* more advanced example
        query = "start refNode=node("+ referenceNode.getId() +") " +
                "match p=(refNode)<-[:ROOT]->(parent)<-[:PART_OF*0..]-(group), (group)<-[:MEMBER_OF]-(user) return group.name, user.name, LENGTH(p) " +
                "order by LENGTH(p)";
                */
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Graph(org.neo4j.doc.test.GraphDescription.Graph) Documented(org.neo4j.annotations.documented.Documented) Test(org.junit.Test)

Example 10 with Documented

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

the class RolesDocTest method user_roles_in_graphs.

@Test
@Documented(ROLES_DOC)
@Graph({ "Admins ROOT Reference_Node", "Users ROOT Reference_Node", "HelpDesk PART_OF Admins", "Managers PART_OF Users", "Technicians PART_OF Users", "ABCTechnicians PART_OF Technicians", "Ali MEMBER_OF Users", "Ali MEMBER_OF Admins", "Engin MEMBER_OF Users", "Engin MEMBER_OF HelpDesk", "Demet MEMBER_OF HelpDesk", "Burcu MEMBER_OF Users", "Can MEMBER_OF Users", "Gul MEMBER_OF Managers", "Fuat MEMBER_OF Managers", "Hakan MEMBER_OF Technicians", "Irmak MEMBER_OF Technicians", "Jale MEMBER_OF ABCTechnicians" })
public void user_roles_in_graphs() {
    // get Admins
    gen.get().addTestSourceSnippets(this.getClass(), "get-admins", "get-user-memberships", "get-groups", "get-members", "read-traverser");
    System.out.println("All admins:");
    // tag::get-admins[]
    Node admins = getNodeByName("Admins");
    GraphDatabaseService db = graphdb();
    try (Transaction tx = db.beginTx()) {
        TraversalDescription traversalDescription = tx.traversalDescription().breadthFirst().evaluator(Evaluators.excludeStartPosition()).relationships(RoleRels.PART_OF, Direction.INCOMING).relationships(RoleRels.MEMBER_OF, Direction.INCOMING);
        Traverser traverser = traversalDescription.traverse(tx.getNodeById(admins.getId()));
        gen.get().addSnippet("o-get-admins", createOutputSnippet(traverserToString(traverser)));
        String query = "match ({name: 'Admins'})<-[:PART_OF*0..]-(group)<-[:MEMBER_OF]-(user) return user.name, group.name";
        gen.get().addSnippet("query-get-admins", createCypherSnippet(query));
        String result = tx.execute(query).resultAsString();
        assertTrue(result.contains("Engin"));
        gen.get().addSnippet("o-query-get-admins", createQueryResultSnippet(result));
        // Jale's memberships
        // tag::get-user-memberships[]
        Node jale = tx.getNodeById(getNodeByName("Jale").getId());
        traversalDescription = tx.traversalDescription().depthFirst().evaluator(Evaluators.excludeStartPosition()).relationships(RoleRels.MEMBER_OF, Direction.OUTGOING).relationships(RoleRels.PART_OF, Direction.OUTGOING);
        traverser = traversalDescription.traverse(jale);
        // end::get-user-memberships[]
        gen.get().addSnippet("o-get-user-memberships", createOutputSnippet(traverserToString(traverser)));
        query = "match ({name: 'Jale'})-[:MEMBER_OF]->()-[:PART_OF*0..]->(group) return group.name";
        gen.get().addSnippet("query-get-user-memberships", createCypherSnippet(query));
        result = tx.execute(query).resultAsString();
        assertTrue(result.contains("Users"));
        gen.get().addSnippet("o-query-get-user-memberships", createQueryResultSnippet(result));
        // get all groups
        // tag::get-groups[]
        Node referenceNode = tx.getNodeById(getNodeByName("Reference_Node").getId());
        traversalDescription = tx.traversalDescription().breadthFirst().evaluator(Evaluators.excludeStartPosition()).relationships(RoleRels.ROOT, Direction.INCOMING).relationships(RoleRels.PART_OF, Direction.INCOMING);
        traverser = traversalDescription.traverse(referenceNode);
        // end::get-groups[]
        gen.get().addSnippet("o-get-groups", createOutputSnippet(traverserToString(traverser)));
        query = "match ({name: 'Reference_Node'})<-[:ROOT]->()<-[:PART_OF*0..]-(group) return group.name";
        gen.get().addSnippet("query-get-groups", createCypherSnippet(query));
        result = tx.execute(query).resultAsString();
        assertTrue(result.contains("Users"));
        gen.get().addSnippet("o-query-get-groups", createQueryResultSnippet(result));
        // get all members
        // tag::get-members[]
        traversalDescription = tx.traversalDescription().breadthFirst().evaluator(Evaluators.includeWhereLastRelationshipTypeIs(RoleRels.MEMBER_OF));
        traverser = traversalDescription.traverse(referenceNode);
        // end::get-members[]
        gen.get().addSnippet("o-get-members", createOutputSnippet(traverserToString(traverser)));
        query = "match ({name: 'Reference_Node'})<-[:ROOT]->(root), p=(root)<-[PART_OF*0..]-()<-[:MEMBER_OF]-(user) " + "return user.name, min(length(p)) " + "order by min(length(p)), user.name";
        gen.get().addSnippet("query-get-members", createCypherSnippet(query));
        result = tx.execute(query).resultAsString();
        assertTrue(result.contains("Engin"));
        gen.get().addSnippet("o-query-get-members", createQueryResultSnippet(result));
    /* more advanced example
            query = "start refNode=node("+ referenceNode.getId() +") " +
                    "match p=refNode<-[:ROOT]->parent<-[:PART_OF*0..]-group, group<-[:MEMBER_OF]-user return group.name, user.name, LENGTH(p) " +
                    "order by LENGTH(p)";
                    */
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Traverser(org.neo4j.graphdb.traversal.Traverser) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Graph(org.neo4j.doc.test.GraphDescription.Graph) 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