Search in sources :

Example 1 with RuleComponent

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

Aggregations

ArrayList (java.util.ArrayList)1 LiteralRestriction (org.drools.verifier.components.LiteralRestriction)1 Pattern (org.drools.verifier.components.Pattern)1 Restriction (org.drools.verifier.components.Restriction)1 RuleComponent (org.drools.verifier.components.RuleComponent)1 SubPattern (org.drools.verifier.components.SubPattern)1 SubRule (org.drools.verifier.components.SubRule)1 VerifierRule (org.drools.verifier.components.VerifierRule)1 Solvers (org.drools.verifier.solver.Solvers)1 Test (org.junit.Test)1