Search in sources :

Example 1 with FileRuleSource

use of com.buschmais.jqassistant.core.rule.api.source.FileRuleSource in project jqa-core-framework by buschmais.

the class RuleSetBuilderTest method duplicateRules.

@Test
public void duplicateRules() throws RuleException {
    RuleSource ruleSource = new FileRuleSource(new File("test.xml"));
    // Concepts
    Concept concept1 = Concept.Builder.newConcept().id("test").ruleSource(ruleSource).get();
    Concept concept2 = Concept.Builder.newConcept().id("test").ruleSource(ruleSource).get();
    RuleSetBuilder builder = RuleSetBuilder.newInstance();
    builder.addConcept(concept1);
    try {
        builder.addConcept(concept2);
        Assert.fail("Expecting an exception");
    } catch (RuleException e) {
    }
    // Constraints
    Constraint constraint1 = Constraint.Builder.newConstraint().id("test").ruleSource(ruleSource).get();
    Constraint constraint2 = Constraint.Builder.newConstraint().id("test").ruleSource(ruleSource).get();
    builder.addConstraint(constraint1);
    try {
        builder.addConstraint(constraint2);
        Assert.fail("Expecting an exception");
    } catch (RuleException e) {
    }
    // Groups
    Group group1 = Group.Builder.newGroup().id("test").ruleSource(ruleSource).get();
    Group group2 = Group.Builder.newGroup().id("test").ruleSource(ruleSource).get();
    builder.addGroup(group1);
    try {
        builder.addGroup(group2);
        Assert.fail("Expecting an exception");
    } catch (RuleException e) {
    }
}
Also used : RuleSource(com.buschmais.jqassistant.core.rule.api.source.RuleSource) FileRuleSource(com.buschmais.jqassistant.core.rule.api.source.FileRuleSource) FileRuleSource(com.buschmais.jqassistant.core.rule.api.source.FileRuleSource) File(java.io.File) Test(org.junit.Test)

Example 2 with FileRuleSource

use of com.buschmais.jqassistant.core.rule.api.source.FileRuleSource in project jqa-core-framework by buschmais.

the class AnalyzerVisitorTest method createConstraint.

private Constraint createConstraint(String statement) {
    Executable executable = new CypherExecutable(statement);
    Parameter parameterWithoutDefaultValue = new Parameter(PARAMETER_WITHOUT_DEFAULT, Parameter.Type.STRING, null);
    Parameter parameterWithDefaultValue = new Parameter(PARAMETER_WITH_DEFAULT, Parameter.Type.STRING, "defaultValue");
    Map<String, Parameter> parameters = new HashMap<>();
    parameters.put(parameterWithoutDefaultValue.getName(), parameterWithoutDefaultValue);
    parameters.put(parameterWithDefaultValue.getName(), parameterWithDefaultValue);
    Report report = Report.Builder.newInstance().primaryColumn("primaryColumn").get();
    return Constraint.Builder.newConstraint().id("test:Constraint").description("Test Constraint").ruleSource(new FileRuleSource(new File(RULESOURCE))).severity(Severity.MAJOR).executable(executable).parameters(parameters).verification(ROW_COUNT_VERIFICATION).report(report).get();
}
Also used : FileRuleSource(com.buschmais.jqassistant.core.rule.api.source.FileRuleSource) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File)

Example 3 with FileRuleSource

use of com.buschmais.jqassistant.core.rule.api.source.FileRuleSource in project jqa-core-framework by buschmais.

the class CompoundRuleSetReaderTest method testReadCompoundSources.

@Test
public void testReadCompoundSources() throws Exception {
    File adocFile = ClasspathResource.getFile("/junit-without-assert.adoc");
    File xmlFile = ClasspathResource.getFile("/test-concepts.xml");
    RuleSetBuilder ruleSetBuilder = RuleSetBuilder.newInstance();
    RuleSetReader reader = new CompoundRuleSetReader(RuleConfiguration.builder().build());
    reader.read(asList(new FileRuleSource(adocFile), new FileRuleSource(xmlFile)), ruleSetBuilder);
    RuleSet ruleSet = ruleSetBuilder.getRuleSet();
    assertThat(ruleSet.getConceptBucket().size(), equalTo(3));
    assertThat(ruleSet.getConstraintBucket().size(), equalTo(2));
    assertThat(ruleSet.getConceptBucket().getIds(), containsInAnyOrder("junit4:TestClassOrMethod", "junit4:AssertMethod", "java:Throwable"));
    assertThat(ruleSet.getConstraintBucket().getIds(), containsInAnyOrder("junit4:TestMethodWithoutAssertion", "example:ConstructorOfDateMustNotBeUsed"));
    assertThat(ruleSet.getGroupsBucket().size(), equalTo(1));
    Group group = ruleSet.getGroupsBucket().getById("default");
    assertThat(group.getId(), equalTo("default"));
    assertThat(group.getConcepts(), aMapWithSize(1));
    assertThat(group.getConcepts(), hasKey("java:Throwable"));
    assertThat(group.getConstraints().size(), equalTo(1));
    assertThat(group.getConstraints(), hasKey("example:ConstructorOfDateMustNotBeUsed"));
}
Also used : FileRuleSource(com.buschmais.jqassistant.core.rule.api.source.FileRuleSource) CompoundRuleSetReader(com.buschmais.jqassistant.core.rule.impl.reader.CompoundRuleSetReader) RuleSetReader(com.buschmais.jqassistant.core.rule.api.reader.RuleSetReader) XmlRuleSetReader(com.buschmais.jqassistant.core.rule.impl.reader.XmlRuleSetReader) File(java.io.File) CompoundRuleSetReader(com.buschmais.jqassistant.core.rule.impl.reader.CompoundRuleSetReader) Test(org.junit.Test)

Example 4 with FileRuleSource

use of com.buschmais.jqassistant.core.rule.api.source.FileRuleSource in project jqa-core-framework by buschmais.

the class AnalyzerVisitorTest method createConcept.

private Concept createConcept(String statement) {
    Executable executable = new CypherExecutable(statement);
    Parameter parameterWithoutDefaultValue = new Parameter(PARAMETER_WITHOUT_DEFAULT, Parameter.Type.STRING, null);
    Parameter parameterWithDefaultValue = new Parameter(PARAMETER_WITH_DEFAULT, Parameter.Type.STRING, "defaultValue");
    Map<String, Parameter> parameters = new HashMap<>();
    parameters.put(parameterWithoutDefaultValue.getName(), parameterWithoutDefaultValue);
    parameters.put(parameterWithDefaultValue.getName(), parameterWithDefaultValue);
    Report report = Report.Builder.newInstance().primaryColumn("primaryColumn").get();
    return Concept.Builder.newConcept().id("test:Concept").description("Test Concept").ruleSource(new FileRuleSource(new File(RULESOURCE))).severity(Severity.MINOR).executable(executable).parameters(parameters).verification(ROW_COUNT_VERIFICATION).report(report).get();
}
Also used : FileRuleSource(com.buschmais.jqassistant.core.rule.api.source.FileRuleSource) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File)

Aggregations

FileRuleSource (com.buschmais.jqassistant.core.rule.api.source.FileRuleSource)4 File (java.io.File)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Test (org.junit.Test)2 RuleSetReader (com.buschmais.jqassistant.core.rule.api.reader.RuleSetReader)1 RuleSource (com.buschmais.jqassistant.core.rule.api.source.RuleSource)1 CompoundRuleSetReader (com.buschmais.jqassistant.core.rule.impl.reader.CompoundRuleSetReader)1 XmlRuleSetReader (com.buschmais.jqassistant.core.rule.impl.reader.XmlRuleSetReader)1