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) {
}
}
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();
}
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"));
}
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();
}
Aggregations