Search in sources :

Example 6 with Result

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)");
}
Also used : Concept(com.buschmais.jqassistant.core.analysis.api.rule.Concept) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Constraint(com.buschmais.jqassistant.core.analysis.api.rule.Constraint) Result(com.buschmais.jqassistant.core.analysis.api.Result) Test(org.junit.Test)

Example 7 with Result

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;
}
Also used : RuleExecutorException(com.buschmais.jqassistant.core.rule.api.executor.RuleExecutorException) Result(com.buschmais.jqassistant.core.analysis.api.Result)

Example 8 with Result

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);
}
Also used : Result(com.buschmais.jqassistant.core.analysis.api.Result) Test(org.junit.Test)

Example 9 with Result

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();
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.anyMap(org.mockito.Matchers.anyMap) Result(com.buschmais.jqassistant.core.analysis.api.Result) Test(org.junit.Test)

Example 10 with Result

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();
}
Also used : Result(com.buschmais.jqassistant.core.analysis.api.Result) Test(org.junit.Test)

Aggregations

Result (com.buschmais.jqassistant.core.analysis.api.Result)19 Test (org.junit.Test)12 Constraint (com.buschmais.jqassistant.core.analysis.api.rule.Constraint)7 StringContains.containsString (org.hamcrest.core.StringContains.containsString)6 RuleExecutorException (com.buschmais.jqassistant.core.rule.api.executor.RuleExecutorException)4 Concept (com.buschmais.jqassistant.core.analysis.api.rule.Concept)3 XmlReportWriter (com.buschmais.jqassistant.core.report.impl.XmlReportWriter)3 StringWriter (java.io.StringWriter)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Matchers.anyMap (org.mockito.Matchers.anyMap)3 XOException (com.buschmais.xo.api.XOException)2 ScriptException (javax.script.ScriptException)2 ConceptDescriptor (com.buschmais.jqassistant.core.analysis.api.model.ConceptDescriptor)1 PackageDescriptor (com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor)1 A (com.buschmais.jqassistant.plugin.java.test.set.rules.dependency.packages.a.A)1 Query (com.buschmais.xo.api.Query)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ScriptEngine (javax.script.ScriptEngine)1 ScriptEngineFactory (javax.script.ScriptEngineFactory)1