Search in sources :

Example 6 with VerifierRule

use of org.drools.verifier.components.VerifierRule 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.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VerifierRule(org.drools.verifier.components.VerifierRule) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with VerifierRule

use of org.drools.verifier.components.VerifierRule 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.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VerifierRule(org.drools.verifier.components.VerifierRule) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with VerifierRule

use of org.drools.verifier.components.VerifierRule 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.");
        }
    }
}
Also used : RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VerifierRule(org.drools.verifier.components.VerifierRule) KieSession(org.kie.api.runtime.KieSession) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with VerifierRule

use of org.drools.verifier.components.VerifierRule in project drools by kiegroup.

the class SolversTest method testBasicAnd.

/**
 * <pre>
 * when
 *     Foo( descr &amp;&amp; descr2 )
 * </pre>
 *
 * result:<br>
 * descr && descr2
 */
@Test
public void testBasicAnd() {
    VerifierRule rule = VerifierComponentMockFactory.createRule1();
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    Restriction r = LiteralRestriction.createRestriction(pattern, "");
    Restriction r2 = LiteralRestriction.createRestriction(pattern, "");
    Solvers solvers = new Solvers();
    solvers.startRuleSolver(rule);
    solvers.startPatternSolver(pattern);
    solvers.startOperator(OperatorDescrType.AND);
    solvers.addPatternComponent(r);
    solvers.addPatternComponent(r2);
    solvers.endOperator();
    solvers.endPatternSolver();
    solvers.endRuleSolver();
    List<SubRule> list = solvers.getRulePossibilities();
    assertEquals(1, list.size());
    assertEquals(1, list.get(0).getItems().size());
    List<Restriction> result = new ArrayList<Restriction>();
    result.add(r);
    result.add(r2);
    Set<RuleComponent> set = list.get(0).getItems();
    for (RuleComponent component : set) {
        SubPattern possibility = (SubPattern) component;
        assertTrue(possibility.getItems().containsAll(result));
    }
}
Also used : Pattern(org.drools.verifier.components.Pattern) SubPattern(org.drools.verifier.components.SubPattern) Restriction(org.drools.verifier.components.Restriction) LiteralRestriction(org.drools.verifier.components.LiteralRestriction) SubRule(org.drools.verifier.components.SubRule) Solvers(org.drools.verifier.solver.Solvers) ArrayList(java.util.ArrayList) VerifierRule(org.drools.verifier.components.VerifierRule) SubPattern(org.drools.verifier.components.SubPattern) RuleComponent(org.drools.verifier.components.RuleComponent) Test(org.junit.Test)

Example 10 with VerifierRule

use of org.drools.verifier.components.VerifierRule in project drools by kiegroup.

the class AlwaysTrueRuleTest method testPatternPossibilities.

@Test
public void testPatternPossibilities() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Rules.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<Object> data = new ArrayList<Object>();
    session.setGlobal("result", result);
    // This rule is always true.
    VerifierRule rule1 = VerifierComponentMockFactory.createRule1();
    Pattern pattern1 = VerifierComponentMockFactory.createPattern1();
    SubRule rp1 = new SubRule(rule1, 0);
    SubPattern pp1 = new SubPattern(pattern1, 0);
    AlwaysTrue alwaysTrue1 = new AlwaysTrue(pp1);
    SubPattern pp2 = new SubPattern(pattern1, 1);
    AlwaysTrue alwaysTrue2 = new AlwaysTrue(pp2);
    rp1.add(pp1);
    rp1.add(pp2);
    // This rule is okay.
    VerifierRule rule2 = VerifierComponentMockFactory.createRule2();
    Pattern pattern2 = VerifierComponentMockFactory.createPattern2();
    SubRule rp2 = new SubRule(rule2, 0);
    SubPattern pp3 = new SubPattern(pattern2, 0);
    SubPattern pp4 = new SubPattern(pattern2, 1);
    AlwaysTrue alwaysTrue4 = new AlwaysTrue(pp4);
    rp2.add(pp3);
    rp2.add(pp4);
    data.add(rule1);
    data.add(rp1);
    data.add(pp1);
    data.add(pp2);
    data.add(alwaysTrue1);
    data.add(alwaysTrue2);
    data.add(rule2);
    data.add(rp2);
    data.add(pp3);
    data.add(pp4);
    data.add(alwaysTrue4);
    for (Object o : data) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Rule possibility that is always true"));
    boolean rp1true = false;
    boolean rp2true = false;
    boolean rp3true = false;
    boolean rp4true = false;
    for (Object o : session.getObjects()) {
        if (o instanceof AlwaysTrue) {
            AlwaysTrue alwaysTrue = (AlwaysTrue) o;
            if (!rp1true) {
                rp1true = alwaysTrue.getCause().equals(pp1);
            }
            if (!rp2true) {
                rp2true = alwaysTrue.getCause().equals(pp2);
            }
            if (!rp3true) {
                rp3true = alwaysTrue.getCause().equals(pp3);
            }
            if (!rp4true) {
                rp4true = alwaysTrue.getCause().equals(pp4);
            }
        }
    }
    assertTrue(rp1true);
    assertTrue(rp2true);
    assertFalse(rp3true);
    assertTrue(rp4true);
}
Also used : Pattern(org.drools.verifier.components.Pattern) SubPattern(org.drools.verifier.components.SubPattern) RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) SubRule(org.drools.verifier.components.SubRule) VerifierReport(org.drools.verifier.data.VerifierReport) ArrayList(java.util.ArrayList) VerifierRule(org.drools.verifier.components.VerifierRule) KieSession(org.kie.api.runtime.KieSession) SubPattern(org.drools.verifier.components.SubPattern) AlwaysTrue(org.drools.verifier.report.components.AlwaysTrue) Test(org.junit.Test)

Aggregations

VerifierRule (org.drools.verifier.components.VerifierRule)20 Test (org.junit.Test)15 VerifierReport (org.drools.verifier.data.VerifierReport)11 RuleNameMatchesAgendaFilter (org.drools.core.base.RuleNameMatchesAgendaFilter)10 VerifierMessage (org.drools.verifier.report.components.VerifierMessage)10 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)10 KieSession (org.kie.api.runtime.KieSession)10 HashSet (java.util.HashSet)8 ArrayList (java.util.ArrayList)5 ObjectType (org.drools.verifier.components.ObjectType)5 Pattern (org.drools.verifier.components.Pattern)5 SubPattern (org.drools.verifier.components.SubPattern)5 SubRule (org.drools.verifier.components.SubRule)5 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)4 Restriction (org.drools.verifier.components.Restriction)3 Field (org.drools.verifier.components.Field)2 LiteralRestriction (org.drools.verifier.components.LiteralRestriction)2 RulePackage (org.drools.verifier.components.RulePackage)2 VerifierData (org.drools.verifier.data.VerifierData)2 AlwaysTrue (org.drools.verifier.report.components.AlwaysTrue)2