use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.
the class MissingEqualityTest method testMissingEqualityInVariableRestrictions3.
@Test
public void testMissingEqualityInVariableRestrictions3() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("MissingEquality.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingEqualityTest.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Missing restriction in VariableRestrictions, custom operator"));
Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
Set<String> ruleNames = new HashSet<String>();
while (iter.hasNext()) {
Object o = (Object) iter.next();
if (o instanceof VerifierMessage) {
Cause cause = ((VerifierMessage) o).getFaulty();
String name = ((VariableRestriction) cause).getRuleName();
ruleNames.add(name);
}
}
assertTrue(ruleNames.remove("Missing equality 3"));
assertTrue(ruleNames.remove("Missing equality 4"));
assertTrue(ruleNames.remove("Missing equality 6"));
if (!ruleNames.isEmpty()) {
for (String string : ruleNames) {
fail("Rule " + string + " caused an error.");
}
}
}
use of org.drools.verifier.data.VerifierReport in project drools by kiegroup.
the class PatternOrderTest method testEvalOrderInsideOperator.
@Test
public void testEvalOrderInsideOperator() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("PatternOrder.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("OptimisationPatternOrderTest.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Optimise evals inside pattern"));
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 RuleComponent[2])[0].getRuleName();
ruleNames.add(name);
}
}
assertTrue(ruleNames.remove("Wrong eval order 1"));
if (!ruleNames.isEmpty()) {
for (String string : ruleNames) {
fail("Rule " + string + " caused an error.");
}
}
}
use of org.drools.verifier.data.VerifierReport 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.data.VerifierReport 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.data.VerifierReport 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());
}
Aggregations