Search in sources :

Example 6 with Constraint

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

the class TransactionalVisitorTest method skipConstraint.

@Test
void skipConstraint() throws RuleException {
    Constraint constraint = mock(Constraint.class);
    visitor.skipConstraint(constraint, MAJOR);
    verify(delegate).skipConstraint(constraint, MAJOR);
    verifySuccessfulTransaction();
}
Also used : Constraint(com.buschmais.jqassistant.core.rule.api.model.Constraint) Test(org.junit.jupiter.api.Test)

Example 7 with Constraint

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

the class TransactionalVisitorTest method runtimeException.

@Test
void runtimeException() throws RuleException {
    Constraint constraint = mock(Constraint.class);
    doThrow(new NullPointerException()).when(delegate).visitConstraint(constraint, MAJOR);
    try {
        visitor.visitConstraint(constraint, MAJOR);
        fail("Expecting a " + XOException.class);
    } catch (RuleException e) {
        verify(delegate).visitConstraint(constraint, MAJOR);
        verifyFailedTransaction();
    }
}
Also used : XOException(com.buschmais.xo.api.XOException) Constraint(com.buschmais.jqassistant.core.rule.api.model.Constraint) RuleException(com.buschmais.jqassistant.core.rule.api.model.RuleException) Test(org.junit.jupiter.api.Test)

Example 8 with Constraint

use of com.buschmais.jqassistant.core.rule.api.model.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
void packageCycles() throws Exception {
    scanClassPathDirectory(getClassesDirectory(A.class));
    assertThat(validateConstraint("dependency:PackageCycles").getStatus(), equalTo(FAILURE));
    store.beginTransaction();
    Map<String, Result<Constraint>> constraintViolations = reportPlugin.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.rule.api.model.Constraint) PackageDescriptor(com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor) Result(com.buschmais.jqassistant.core.report.api.model.Result) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 9 with Constraint

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

the class CompositeReportPluginTest method noSelection.

@Test
void noSelection() throws ReportException {
    Concept concept = getRule(Concept.class);
    Constraint constraint = getRule(Constraint.class);
    write(concept, constraint);
    verifyInvoked(concept, reportPlugin1, reportPlugin2);
    verifyNotInvoked(concept, reportPlugin3, selectableReportPlugin1, selectableReportPlugin2);
    verifyInvoked(constraint, reportPlugin1, reportPlugin2);
    verifyNotInvoked(constraint, reportPlugin3, selectableReportPlugin1, selectableReportPlugin2);
    verifyGroup();
}
Also used : Concept(com.buschmais.jqassistant.core.rule.api.model.Concept) Constraint(com.buschmais.jqassistant.core.rule.api.model.Constraint) Test(org.junit.jupiter.api.Test)

Example 10 with Constraint

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

the class ReportHelperTest method failedConstraintsWithOverriddenSeverity.

@Test
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, 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, 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, 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.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)

Aggregations

Constraint (com.buschmais.jqassistant.core.rule.api.model.Constraint)12 Test (org.junit.jupiter.api.Test)11 Result (com.buschmais.jqassistant.core.report.api.model.Result)4 Concept (com.buschmais.jqassistant.core.rule.api.model.Concept)3 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 RuleException (com.buschmais.jqassistant.core.rule.api.model.RuleException)2 CompositeObject (com.buschmais.xo.api.CompositeObject)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CypherExecutable (com.buschmais.jqassistant.core.rule.api.model.CypherExecutable)1 Group (com.buschmais.jqassistant.core.rule.api.model.Group)1 Severity (com.buschmais.jqassistant.core.rule.api.model.Severity)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 XOException (com.buschmais.xo.api.XOException)1 ArrayList (java.util.ArrayList)1