use of org.drools.verifier.report.components.Incompatibility in project drools by kiegroup.
the class IncompatibilityBase method createIncompatibilityMap.
/**
* Creates incompatibility map from Incompatibility objects, one rule may
* have several incompatibility dependencies.
*
* @param iter
* @return
*/
protected Map<Cause, Set<Cause>> createIncompatibilityMap(VerifierComponentType type, Iterator<Object> iter) {
Map<Cause, Set<Cause>> map = new HashMap<Cause, Set<Cause>>();
while (iter.hasNext()) {
Object o = (Object) iter.next();
if (o instanceof Incompatibility) {
Incompatibility r = (Incompatibility) o;
if (((VerifierComponent) r.getLeft()).getVerifierComponentType().equals(type)) {
Cause left = r.getLeft();
Cause right = r.getRight();
if (map.containsKey(left)) {
Set<Cause> set = map.get(left);
set.add(right);
} else {
Set<Cause> set = new HashSet<Cause>();
set.add(right);
map.put(left, set);
}
}
}
}
return map;
}
use of org.drools.verifier.report.components.Incompatibility in project drools by kiegroup.
the class IncompatibilityPatternsTest method testPatternsPossibilitiesIncompatibility.
@Test
public void testPatternsPossibilitiesIncompatibility() throws Exception {
KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Patterns.drl"));
Collection<Object> data = new ArrayList<Object>();
Pattern pattern1 = VerifierComponentMockFactory.createPattern1();
Pattern pattern2 = VerifierComponentMockFactory.createPattern2();
/*
* Working pair
*/
SubPattern pp1 = new SubPattern(pattern1, 0);
SubPattern pp2 = new SubPattern(pattern2, 0);
Restriction r1 = LiteralRestriction.createRestriction(pattern1, "");
pp1.add(r1);
Restriction r2 = LiteralRestriction.createRestriction(pattern2, "");
pp2.add(r2);
Restriction r3 = LiteralRestriction.createRestriction(pattern1, "");
pp1.add(r3);
Restriction r4 = LiteralRestriction.createRestriction(pattern2, "");
pp2.add(r4);
Incompatibility o1 = new Incompatibility(r1, r2);
Incompatibility o2 = new Incompatibility(r3, r4);
Pattern pattern3 = VerifierComponentMockFactory.createPattern(3);
Pattern pattern4 = VerifierComponentMockFactory.createPattern(4);
/*
* Another working pair.
*/
SubPattern pp3 = new SubPattern(pattern3, 0);
SubPattern pp4 = new SubPattern(pattern4, 0);
Restriction r5 = LiteralRestriction.createRestriction(pattern3, "");
pp3.add(r5);
Restriction r6 = LiteralRestriction.createRestriction(pattern4, "");
pp4.add(r6);
Restriction r7 = LiteralRestriction.createRestriction(pattern3, "");
pp3.add(r7);
Restriction r8 = LiteralRestriction.createRestriction(pattern4, "");
pp4.add(r8);
Incompatibility o3 = new Incompatibility(r5, r6);
data.add(r1);
data.add(r2);
data.add(r3);
data.add(r4);
data.add(r5);
data.add(r6);
data.add(r7);
data.add(r8);
data.add(pp1);
data.add(pp2);
data.add(pp3);
data.add(pp4);
data.add(o1);
data.add(o2);
data.add(o3);
for (Object o : data) {
session.insert(o);
}
session.fireAllRules(new RuleNameMatchesAgendaFilter("Incompatible Patterns"));
Map<Cause, Set<Cause>> map = createIncompatibilityMap(VerifierComponentType.SUB_PATTERN, (Iterator<Object>) session.getObjects().iterator());
assertTrue((TestBaseOld.causeMapContains(map, pp1, pp2) ^ TestBaseOld.causeMapContains(map, pp2, pp1)));
assertTrue((TestBaseOld.causeMapContains(map, pp3, pp4) ^ TestBaseOld.causeMapContains(map, pp4, pp3)));
if (!map.isEmpty()) {
fail("More opposites than was expected.");
}
}
Aggregations