use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-core-framework by buschmais.
the class ReportHelperTest method failedConceptsWithOverriddenSeverity.
@Test
public void failedConceptsWithOverriddenSeverity() {
Result<Concept> infoConceptResult = mockResult("test:infoConcept", Concept.class, Result.Status.FAILURE, Severity.INFO, Severity.MINOR);
Result<Concept> minorConceptResult = mockResult("test:minorConcept", Concept.class, Result.Status.FAILURE, Severity.MINOR, Severity.MAJOR);
Result<Concept> majorConceptResult = mockResult("test:majorConcept", Concept.class, Result.Status.FAILURE, Severity.MAJOR, Severity.CRITICAL);
Map<String, Result<Concept>> conceptResults = new HashMap<>();
conceptResults.put("test:infoConcept", infoConceptResult);
conceptResults.put("test:minorConcept", minorConceptResult);
conceptResults.put("test:majorConcept", majorConceptResult);
when(inMemoryReportWriter.getConceptResults()).thenReturn(conceptResults);
int violations = reportHelper.verifyConceptResults(Severity.MAJOR, Severity.CRITICAL, inMemoryReportWriter);
assertThat(violations, equalTo(1));
verifyMessages(debugMessages, ReportHelper.CONCEPT_FAILED_HEADER, "Concept: test:infoConcept", "Severity: MINOR (from INFO)");
verifyMessages(warnMessages, ReportHelper.CONCEPT_FAILED_HEADER, "Concept: test:minorConcept", "Severity: MAJOR (from MINOR)");
verifyMessages(errorMessages, ReportHelper.CONCEPT_FAILED_HEADER, "Concept: test:majorConcept", "Severity: CRITICAL (from MAJOR)");
}
use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-core-framework by buschmais.
the class AggregationVerificationStrategy method verify.
@Override
public <T extends ExecutableRule> Result.Status verify(T executable, AggregationVerification verification, List<String> columnNames, List<Map<String, Object>> rows) throws RuleExecutorException {
LOGGER.debug("Verifying result of " + executable);
if (rows.isEmpty()) {
return getStatus(executable, 0, verification.getMin(), verification.getMax());
}
if (columnNames.isEmpty()) {
throw new RuleExecutorException("Result contains no columns, at least one with a numeric value is expected.");
}
String column = verification.getColumn();
if (column == null) {
column = columnNames.get(0);
LOGGER.debug("No aggregation column specified, using " + column);
}
for (Map<String, Object> row : rows) {
Object value = row.get(column);
if (value == null) {
throw new RuleExecutorException("The result does not contain a column '" + column);
} else if (!Number.class.isAssignableFrom(value.getClass())) {
throw new RuleExecutorException("The value in column '" + column + "' must be a numeric value but was '" + value + "'");
}
int aggregationValue = ((Number) value).intValue();
Result.Status status = getStatus(executable, aggregationValue, verification.getMin(), verification.getMax());
if (Result.Status.FAILURE.equals(status)) {
return Result.Status.FAILURE;
}
}
return Result.Status.SUCCESS;
}
use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-core-framework by buschmais.
the class AnalyzerVisitorTest method skipConcept.
@Test
public void skipConcept() throws RuleException {
analyzerVisitor.skipConcept(concept, Severity.MAJOR);
verify(store, never()).executeQuery(Mockito.eq(statement), anyMap());
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.SKIPPED));
assertThat(result.getSeverity(), equalTo(Severity.MAJOR));
verify(reportWriter).endConcept();
verify(store, never()).create(ConceptDescriptor.class);
}
use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-core-framework by buschmais.
the class AnalyzerVisitorTest method executeConstraint.
@Test
public void executeConstraint() throws RuleException {
analyzerVisitor.visitConstraint(constraint, Severity.BLOCKER);
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).beginConstraint(constraint);
ArgumentCaptor<Result> resultCaptor = ArgumentCaptor.forClass(Result.class);
verify(reportWriter).setResult(resultCaptor.capture());
Result result = resultCaptor.getValue();
assertThat(result.getStatus(), equalTo(Result.Status.FAILURE));
assertThat(result.getSeverity(), equalTo(Severity.BLOCKER));
verify(reportWriter).endConstraint();
}
use of com.buschmais.jqassistant.core.analysis.api.Result in project jqa-core-framework by buschmais.
the class AnalyzerVisitorTest method skipConstraint.
@Test
public void skipConstraint() throws RuleException {
analyzerVisitor.skipConstraint(constraint, Severity.BLOCKER);
verify(store, never()).executeQuery(Mockito.eq(statement), anyMap());
verify(reportWriter).beginConstraint(constraint);
ArgumentCaptor<Result> resultCaptor = ArgumentCaptor.forClass(Result.class);
verify(reportWriter).setResult(resultCaptor.capture());
Result result = resultCaptor.getValue();
assertThat(result.getStatus(), equalTo(Result.Status.SKIPPED));
assertThat(result.getSeverity(), equalTo(Severity.BLOCKER));
verify(reportWriter).endConstraint();
}
Aggregations