Search in sources :

Example 1 with RulePackage

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

the class SolversTest method testNotAnd.

/**
 * <pre>
 * when
 *     Foo( r &amp;&amp; r2 )
 *     and
 *     not Foo( r3 &amp;&amp; r4 )
 * </pre>
 *
 * result:<br>
 * r && r2<br>
 * r3 && r4
 */
@Test
public void testNotAnd() {
    PackageDescr descr = new PackageDescr("testPackage");
    RulePackage rulePackage = new RulePackage(descr);
    rulePackage.setName("testPackage");
    VerifierRule rule = new VerifierRule(descr, rulePackage, new HashMap<String, Object>());
    rule.setName("testRule");
    Pattern pattern = new Pattern(new PatternDescr(), rule);
    Restriction r = LiteralRestriction.createRestriction(pattern, "");
    Restriction r2 = LiteralRestriction.createRestriction(pattern, "");
    Restriction r3 = LiteralRestriction.createRestriction(pattern, "");
    Restriction r4 = LiteralRestriction.createRestriction(pattern, "");
    Solvers solvers = new Solvers();
    solvers.startRuleSolver(rule);
    solvers.startOperator(OperatorDescrType.AND);
    solvers.startPatternSolver(pattern);
    solvers.startOperator(OperatorDescrType.AND);
    solvers.addPatternComponent(r);
    solvers.addPatternComponent(r2);
    solvers.endOperator();
    solvers.endPatternSolver();
    solvers.startNot();
    solvers.startPatternSolver(pattern);
    solvers.startOperator(OperatorDescrType.AND);
    solvers.addPatternComponent(r3);
    solvers.addPatternComponent(r4);
    solvers.endOperator();
    solvers.endPatternSolver();
    solvers.endNot();
    solvers.endOperator();
    solvers.endRuleSolver();
    List<SubRule> list = solvers.getRulePossibilities();
    assertEquals(1, list.size());
    assertEquals(2, list.get(0).getItems().size());
    List<Restriction> result = new ArrayList<Restriction>();
    result.add(r);
    result.add(r2);
    List<Restriction> result2 = new ArrayList<Restriction>();
    result2.add(r3);
    result2.add(r4);
    Object[] possibilies = list.get(0).getItems().toArray();
    SubPattern p1 = (SubPattern) possibilies[0];
    SubPattern p2 = (SubPattern) possibilies[1];
    /*
         * Order may change but it doesn't matter.
         */
    if (p1.getItems().containsAll(result)) {
        assertTrue(p2.getItems().containsAll(result2));
    } else if (p1.getItems().containsAll(result2)) {
        assertTrue(p2.getItems().containsAll(result));
    } else {
        fail("No items found.");
    }
}
Also used : Pattern(org.drools.verifier.components.Pattern) SubPattern(org.drools.verifier.components.SubPattern) PatternDescr(org.drools.drl.ast.descr.PatternDescr) SubRule(org.drools.verifier.components.SubRule) ArrayList(java.util.ArrayList) VerifierRule(org.drools.verifier.components.VerifierRule) SubPattern(org.drools.verifier.components.SubPattern) RulePackage(org.drools.verifier.components.RulePackage) Restriction(org.drools.verifier.components.Restriction) LiteralRestriction(org.drools.verifier.components.LiteralRestriction) Solvers(org.drools.verifier.solver.Solvers) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Test(org.junit.Test)

Example 2 with RulePackage

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

the class VerifierImpl method addDrlPackageData.

private DrlPackageParser addDrlPackageData(String drl) throws ParseException {
    DrlPackageParser pData = DrlPackageParser.findPackageDataFromDrl(drl);
    RulePackage rPackage = this.result.getVerifierData().getPackageByName(pData.getName());
    rPackage.getGlobals().addAll(pData.getGlobals());
    rPackage.setDescription(pData.getDescription());
    rPackage.getMetadata().addAll(pData.getMetadata());
    rPackage.getOtherInfo().putAll(pData.getOtherInformation());
    return pData;
}
Also used : DrlPackageParser(org.drools.verifier.misc.DrlPackageParser) RulePackage(org.drools.verifier.components.RulePackage)

Example 3 with RulePackage

use of org.drools.verifier.components.RulePackage 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.drl.ast.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.drl.ast.descr.PackageDescr) VerifierCollectDescr(org.drools.verifier.components.VerifierCollectDescr) VerifierAccessorDescr(org.drools.verifier.components.VerifierAccessorDescr) InlineEvalDescr(org.drools.verifier.components.InlineEvalDescr) Test(org.junit.Test)

Example 4 with RulePackage

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

the class PackageDescrVisitor method visitPackageDescr.

public void visitPackageDescr(PackageDescr descr) throws UnknownDescriptionException, ClassNotFoundException, IOException {
    rulePackage = data.getPackageByName(descr.getName());
    if (rulePackage == null) {
        rulePackage = new RulePackage(descr);
        rulePackage.setName(descr.getName());
        data.add(rulePackage);
    }
    visitImports(descr.getImports());
    TypeDeclarationDescrVisitor typeDeclarationDescrVisitor = new TypeDeclarationDescrVisitor(data);
    typeDeclarationDescrVisitor.visit(descr.getTypeDeclarations());
    visitRules(descr.getRules());
}
Also used : RulePackage(org.drools.verifier.components.RulePackage)

Example 5 with RulePackage

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

the class VerifierComponentMockFactory method createPackage1.

public static RulePackage createPackage1() {
    PackageDescr descr = new PackageDescr("testPackage1");
    RulePackage rulePackage = new RulePackage(descr);
    rulePackage.setName("testPackage1");
    return rulePackage;
}
Also used : PackageDescr(org.drools.drl.ast.descr.PackageDescr) RulePackage(org.drools.verifier.components.RulePackage)

Aggregations

RulePackage (org.drools.verifier.components.RulePackage)5 PackageDescr (org.drools.drl.ast.descr.PackageDescr)3 Pattern (org.drools.verifier.components.Pattern)2 SubPattern (org.drools.verifier.components.SubPattern)2 SubRule (org.drools.verifier.components.SubRule)2 VerifierRule (org.drools.verifier.components.VerifierRule)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 AndDescr (org.drools.drl.ast.descr.AndDescr)1 PatternDescr (org.drools.drl.ast.descr.PatternDescr)1 InlineEvalDescr (org.drools.verifier.components.InlineEvalDescr)1 LiteralRestriction (org.drools.verifier.components.LiteralRestriction)1 ObjectType (org.drools.verifier.components.ObjectType)1 PatternEval (org.drools.verifier.components.PatternEval)1 PatternOperatorDescr (org.drools.verifier.components.PatternOperatorDescr)1 PatternVariable (org.drools.verifier.components.PatternVariable)1 Restriction (org.drools.verifier.components.Restriction)1 ReturnValueFieldDescr (org.drools.verifier.components.ReturnValueFieldDescr)1 RuleEval (org.drools.verifier.components.RuleEval)1 RuleOperatorDescr (org.drools.verifier.components.RuleOperatorDescr)1