use of org.drools.core.base.RuleNameMatchesAgendaFilter in project drools by kiegroup.
the class OppositeRestrictionsTest method testLiteralRestrictionOpposite.
@Test
public void testLiteralRestrictionOpposite() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Restrictions.drl"));
Collection<Object> data = new ArrayList<Object>();
Pattern pattern = VerifierComponentMockFactory.createPattern1();
LiteralRestriction r1 = LiteralRestriction.createRestriction(pattern, "1");
r1.setFieldPath("0");
r1.setOperator(Operator.BuiltInOperator.EQUAL.getOperator());
r1.setOrderNumber(0);
LiteralRestriction r2 = LiteralRestriction.createRestriction(pattern, "1");
r2.setFieldPath("0");
r2.setOperator(Operator.BuiltInOperator.NOT_EQUAL.getOperator());
r2.setOrderNumber(1);
LiteralRestriction r3 = LiteralRestriction.createRestriction(pattern, "1.0");
r3.setFieldPath("0");
r3.setOperator(Operator.BuiltInOperator.EQUAL.getOperator());
r3.setOrderNumber(2);
LiteralRestriction r4 = LiteralRestriction.createRestriction(pattern, "1.0");
r4.setFieldPath("0");
r4.setOperator(Operator.BuiltInOperator.NOT_EQUAL.getOperator());
r4.setOrderNumber(3);
data.add(r1);
data.add(r2);
data.add(r3);
data.add(r4);
for (Object o : data) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Opposite LiteralRestrictions"));
Map<Cause, Set<Cause>> map = createOppositesMap(VerifierComponentType.RESTRICTION, (Iterator<Object>) session.getObjects().iterator());
assertTrue((TestBaseOld.causeMapContains(map, r1, r2) ^ TestBaseOld.causeMapContains(map, r2, r1)));
assertTrue((TestBaseOld.causeMapContains(map, r3, r4) ^ TestBaseOld.causeMapContains(map, r4, r3)));
if (!map.isEmpty()) {
fail("More opposites than was expected.");
}
}
use of org.drools.core.base.RuleNameMatchesAgendaFilter in project drools by kiegroup.
the class OppositeRestrictionsTest method testLiteralRestrictionOppositeWithRangesLessOrEqualAndGreaterOrEqualForIntsAndDates.
@Test
public void testLiteralRestrictionOppositeWithRangesLessOrEqualAndGreaterOrEqualForIntsAndDates() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Restrictions.drl"));
Collection<Object> data = new ArrayList<Object>();
Pattern pattern = VerifierComponentMockFactory.createPattern1();
LiteralRestriction r1 = LiteralRestriction.createRestriction(pattern, "1");
r1.setFieldPath("0");
r1.setOperator(Operator.BuiltInOperator.GREATER_OR_EQUAL.getOperator());
r1.setOrderNumber(0);
LiteralRestriction r2 = LiteralRestriction.createRestriction(pattern, "0");
r2.setFieldPath("0");
r2.setOperator(Operator.BuiltInOperator.LESS_OR_EQUAL.getOperator());
r2.setOrderNumber(1);
data.add(r1);
data.add(r2);
for (Object o : data) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Opposite LiteralRestrictions with ranges, less or equal - greater or equal for ints and dates"));
Map<Cause, Set<Cause>> map = createOppositesMap(VerifierComponentType.RESTRICTION, (Iterator<Object>) session.getObjects().iterator());
assertTrue((TestBaseOld.causeMapContains(map, r1, r2) ^ TestBaseOld.causeMapContains(map, r2, r1)));
if (!map.isEmpty()) {
fail("More opposites than was expected.");
}
}
use of org.drools.core.base.RuleNameMatchesAgendaFilter 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.core.base.RuleNameMatchesAgendaFilter in project drools by kiegroup.
the class RangeCheckDatesTest method testEqualAndSmallerThan.
@Test
public void testEqualAndSmallerThan() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("rangeChecks/Dates.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingRangesForDates.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Range check for dates, equal and smaller than"));
Set<String> rulesThatHadErrors = new HashSet<String>();
for (Object o : session.getObjects()) {
if (o instanceof Gap) {
rulesThatHadErrors.add(((Gap) o).getRuleName());
}
// System.out.println(o);
}
assertTrue(rulesThatHadErrors.remove("Date gap rule 1"));
assertTrue(rulesThatHadErrors.remove("Date gap rule 6b"));
assertTrue(rulesThatHadErrors.remove("Date gap rule 2"));
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 RangeCheckIntegersTest method testGreaterOrEqual.
@Test
public void testGreaterOrEqual() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("rangeChecks/Integers.drl"));
VerifierReport result = VerifierReportFactory.newVerifierReport();
Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingRangesForInts.drl"), result.getVerifierData());
session.setGlobal("result", result);
for (Object o : testData) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Range check for integers, if greater than or equal is missing"));
Set<String> rulesThatHadErrors = new HashSet<String>();
for (Object o : session.getObjects()) {
if (o instanceof Gap) {
rulesThatHadErrors.add(((Gap) o).getRuleName());
}
// System.out.println(o);
}
assertTrue(rulesThatHadErrors.remove("Integer gap rule 4b"));
assertTrue(rulesThatHadErrors.remove("Integer gap rule 5b"));
if (!rulesThatHadErrors.isEmpty()) {
for (String string : rulesThatHadErrors) {
fail("Rule " + string + " caused an error.");
}
}
}
Aggregations