use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-core-framework by buschmais.
the class AnalyzerVisitorTest method executeConcept.
@Test
public void executeConcept() throws RuleException {
boolean visitConcept = analyzerVisitor.visitConcept(concept, Severity.MAJOR);
assertThat(visitConcept, equalTo(true));
ArgumentCaptor<Map> argumentCaptor = ArgumentCaptor.forClass(Map.class);
verify(store).executeQuery(Mockito.eq(statement), argumentCaptor.capture());
Map<String, Object> parameters = argumentCaptor.getValue();
assertThat(parameters.get(PARAMETER_WITHOUT_DEFAULT), CoreMatchers.<Object>equalTo("value"));
assertThat(parameters.get(PARAMETER_WITH_DEFAULT), CoreMatchers.<Object>equalTo("defaultValue"));
verify(reportWriter).beginConcept(concept);
ArgumentCaptor<Result> resultCaptor = ArgumentCaptor.forClass(Result.class);
verify(reportWriter).setResult(resultCaptor.capture());
Result result = resultCaptor.getValue();
assertThat(result.getStatus(), equalTo(Result.Status.SUCCESS));
assertThat(result.getSeverity(), equalTo(Severity.MAJOR));
verify(reportWriter).endConcept();
verify(store).create(ConceptDescriptor.class);
}
use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-core-framework by buschmais.
the class AnalyzerVisitor method executeCypher.
/**
* Execute the cypher query of a rule.
*
* @param executableRule
* The executable.
* @param executable
* The executable.
* @param parameters
* The parameters.
* @param severity
* The severity.
* @param <T>
* The rule type.
* @return The result.
* @throws RuleExecutorException
* If execution fails.
*/
private <T extends ExecutableRule> Result<T> executeCypher(T executableRule, CypherExecutable executable, Map<String, Object> parameters, Severity severity) throws RuleExecutorException {
String cypher = executable.getStatement();
List<Map<String, Object>> rows = new ArrayList<>();
try (Query.Result<Query.Result.CompositeRowObject> compositeRowObjects = executeQuery(cypher, parameters)) {
List<String> columnNames = null;
for (Query.Result.CompositeRowObject rowObject : compositeRowObjects) {
if (columnNames == null) {
columnNames = new ArrayList<>(rowObject.getColumns());
}
Map<String, Object> row = new LinkedHashMap<>();
for (String columnName : columnNames) {
row.put(columnName, rowObject.get(columnName, Object.class));
}
rows.add(row);
}
Result.Status status = verify(executableRule, columnNames, rows);
return new Result<>(executableRule, status, severity, columnNames, rows);
} catch (Exception e) {
throw new RuleExecutorException("Cannot execute query for rule '" + executableRule + "'.", e);
}
}
use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-core-framework by buschmais.
the class AnalyzerVisitorTest method columnOrder.
/**
* Verifies that columns of a query a reported in the order given by the
* query.
*
* @throws RuleException
* If the test fails.
*/
@Test
public void columnOrder() throws RuleException {
analyzerVisitor.visitConcept(concept, Severity.MINOR);
ArgumentCaptor<Result> resultCaptor = ArgumentCaptor.forClass(Result.class);
verify(reportWriter).setResult(resultCaptor.capture());
Result capturedResult = resultCaptor.getValue();
assertThat("The reported column names must match the given column names.", capturedResult.getColumnNames(), CoreMatchers.<List>equalTo(columnNames));
List<Map<String, Object>> capturedRows = capturedResult.getRows();
assertThat("Expecting one row.", capturedRows.size(), equalTo(1));
Map<String, Object> capturedRow = capturedRows.get(0);
assertThat("The reported column names must match the given column names.", new ArrayList<>(capturedRow.keySet()), equalTo(columnNames));
}
use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-java-plugin by buschmais.
the class DependencyIT method packageCycles.
/**
* Verifies the constraint "dependency:PackageCycles".
*
* @throws IOException
* If the test fails.
*/
@Test
public void packageCycles() throws Exception {
scanClassPathDirectory(getClassesDirectory(A.class));
assertThat(validateConstraint("dependency:PackageCycles").getStatus(), equalTo(FAILURE));
store.beginTransaction();
Map<String, Result<Constraint>> constraintViolations = reportWriter.getConstraintResults();
Matcher<Iterable<? super Result<Constraint>>> matcher = hasItem(result(constraint("dependency:PackageCycles")));
assertThat(constraintViolations.values(), matcher);
Result<Constraint> result = constraintViolations.get("dependency:PackageCycles");
List<Map<String, Object>> rows = result.getRows();
assertThat(rows.size(), equalTo(2));
for (Map<String, Object> row : rows) {
PackageDescriptor p = (PackageDescriptor) row.get("Package");
assertThat(p.getFullQualifiedName(), anyOf(equalTo(A.class.getPackage().getName()), equalTo(B.class.getPackage().getName())));
}
store.commitTransaction();
}
Aggregations