Search in sources :

Example 1 with Result

use of com.buschmais.jqassistant.core.report.api.model.Result in project jqa-core-framework by buschmais.

the class ReportHelperTest method validatedConstraint.

@Test
void validatedConstraint() {
    Result<Constraint> constraintResult = mockResult("test:concept", Constraint.class, Result.Status.SUCCESS, Severity.MAJOR);
    Map<String, Result<Constraint>> constraintResults = new HashMap<>();
    constraintResults.put("test:concept", constraintResult);
    when(inMemoryReportWriter.getConstraintResults()).thenReturn(constraintResults);
    int violations = reportHelper.verifyConstraintResults(Severity.MINOR, Severity.MINOR, inMemoryReportWriter);
    assertThat(violations, equalTo(0));
    assertThat(warnMessages.size(), equalTo(0));
    assertThat(debugMessages.size(), equalTo(0));
    assertThat(errorMessages.size(), equalTo(0));
}
Also used : Constraint(com.buschmais.jqassistant.core.rule.api.model.Constraint) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Constraint(com.buschmais.jqassistant.core.rule.api.model.Constraint) Result(com.buschmais.jqassistant.core.report.api.model.Result) Test(org.junit.jupiter.api.Test)

Example 2 with Result

use of com.buschmais.jqassistant.core.report.api.model.Result in project jqa-core-framework by buschmais.

the class ReportHelperTest method failedConceptsWithOverriddenSeverity.

@Test
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.rule.api.model.Concept) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Constraint(com.buschmais.jqassistant.core.rule.api.model.Constraint) Result(com.buschmais.jqassistant.core.report.api.model.Result) Test(org.junit.jupiter.api.Test)

Example 3 with Result

use of com.buschmais.jqassistant.core.report.api.model.Result in project jqa-core-framework by buschmais.

the class ReportHelperTest method failedConstraints.

@Test
void failedConstraints() {
    Map<String, Object> infoRow = new HashMap<>();
    infoRow.put("InfoElement", "InfoValue");
    Result<Constraint> infoConstraintResult = mockResult("test:infoConstraint", Constraint.class, Result.Status.FAILURE, Severity.INFO, singletonList(infoRow));
    Map<String, Object> minorRow = new HashMap<>();
    minorRow.put("MinorElement", "MinorValue");
    Result<Constraint> minorConstraintResult = mockResult("test:minorConstraint", Constraint.class, Result.Status.FAILURE, Severity.MINOR, singletonList(minorRow));
    Map<String, Object> majorRow = new HashMap<>();
    majorRow.put("MajorElement", "MajorValue");
    Result<Constraint> majorConstraintResult = mockResult("test:majorConstraint", Constraint.class, Result.Status.FAILURE, Severity.MAJOR, singletonList(majorRow));
    Map<String, Result<Constraint>> constraintResults = new HashMap<>();
    constraintResults.put("test:infoConstraint", infoConstraintResult);
    constraintResults.put("test:minorConstraint", minorConstraintResult);
    constraintResults.put("test:majorConstraint", majorConstraintResult);
    when(inMemoryReportWriter.getConstraintResults()).thenReturn(constraintResults);
    int violations = reportHelper.verifyConstraintResults(Severity.MINOR, Severity.MAJOR, inMemoryReportWriter);
    assertThat(violations, equalTo(1));
    verifyMessages(debugMessages, ReportHelper.CONSTRAINT_VIOLATION_HEADER, "Constraint: test:infoConstraint", "Severity: INFO", "InfoElement=InfoValue");
    verifyMessages(warnMessages, ReportHelper.CONSTRAINT_VIOLATION_HEADER, "Constraint: test:minorConstraint", "Severity: MINOR", "MinorElement=MinorValue");
    verifyMessages(errorMessages, ReportHelper.CONSTRAINT_VIOLATION_HEADER, "Constraint: test:majorConstraint", "Severity: MAJOR", "MajorElement=MajorValue");
}
Also used : Constraint(com.buschmais.jqassistant.core.rule.api.model.Constraint) CompositeObject(com.buschmais.xo.api.CompositeObject) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Constraint(com.buschmais.jqassistant.core.rule.api.model.Constraint) Result(com.buschmais.jqassistant.core.report.api.model.Result) Test(org.junit.jupiter.api.Test)

Example 4 with Result

use of com.buschmais.jqassistant.core.report.api.model.Result in project jqa-core-framework by buschmais.

the class ReportHelperTest method successfulConcept.

@Test
void successfulConcept() {
    Result<Concept> conceptResult = mockResult("test:concept", Concept.class, Result.Status.SUCCESS, Severity.MAJOR);
    Map<String, Result<Concept>> conceptResults = new HashMap<>();
    conceptResults.put("test:concept", conceptResult);
    when(inMemoryReportWriter.getConceptResults()).thenReturn(conceptResults);
    int violations = reportHelper.verifyConceptResults(Severity.MINOR, Severity.MAJOR, inMemoryReportWriter);
    assertThat(violations, equalTo(0));
    assertThat(warnMessages.size(), equalTo(0));
    assertThat(debugMessages.size(), equalTo(0));
    assertThat(errorMessages.size(), equalTo(0));
}
Also used : Concept(com.buschmais.jqassistant.core.rule.api.model.Concept) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Constraint(com.buschmais.jqassistant.core.rule.api.model.Constraint) Result(com.buschmais.jqassistant.core.report.api.model.Result) Test(org.junit.jupiter.api.Test)

Example 5 with Result

use of com.buschmais.jqassistant.core.report.api.model.Result in project jqa-core-framework by buschmais.

the class AnalyzerRuleVisitor method visitConcept.

@Override
public boolean visitConcept(Concept concept, Severity effectiveSeverity) throws RuleException {
    ConceptDescriptor conceptDescriptor = analyzerContext.getStore().find(ConceptDescriptor.class, concept.getId());
    Result.Status status;
    if (conceptDescriptor == null || configuration.isExecuteAppliedConcepts()) {
        analyzerContext.getLogger().info("Applying concept '" + concept.getId() + "' with severity: '" + concept.getSeverity().getInfo(effectiveSeverity) + "'" + ".");
        reportPlugin.beginConcept(concept);
        Result<Concept> result = execute(concept, effectiveSeverity);
        reportPlugin.setResult(result);
        status = result.getStatus();
        if (conceptDescriptor == null) {
            conceptDescriptor = analyzerContext.getStore().create(ConceptDescriptor.class);
            conceptDescriptor.setId(concept.getId());
            conceptDescriptor.setStatus(status);
        }
        reportPlugin.endConcept();
    } else {
        status = conceptDescriptor.getStatus();
    }
    return Result.Status.SUCCESS.equals(status);
}
Also used : Concept(com.buschmais.jqassistant.core.rule.api.model.Concept) ConceptDescriptor(com.buschmais.jqassistant.core.analysis.api.model.ConceptDescriptor) Result(com.buschmais.jqassistant.core.report.api.model.Result)

Aggregations

Result (com.buschmais.jqassistant.core.report.api.model.Result)16 Test (org.junit.jupiter.api.Test)12 Constraint (com.buschmais.jqassistant.core.rule.api.model.Constraint)7 StringContains.containsString (org.hamcrest.core.StringContains.containsString)6 Concept (com.buschmais.jqassistant.core.rule.api.model.Concept)4 RuleException (com.buschmais.jqassistant.core.rule.api.model.RuleException)3 Map (java.util.Map)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Matchers.anyMap (org.mockito.Matchers.anyMap)3 CompositeObject (com.buschmais.xo.api.CompositeObject)2 ConceptDescriptor (com.buschmais.jqassistant.core.analysis.api.model.ConceptDescriptor)1 Status (com.buschmais.jqassistant.core.report.api.model.Result.Status)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 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 ScriptEngine (javax.script.ScriptEngine)1