Search in sources :

Example 1 with ExecutableRule

use of com.buschmais.jqassistant.core.rule.api.model.ExecutableRule in project jqa-core-framework by buschmais.

the class SubGraphFactoryTest method subGraph.

@Test
public void subGraph() throws ReportException {
    Map<String, Object> virtualGraph = // 
    MapBuilder.<String, Object>builder().entry("role", // 
    "graph").entry("label", // 
    "Virtual Graph").entry("parent", // 
    getNeo4jNode(0l)).entry("nodes", // 
    singletonList(getNeo4jNode(1l))).entry("relationships", // 
    singletonList(getNeo4jRelationship(1l, "TEST"))).build();
    MapBuilder<String, Object> rowBuilder = MapBuilder.builder();
    Map<String, Object> row = rowBuilder.entry("graph", virtualGraph).build();
    Result<ExecutableRule> result = Result.builder().rows(singletonList(row)).build();
    SubGraph graph = factory.createSubGraph(result);
    assertThat(graph.getParent()).isNull();
    assertThat(graph.getNodes()).isEmpty();
    assertThat(graph.getRelationships()).isEmpty();
    Map<Long, SubGraph> subGraphs = graph.getSubGraphs();
    assertThat(subGraphs).hasSize(1);
    SubGraph subGraph = subGraphs.get(-2l);
    assertThat(subGraph.getId()).isEqualTo(-2l);
    assertThat(subGraph.getLabel()).isEqualTo("Virtual Graph");
    Node parent = subGraph.getParent();
    assertThat(parent).isNotNull();
    assertThat(parent.getId()).isEqualTo(0l);
    Map<Long, Node> nodes = subGraph.getNodes();
    assertThat(nodes).hasSize(1);
    Node node1 = nodes.get(1l);
    assertThat(node1.getId()).isEqualTo(1l);
    Map<Long, Relationship> relationships = subGraph.getRelationships();
    assertThat(relationships).hasSize(1);
    Relationship relationship1 = relationships.get(1l);
    assertThat(relationship1.getId()).isEqualTo(1l);
}
Also used : ExecutableRule(com.buschmais.jqassistant.core.rule.api.model.ExecutableRule) Node(com.buschmais.jqassistant.core.report.api.graph.model.Node) Neo4jNode(com.buschmais.xo.neo4j.api.model.Neo4jNode) Neo4jRelationship(com.buschmais.xo.neo4j.api.model.Neo4jRelationship) Relationship(com.buschmais.jqassistant.core.report.api.graph.model.Relationship) CompositeObject(com.buschmais.xo.api.CompositeObject) SubGraph(com.buschmais.jqassistant.core.report.api.graph.model.SubGraph) Test(org.junit.jupiter.api.Test)

Example 2 with ExecutableRule

use of com.buschmais.jqassistant.core.rule.api.model.ExecutableRule in project jqa-core-framework by buschmais.

the class SubGraphFactoryTest method compositeObject.

@Test
public void compositeObject() throws ReportException {
    CompositeObject compositeObject = mock(CompositeObject.class);
    Neo4jNode neo4jNode = getNeo4jNode(1l, "Test");
    doReturn(neo4jNode).when(compositeObject).getDelegate();
    MapBuilder<String, Object> builder = MapBuilder.builder();
    builder.entry("nodes", singletonList(compositeObject));
    Result<ExecutableRule> result = Result.builder().rows(singletonList(builder.build())).build();
    SubGraph graph = factory.createSubGraph(result);
    Map<Long, Node> nodes = graph.getNodes();
    assertThat(nodes).isNotEmpty();
    Node node = nodes.get(1l);
    assertThat(node).isNotNull();
    assertThat(node.getId()).isEqualTo(1l);
    assertThat(node.getLabels()).containsExactly("Test");
}
Also used : CompositeObject(com.buschmais.xo.api.CompositeObject) ExecutableRule(com.buschmais.jqassistant.core.rule.api.model.ExecutableRule) Node(com.buschmais.jqassistant.core.report.api.graph.model.Node) Neo4jNode(com.buschmais.xo.neo4j.api.model.Neo4jNode) CompositeObject(com.buschmais.xo.api.CompositeObject) Neo4jNode(com.buschmais.xo.neo4j.api.model.Neo4jNode) SubGraph(com.buschmais.jqassistant.core.report.api.graph.model.SubGraph) Test(org.junit.jupiter.api.Test)

Example 3 with ExecutableRule

use of com.buschmais.jqassistant.core.rule.api.model.ExecutableRule in project jqa-core-framework by buschmais.

the class SubGraphFactoryTest method virtualNode.

@Test
public void virtualNode() throws ReportException {
    Map<Object, Object> properties = MapBuilder.builder().entry("key", "value").build();
    Map<String, Object> virtualNode = // 
    MapBuilder.<String, Object>builder().entry("role", // 
    "node").entry("label", // 
    "Virtual Node").entry("labels", // 
    singletonList("Test")).entry("properties", // 
    properties).build();
    MapBuilder<String, Object> builder = MapBuilder.builder();
    builder.entry("nodes", singletonList(virtualNode));
    Result<ExecutableRule> result = Result.builder().rows(singletonList(builder.build())).build();
    SubGraph graph = factory.createSubGraph(result);
    Map<Long, Node> nodes = graph.getNodes();
    assertThat(nodes.size()).isEqualTo(1);
    Node node = nodes.get(-1l);
    assertThat(node).isNotNull();
    assertThat(node.getId()).isEqualTo(-1l);
    assertThat(node.getLabel()).isEqualTo("Virtual Node");
    assertThat(node.getLabels()).containsExactly("Test");
    assertThat(node.getProperties()).isEqualTo(properties);
}
Also used : ExecutableRule(com.buschmais.jqassistant.core.rule.api.model.ExecutableRule) Node(com.buschmais.jqassistant.core.report.api.graph.model.Node) Neo4jNode(com.buschmais.xo.neo4j.api.model.Neo4jNode) CompositeObject(com.buschmais.xo.api.CompositeObject) SubGraph(com.buschmais.jqassistant.core.report.api.graph.model.SubGraph) Test(org.junit.jupiter.api.Test)

Example 4 with ExecutableRule

use of com.buschmais.jqassistant.core.rule.api.model.ExecutableRule in project jqa-core-framework by buschmais.

the class ReportHelper method verifyRuleResults.

/**
 * Verifies the given results and logs messages.
 *
 * @param results
 *            The collection of results to verify.
 * @param warnOnSeverity
 *            The severity threshold to warn.
 * @param failOnSeverity
 *            The severity threshold to fail.
 * @param type
 *            The type of the rules (as string).
 * @param header
 *            The header to use.
 * @param logResult
 *            if `true` log the result of the executable rule.
 * @return The number of detected violations.
 */
private int verifyRuleResults(Collection<? extends Result<? extends ExecutableRule>> results, Severity warnOnSeverity, Severity failOnSeverity, String type, String header, boolean logResult) {
    int violations = 0;
    for (Result<?> result : results) {
        if (Result.Status.FAILURE.equals(result.getStatus())) {
            ExecutableRule rule = result.getRule();
            String severityInfo = rule.getSeverity().getInfo(result.getSeverity());
            List<String> resultRows = getResultRows(result, logResult);
            // violation severity level check
            boolean warn = warnOnSeverity != null && result.getSeverity().getLevel() <= warnOnSeverity.getLevel();
            boolean fail = failOnSeverity != null && result.getSeverity().getLevel() <= failOnSeverity.getLevel();
            LoggingStrategy loggingStrategy;
            if (fail) {
                violations++;
                loggingStrategy = errorLogger;
            } else if (warn) {
                loggingStrategy = warnLogger;
            } else {
                loggingStrategy = debugLogger;
            }
            log(loggingStrategy, rule, resultRows, severityInfo, type, header);
        }
    }
    return violations;
}
Also used : ExecutableRule(com.buschmais.jqassistant.core.rule.api.model.ExecutableRule) Constraint(com.buschmais.jqassistant.core.rule.api.model.Constraint)

Example 5 with ExecutableRule

use of com.buschmais.jqassistant.core.rule.api.model.ExecutableRule in project jqa-core-framework by buschmais.

the class SubGraphFactoryTest method nodeAndRelationship.

@Test
public void nodeAndRelationship() throws ReportException {
    MapBuilder<String, Object> builder = MapBuilder.builder();
    Map<String, Object> nodeProperties = MapBuilder.<String, Object>builder().entry("nodeKey", "value").build();
    builder.entry("node", getNeo4jNode(1l, nodeProperties, "Test1", "Test2"));
    Map<String, Object> relationshipProperties = MapBuilder.<String, Object>builder().entry("relationshipKey", "value").build();
    builder.entry("relation", getNeo4jRelationship(1l, relationshipProperties, "TEST"));
    Result<ExecutableRule> result = Result.builder().rows(singletonList(builder.build())).build();
    SubGraph graph = factory.createSubGraph(result);
    assertThat(graph.getId()).isEqualTo(-1l);
    assertThat(graph.getParent()).isNull();
    assertThat(graph.getSubGraphs()).isEmpty();
    Map<Long, Node> nodes = graph.getNodes();
    assertThat(nodes).hasSize(1);
    Node node = nodes.get(1l);
    assertThat(node.getId()).isEqualTo(1l);
    assertThat(node.getLabels()).containsExactly("Test1", "Test2");
    assertThat(node.getProperties()).isEqualTo(nodeProperties);
    Map<Long, Relationship> relationships = graph.getRelationships();
    assertThat(relationships).hasSize(1);
    Relationship relationship = relationships.get(1l);
    assertThat(relationship.getId()).isEqualTo(1l);
    assertThat(relationship.getType()).isEqualTo("TEST");
    assertThat(relationship.getProperties()).isEqualTo(relationshipProperties);
}
Also used : ExecutableRule(com.buschmais.jqassistant.core.rule.api.model.ExecutableRule) Node(com.buschmais.jqassistant.core.report.api.graph.model.Node) Neo4jNode(com.buschmais.xo.neo4j.api.model.Neo4jNode) Neo4jRelationship(com.buschmais.xo.neo4j.api.model.Neo4jRelationship) Relationship(com.buschmais.jqassistant.core.report.api.graph.model.Relationship) CompositeObject(com.buschmais.xo.api.CompositeObject) SubGraph(com.buschmais.jqassistant.core.report.api.graph.model.SubGraph) Test(org.junit.jupiter.api.Test)

Aggregations

ExecutableRule (com.buschmais.jqassistant.core.rule.api.model.ExecutableRule)7 Node (com.buschmais.jqassistant.core.report.api.graph.model.Node)6 SubGraph (com.buschmais.jqassistant.core.report.api.graph.model.SubGraph)6 CompositeObject (com.buschmais.xo.api.CompositeObject)6 Neo4jNode (com.buschmais.xo.neo4j.api.model.Neo4jNode)6 Test (org.junit.jupiter.api.Test)6 Relationship (com.buschmais.jqassistant.core.report.api.graph.model.Relationship)4 Neo4jRelationship (com.buschmais.xo.neo4j.api.model.Neo4jRelationship)4 Constraint (com.buschmais.jqassistant.core.rule.api.model.Constraint)1