use of org.drools.core.base.RuleNameMatchesAgendaFilter in project drools by kiegroup.
the class IncompatibilityRestrictionsTest method testLiteralRestrictionsIncompatibilityLessOrEqual.
@Test
public void testLiteralRestrictionsIncompatibilityLessOrEqual() 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.EQUAL.getOperator());
r1.setFieldPath("0");
r1.setOrderNumber(0);
LiteralRestriction r2 = LiteralRestriction.createRestriction(pattern1, "1");
r2.setOperator(Operator.BuiltInOperator.LESS.getOperator());
r2.setFieldPath("0");
r2.setOrderNumber(2);
/*
* 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 less or equal"));
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 testVariableRestrictionsIncompatibilityImpossibleRange.
@Test
public void testVariableRestrictionsIncompatibilityImpossibleRange() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Restrictions.drl"));
Collection<Object> data = new ArrayList<Object>();
VerifierRule rule = VerifierComponentMockFactory.createRule1();
ObjectType objectType = new ObjectType(new PackageDescr("testPackage1"));
objectType.setFullName("org.test.Person");
Pattern pattern1 = VerifierComponentMockFactory.createPattern1();
Pattern pattern2 = VerifierComponentMockFactory.createPattern2();
/*
* Working pair
*/
PatternVariable variable1 = new PatternVariable(rule);
variable1.setParentPath("0");
variable1.setParentType(VerifierComponentType.FIELD);
variable1.setOrderNumber(11);
VariableRestriction r1 = new VariableRestriction(pattern1);
r1.setOperator(Operator.BuiltInOperator.GREATER.getOperator());
r1.setFieldPath("0");
r1.setVariable(variable1);
r1.setOrderNumber(0);
VariableRestriction r2 = new VariableRestriction(pattern1);
r2.setOperator(Operator.BuiltInOperator.LESS.getOperator());
r2.setFieldPath("0");
r2.setVariable(variable1);
r2.setOrderNumber(1);
/*
* Pair that doesn't work.
*/
PatternVariable variable2 = new PatternVariable(rule);
variable2.setParentPath("1");
variable2.setParentType(VerifierComponentType.FIELD);
variable2.setOrderNumber(10);
VariableRestriction r3 = new VariableRestriction(pattern2);
r3.setOperator(Operator.BuiltInOperator.GREATER_OR_EQUAL.getOperator());
r3.setFieldPath("1");
r3.setVariable(variable2);
r3.setOrderNumber(0);
VariableRestriction r4 = new VariableRestriction(pattern2);
r4.setOperator(Operator.BuiltInOperator.EQUAL.getOperator());
r4.setFieldPath("1");
r4.setVariable(variable2);
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("Incoherent VariableRestrictions 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.");
}
}
use of org.drools.core.base.RuleNameMatchesAgendaFilter in project drools by kiegroup.
the class MissingEqualityTest method testMissingEqualityInVariableRestrictions.
@Test
public void testMissingEqualityInVariableRestrictions() 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, equal 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 5"));
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 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.core.base.RuleNameMatchesAgendaFilter in project drools by kiegroup.
the class OppositeRestrictionsTest method testLiteralRestrictionOppositeWithRangesGreaterAndLessOrEqual.
@Test
public void testLiteralRestrictionOppositeWithRangesGreaterAndLessOrEqual() 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.getOperator());
r1.setOrderNumber(0);
LiteralRestriction r2 = LiteralRestriction.createRestriction(pattern, "1");
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, greater - less or equal"));
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.");
}
}
Aggregations