use of org.drools.verifier.report.components.Cause 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.GREATER);
r1.setFieldPath("0");
r1.setVariable(variable1);
r1.setOrderNumber(0);
VariableRestriction r2 = new VariableRestriction(pattern1);
r2.setOperator(Operator.LESS);
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.GREATER_OR_EQUAL);
r3.setFieldPath("1");
r3.setVariable(variable2);
r3.setOrderNumber(0);
VariableRestriction r4 = new VariableRestriction(pattern2);
r4.setOperator(Operator.EQUAL);
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.");
}
}
Aggregations