use of org.drools.core.base.RuleNameMatchesAgendaFilter in project drools by kiegroup.
the class IncoherentPatternsTest method testIncoherentPatternsInSubRule.
@Test
public void testIncoherentPatternsInSubRule() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Patterns.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("PatternsTest.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Incoherent Patterns in rule possibility"));
Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
Set<String> rulesThatHadErrors = new HashSet<String>();
while (iter.hasNext()) {
Object o = iter.next();
if (o instanceof VerifierMessage) {
VerifierRule rule = (VerifierRule) ((VerifierMessage) o).getFaulty();
rulesThatHadErrors.add(rule.getName());
}
}
assertTrue(rulesThatHadErrors.remove("Incoherent patterns 1"));
assertTrue(rulesThatHadErrors.remove("Incoherent patterns 2"));
assertTrue(rulesThatHadErrors.remove("Incoherent patterns 7"));
if (!rulesThatHadErrors.isEmpty()) {
for (String string : rulesThatHadErrors) {
fail("Rule " + string + " caused an error.");
}
}
}
use of org.drools.core.base.RuleNameMatchesAgendaFilter in project drools by kiegroup.
the class IncoherentPatternsTest method testIncoherentPatternsInSubRuleRangesLess.
@Test
public void testIncoherentPatternsInSubRuleRangesLess() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Patterns.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("PatternsTest.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Incoherent Patterns in rule possibility, ranges when not conflicts with lesser value"));
Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
Set<String> rulesThatHadErrors = new HashSet<String>();
while (iter.hasNext()) {
Object o = iter.next();
if (o instanceof VerifierMessage) {
VerifierRule rule = (VerifierRule) ((VerifierMessage) o).getFaulty();
rulesThatHadErrors.add(rule.getName());
}
}
assertTrue(rulesThatHadErrors.remove("Incoherent patterns 8"));
assertTrue(rulesThatHadErrors.remove("Incoherent patterns 12"));
if (!rulesThatHadErrors.isEmpty()) {
for (String string : rulesThatHadErrors) {
fail("Rule " + string + " caused an error.");
}
}
}
use of org.drools.core.base.RuleNameMatchesAgendaFilter in project drools by kiegroup.
the class IncoherentPatternsTest method testIncoherentPatternsInSubRuleRangesEqualOrUnequalVariables.
@Test
public void testIncoherentPatternsInSubRuleRangesEqualOrUnequalVariables() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Patterns.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("PatternsTest.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Incoherent Patterns in rule possibility, ranges when not conflicts with equal or unequal variables"));
Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
Set<String> rulesThatHadErrors = new HashSet<String>();
while (iter.hasNext()) {
Object o = iter.next();
if (o instanceof VerifierMessage) {
VerifierRule rule = (VerifierRule) ((VerifierMessage) o).getFaulty();
rulesThatHadErrors.add(rule.getName());
}
}
assertTrue(rulesThatHadErrors.remove("Incoherent patterns 11"));
if (!rulesThatHadErrors.isEmpty()) {
for (String string : rulesThatHadErrors) {
fail("Rule " + string + " caused an error.");
}
}
}
use of org.drools.core.base.RuleNameMatchesAgendaFilter in project drools by kiegroup.
the class IncompatibilityRestrictionsTest method testLiteralRestrictionsIncompatibilityGreater.
@Test
public void testLiteralRestrictionsIncompatibilityGreater() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Restrictions.drl"));
Collection<Object> data = new ArrayList<Object>();
Pattern pattern1 = VerifierComponentMockFactory.createPattern1();
Pattern pattern2 = VerifierComponentMockFactory.createPattern2();
/*
* Working pair
*/
LiteralRestriction r1 = LiteralRestriction.createRestriction(pattern1, "10");
r1.setOperator(Operator.BuiltInOperator.GREATER.getOperator());
r1.setFieldPath("0");
r1.setOrderNumber(0);
LiteralRestriction r2 = LiteralRestriction.createRestriction(pattern1, "1");
r2.setOperator(Operator.BuiltInOperator.EQUAL.getOperator());
r2.setFieldPath("0");
r2.setOrderNumber(1);
/*
* Pair that doesn't work.
*/
LiteralRestriction r3 = LiteralRestriction.createRestriction(pattern2, "1");
r3.setOperator(Operator.BuiltInOperator.GREATER_OR_EQUAL.getOperator());
r3.setFieldPath("1");
r3.setOrderNumber(0);
LiteralRestriction r4 = LiteralRestriction.createRestriction(pattern2, "10");
r4.setOperator(Operator.BuiltInOperator.EQUAL.getOperator());
r4.setFieldPath("1");
r4.setOrderNumber(1);
data.add(r1);
data.add(r2);
data.add(r3);
data.add(r4);
for (Object o : data) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Incompatible LiteralRestrictions with ranges in pattern possibility, impossible equality greater"));
Map<Cause, Set<Cause>> map = createIncompatibilityMap(VerifierComponentType.RESTRICTION, (Iterator<Object>) session.getObjects().iterator());
assertTrue((TestBaseOld.causeMapContains(map, r1, r2) ^ TestBaseOld.causeMapContains(map, r2, r1)));
if (!map.isEmpty()) {
fail("More incompatibilities than was expected.");
}
}
use of org.drools.core.base.RuleNameMatchesAgendaFilter in project drools by kiegroup.
the class IncompatibilityRestrictionsTest method testLiteralRestrictionsIncompatibilityImpossibleRange.
@Test
public void testLiteralRestrictionsIncompatibilityImpossibleRange() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Restrictions.drl"));
Collection<Object> data = new ArrayList<Object>();
Pattern pattern1 = VerifierComponentMockFactory.createPattern1();
Pattern pattern2 = VerifierComponentMockFactory.createPattern2();
/*
* Working pair
*/
LiteralRestriction r1 = LiteralRestriction.createRestriction(pattern1, "10");
r1.setOperator(Operator.BuiltInOperator.GREATER.getOperator());
r1.setFieldPath("0");
r1.setOrderNumber(0);
LiteralRestriction r2 = LiteralRestriction.createRestriction(pattern1, "10");
r2.setOperator(Operator.BuiltInOperator.LESS.getOperator());
r2.setFieldPath("0");
r2.setOrderNumber(1);
/*
* Pair that doesn't work.
*/
LiteralRestriction r3 = LiteralRestriction.createRestriction(pattern2, "1");
r3.setOperator(Operator.BuiltInOperator.GREATER_OR_EQUAL.getOperator());
r3.setFieldPath("1");
r3.setOrderNumber(0);
LiteralRestriction r4 = LiteralRestriction.createRestriction(pattern2, "");
r4.setOperator(Operator.BuiltInOperator.EQUAL.getOperator());
r4.setFieldPath("1");
r4.setOrderNumber(1);
data.add(r1);
data.add(r2);
data.add(r3);
data.add(r4);
for (Object o : data) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Incompatible LiteralRestrictions with ranges in pattern possibility, impossible range"));
Map<Cause, Set<Cause>> map = createIncompatibilityMap(VerifierComponentType.RESTRICTION, (Iterator<Object>) session.getObjects().iterator());
assertTrue((TestBaseOld.causeMapContains(map, r1, r2) ^ TestBaseOld.causeMapContains(map, r2, r1)));
if (!map.isEmpty()) {
fail("More incompatibilities than was expected.");
}
}
Aggregations