use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.
the class RestrictionOrderTest method testRestrictionOrderInsideOperator.
@Test
public void testRestrictionOrderInsideOperator() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("RestrictionOrder.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("OptimisationRestrictionOrderTest.drl"), result.getVerifierData());
// for ( Object object : testData ) {
// if ( object instanceof SubPattern ) {
// SubPattern s = (SubPattern) object;
// System.out.println( " - " + s );
// for ( PatternComponent o : s.getItems() ) {
// System.out.println( " -- " + o + " : " + o.getOrderNumber() );
// }
// }
// }
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Optimise restrictions inside operator"));
Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.NOTE).iterator();
Collection<String> ruleNames = new ArrayList<String>();
while (iter.hasNext()) {
Object o = (Object) iter.next();
if (o instanceof VerifierMessage) {
String name = ((VerifierMessage) o).getCauses().toArray(new Restriction[2])[0].getRuleName();
ruleNames.add(name);
}
}
assertTrue(ruleNames.remove("Wrong descr order 1"));
if (!ruleNames.isEmpty()) {
for (String string : ruleNames) {
fail("Rule " + string + " caused an error.");
}
}
}
use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.
the class NotesTest method testRedundantRestrictionsInPatternPossibilities.
@Test
public void testRedundantRestrictionsInPatternPossibilities() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Notes.drl"));
Pattern pattern = VerifierComponentMockFactory.createPattern1();
Collection<Object> objects = new ArrayList<Object>();
LiteralRestriction left = LiteralRestriction.createRestriction(pattern, "");
LiteralRestriction right = LiteralRestriction.createRestriction(pattern, "");
Redundancy redundancy = new Redundancy(left, right);
SubPattern possibility = new SubPattern(pattern, 0);
possibility.add(left);
possibility.add(right);
objects.add(left);
objects.add(right);
objects.add(redundancy);
objects.add(possibility);
VerifierReport result = VerifierReportFactory.newVerifierReport();
session.setGlobal("result", result);
for (Object o : objects) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Find redundant restrictions from pattern possibilities"));
Collection<VerifierMessageBase> notes = result.getBySeverity(Severity.NOTE);
// Has at least one item.
assertEquals(1, notes.size());
VerifierMessageBase note = notes.iterator().next();
Iterator<Cause> causes = note.getCauses().iterator();
assertEquals(left, causes.next());
assertEquals(right, causes.next());
}
use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.
the class NotesTest method testRedundantPatternPossibilitiesInRulePossibilities.
@Test
public void testRedundantPatternPossibilitiesInRulePossibilities() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Notes.drl"));
VerifierRule rule = VerifierComponentMockFactory.createRule1();
Pattern pattern = VerifierComponentMockFactory.createPattern1();
Collection<Object> objects = new ArrayList<Object>();
SubPattern left = new SubPattern(pattern, 0);
SubPattern right = new SubPattern(pattern, 1);
Redundancy redundancy = new Redundancy(left, right);
SubRule possibility = new SubRule(rule, 0);
possibility.add(left);
possibility.add(right);
objects.add(left);
objects.add(right);
objects.add(redundancy);
objects.add(possibility);
VerifierReport result = VerifierReportFactory.newVerifierReport();
session.setGlobal("result", result);
for (Object o : objects) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Find redundant pattern possibilities from rule possibilities"));
Collection<VerifierMessageBase> notes = result.getBySeverity(Severity.NOTE);
// Has at least one item.
assertEquals(1, notes.size());
VerifierMessageBase note = notes.iterator().next();
Iterator<Cause> causes = note.getCauses().iterator();
assertEquals(left, causes.next());
assertEquals(right, causes.next());
}
use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.
the class RangeCheckTest method testVerifier.
@Test
public void testVerifier() {
VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
// Check that the builder works.
assertFalse(vBuilder.hasErrors());
assertEquals(0, vBuilder.getErrors().size());
Verifier verifier = vBuilder.newVerifier();
verifier.addResourcesToVerify(new ClassPathResource("RangeTest.drl", Verifier.class), ResourceType.DRL);
assertFalse(verifier.hasErrors());
assertEquals(0, verifier.getErrors().size());
boolean works = verifier.fireAnalysis();
assertTrue(works);
VerifierReport result = verifier.getResult();
assertNotNull(result);
for (VerifierMessageBase message : result.getBySeverity(Severity.ERROR)) {
System.out.println(message);
}
// This rule should not have errors, evereververevernever!
assertEquals(0, result.getBySeverity(Severity.ERROR).size());
}
use of org.drools.verifier.report.components.VerifierMessageBase in project drools by kiegroup.
the class VerifierTest method testCustomRule.
@Test
public void testCustomRule() {
VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
VerifierConfiguration vConfiguration = vBuilder.newVerifierConfiguration();
// Check that the builder works.
assertFalse(vBuilder.hasErrors());
assertEquals(0, vBuilder.getErrors().size());
vConfiguration.getVerifyingResources().put(new ClassPathResource("FindPatterns.drl", Verifier.class), ResourceType.DRL);
Verifier verifier = vBuilder.newVerifier(vConfiguration);
verifier.addResourcesToVerify(new ClassPathResource("Misc3.drl", Verifier.class), ResourceType.DRL);
assertFalse(verifier.hasErrors());
assertEquals(0, verifier.getErrors().size());
boolean works = verifier.fireAnalysis();
if (!works) {
for (VerifierError error : verifier.getErrors()) {
System.out.println(error.getMessage());
}
fail("Could not run verifier");
}
assertTrue(works);
VerifierReport result = verifier.getResult();
assertNotNull(result);
assertEquals(0, result.getBySeverity(Severity.ERROR).size());
assertEquals(0, result.getBySeverity(Severity.WARNING).size());
assertEquals(6, result.getBySeverity(Severity.NOTE).size());
for (VerifierMessageBase m : result.getBySeverity(Severity.NOTE)) {
assertEquals("This pattern was found.", m.getMessage());
}
}
Aggregations