Search in sources :

Example 6 with SubPattern

use of org.drools.verifier.components.SubPattern 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)

Example 7 with SubPattern

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

the class VerifierDataMapsTest method testSaveVerifierComponentAndGetForAllComponentTypes.

@Test
public void testSaveVerifierComponentAndGetForAllComponentTypes() {
    RulePackage rulePackage = VerifierComponentMockFactory.createPackage1();
    saveVerifierComponentAndGet(rulePackage);
    VerifierRule rule = VerifierComponentMockFactory.createRule1();
    saveVerifierComponentAndGet(rule);
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    saveVerifierComponentAndGet(pattern);
    saveVerifierComponentAndGet(new InlineEvalDescr(pattern));
    saveVerifierComponentAndGet(new ObjectType(new PackageDescr("testPackage1")));
    saveVerifierComponentAndGet(new RuleOperatorDescr(new AndDescr(), rule, OperatorDescrType.AND));
    saveVerifierComponentAndGet(new PatternOperatorDescr(pattern, OperatorDescrType.AND));
    saveVerifierComponentAndGet(new SubPattern(pattern, 0));
    saveVerifierComponentAndGet(new ReturnValueFieldDescr(pattern));
    saveVerifierComponentAndGet(new SubRule(rule, 0));
    saveVerifierComponentAndGet(new TextConsequence(rule));
    saveVerifierComponentAndGet(new PatternVariable(rule));
    saveVerifierComponentAndGet(new VerifierAccessorDescr(rule));
    saveVerifierComponentAndGet(new VerifierAccumulateDescr(pattern));
    saveVerifierComponentAndGet(new VerifierCollectDescr(pattern));
    saveVerifierComponentAndGet(new RuleEval(rule));
    saveVerifierComponentAndGet(new VerifierFieldAccessDescr(rule));
    saveVerifierComponentAndGet(new VerifierFromDescr(pattern));
    saveVerifierComponentAndGet(new VerifierMethodAccessDescr(rule));
    saveVerifierComponentAndGet(new PatternEval(pattern));
}
Also used : Pattern(org.drools.verifier.components.Pattern) SubPattern(org.drools.verifier.components.SubPattern) TextConsequence(org.drools.verifier.components.TextConsequence) PatternVariable(org.drools.verifier.components.PatternVariable) VerifierMethodAccessDescr(org.drools.verifier.components.VerifierMethodAccessDescr) ReturnValueFieldDescr(org.drools.verifier.components.ReturnValueFieldDescr) SubRule(org.drools.verifier.components.SubRule) VerifierFieldAccessDescr(org.drools.verifier.components.VerifierFieldAccessDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) VerifierAccumulateDescr(org.drools.verifier.components.VerifierAccumulateDescr) VerifierRule(org.drools.verifier.components.VerifierRule) VerifierFromDescr(org.drools.verifier.components.VerifierFromDescr) SubPattern(org.drools.verifier.components.SubPattern) RuleEval(org.drools.verifier.components.RuleEval) RulePackage(org.drools.verifier.components.RulePackage) PatternEval(org.drools.verifier.components.PatternEval) ObjectType(org.drools.verifier.components.ObjectType) PatternOperatorDescr(org.drools.verifier.components.PatternOperatorDescr) RuleOperatorDescr(org.drools.verifier.components.RuleOperatorDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) VerifierCollectDescr(org.drools.verifier.components.VerifierCollectDescr) VerifierAccessorDescr(org.drools.verifier.components.VerifierAccessorDescr) InlineEvalDescr(org.drools.verifier.components.InlineEvalDescr) Test(org.junit.Test)

Aggregations

SubPattern (org.drools.verifier.components.SubPattern)7 Test (org.junit.Test)6 SubRule (org.drools.verifier.components.SubRule)5 Pattern (org.drools.verifier.components.Pattern)4 VerifierRule (org.drools.verifier.components.VerifierRule)4 ArrayList (java.util.ArrayList)3 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)3 LiteralRestriction (org.drools.verifier.components.LiteralRestriction)2 Restriction (org.drools.verifier.components.Restriction)2 RulePackage (org.drools.verifier.components.RulePackage)2 VerifierComponent (org.drools.verifier.data.VerifierComponent)2 VerifierReport (org.drools.verifier.data.VerifierReport)2 Solvers (org.drools.verifier.solver.Solvers)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Set (java.util.Set)1 AndDescr (org.drools.compiler.lang.descr.AndDescr)1 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)1 RuleNameMatchesAgendaFilter (org.drools.core.base.RuleNameMatchesAgendaFilter)1 InlineEvalDescr (org.drools.verifier.components.InlineEvalDescr)1 ObjectType (org.drools.verifier.components.ObjectType)1