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