Search in sources :

Example 1 with Constraint

use of com.buschmais.jqassistant.core.analysis.api.rule.Constraint in project jqa-core-framework by buschmais.

the class ReportHelperTest method validatedConstraint.

@Test
public 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.analysis.api.rule.Constraint) 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 2 with Constraint

use of com.buschmais.jqassistant.core.analysis.api.rule.Constraint in project jqa-core-framework by buschmais.

the class ReportHelperTest method failedConstraints.

@Test
public 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, Collections.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, Collections.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, Collections.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.analysis.api.rule.Constraint) 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 3 with Constraint

use of com.buschmais.jqassistant.core.analysis.api.rule.Constraint in project jqa-core-framework by buschmais.

the class ReportHelperTest method failedConstraintsWithOverriddenSeverity.

@Test
public void failedConstraintsWithOverriddenSeverity() {
    Map<String, Object> infoRow = new HashMap<>();
    infoRow.put("InfoElement", "InfoValue");
    Result<Constraint> infoConstraintResult = mockResult("test:infoConstraint", Constraint.class, Result.Status.FAILURE, Severity.INFO, Severity.MINOR, Collections.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, Severity.MAJOR, Collections.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, Severity.CRITICAL, Collections.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.MAJOR, Severity.CRITICAL, inMemoryReportWriter);
    assertThat(violations, equalTo(1));
    verifyMessages(debugMessages, ReportHelper.CONSTRAINT_VIOLATION_HEADER, "Constraint: test:infoConstraint", "Severity: MINOR (from INFO)", "InfoElement=InfoValue");
    verifyMessages(warnMessages, ReportHelper.CONSTRAINT_VIOLATION_HEADER, "Constraint: test:minorConstraint", "Severity: MAJOR (from MINOR)", "MinorElement=MinorValue");
    verifyMessages(errorMessages, ReportHelper.CONSTRAINT_VIOLATION_HEADER, "Constraint: test:majorConstraint", "Severity: CRITICAL (from MAJOR)", "MajorElement=MajorValue");
}
Also used : Constraint(com.buschmais.jqassistant.core.analysis.api.rule.Constraint) 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 4 with Constraint

use of com.buschmais.jqassistant.core.analysis.api.rule.Constraint 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();
}
Also used : A(com.buschmais.jqassistant.plugin.java.test.set.rules.dependency.packages.a.A) Constraint(com.buschmais.jqassistant.core.analysis.api.rule.Constraint) PackageDescriptor(com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor) Result(com.buschmais.jqassistant.core.analysis.api.Result) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Result (com.buschmais.jqassistant.core.analysis.api.Result)4 Constraint (com.buschmais.jqassistant.core.analysis.api.rule.Constraint)4 Test (org.junit.Test)4 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 PackageDescriptor (com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor)1 A (com.buschmais.jqassistant.plugin.java.test.set.rules.dependency.packages.a.A)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1