Search in sources :

Example 1 with Constraint

use of com.buschmais.jqassistant.core.rule.api.model.Constraint 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 Constraint

use of com.buschmais.jqassistant.core.rule.api.model.Constraint 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 3 with Constraint

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

the class XmlReportTestHelper method createXmlReportWithConstraints.

/**
 * Creates a test report with {@link Constraint}.
 *
 * @return The test report.
 * @throws ReportException
 *             If the test fails.
 */
public File createXmlReportWithConstraints() throws ReportException {
    xmlReportWriter.begin();
    Constraint constraint = Constraint.builder().id("my:Constraint").description("My constraint description").severity(Severity.BLOCKER).executable(new CypherExecutable("match...")).verification(ROW_COUNT_VERIFICATION).report(Report.builder().build()).build();
    Map<String, Severity> constraints = new HashMap<>();
    constraints.put("my:Constraint", Severity.INFO);
    Group group = Group.builder().id("default").description("My group").constraints(constraints).build();
    xmlReportWriter.beginGroup(group);
    xmlReportWriter.beginConstraint(constraint);
    List<Map<String, Object>> rows = new ArrayList<>();
    rows.add(createRow());
    Result<Constraint> result = Result.<Constraint>builder().rule(constraint).status(Result.Status.FAILURE).severity(Severity.CRITICAL).columnNames(Arrays.asList(C1, C2)).rows(rows).build();
    xmlReportWriter.setResult(result);
    xmlReportWriter.endConstraint();
    xmlReportWriter.endGroup();
    xmlReportWriter.end();
    return xmlReportWriter.getXmlReportFile();
}
Also used : Group(com.buschmais.jqassistant.core.rule.api.model.Group) Constraint(com.buschmais.jqassistant.core.rule.api.model.Constraint) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Severity(com.buschmais.jqassistant.core.rule.api.model.Severity) CypherExecutable(com.buschmais.jqassistant.core.rule.api.model.CypherExecutable) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Constraint

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

the class CompositeReportPluginTest method selectMultiplePlugins.

@Test
void selectMultiplePlugins() throws ReportException {
    Concept concept = getRule(Concept.class, "selectablePlugin1", "selectablePlugin2");
    Constraint constraint = getRule(Constraint.class, "selectablePlugin1", "selectablePlugin2");
    write(concept, constraint);
    verifyInvoked(concept, reportPlugin1, reportPlugin2, selectableReportPlugin1, selectableReportPlugin2);
    verifyInvoked(constraint, reportPlugin1, reportPlugin2, selectableReportPlugin1, selectableReportPlugin2);
    verifyNotInvoked(concept, reportPlugin3);
    verifyNotInvoked(constraint, reportPlugin3);
    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 5 with Constraint

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

the class CompositeReportPluginTest method selectOneWriter.

@Test
void selectOneWriter() throws ReportException {
    Concept concept = getRule(Concept.class, "selectablePlugin1");
    Constraint constraint = getRule(Constraint.class, "selectablePlugin1");
    write(concept, constraint);
    verifyInvoked(concept, reportPlugin1, reportPlugin2, selectableReportPlugin1);
    verifyNotInvoked(concept, reportPlugin3, selectableReportPlugin2);
    verifyInvoked(constraint, reportPlugin1, reportPlugin2, selectableReportPlugin1);
    verifyNotInvoked(constraint, reportPlugin3, 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)

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