Search in sources :

Example 66 with ExprConstraintDescr

use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.

the class RuleParserTest method testConstraintAndConnective.

@Test
public void testConstraintAndConnective() throws Exception {
    final String text = "rule X when Person( age < 42 && location==\"atlanta\") then end";
    PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
    assertEquals(1, pattern.getDescrs().size());
    ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
    assertEquals("age < 42 && location==\"atlanta\"", fcd.getExpression());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 67 with ExprConstraintDescr

use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.

the class RuleParserTest method testPositionalConstraintsOnly.

@Test
public void testPositionalConstraintsOnly() throws Exception {
    final String text = "rule X when Person( \"Mark\", 42; ) then end";
    PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
    assertEquals(2, pattern.getDescrs().size());
    ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
    assertEquals("\"Mark\"", fcd.getExpression());
    assertEquals(0, fcd.getPosition());
    assertEquals(ExprConstraintDescr.Type.POSITIONAL, fcd.getType());
    fcd = (ExprConstraintDescr) pattern.getDescrs().get(1);
    assertEquals("42", fcd.getExpression());
    assertEquals(1, fcd.getPosition());
    assertEquals(ExprConstraintDescr.Type.POSITIONAL, fcd.getType());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 68 with ExprConstraintDescr

use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.

the class RuleParserTest method testPositionalsAndNamedConstraints.

@Test
public void testPositionalsAndNamedConstraints() throws Exception {
    final String text = "rule X when Person( \"Mark\", 42; location == \"atlanta\" ) then end";
    PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
    assertEquals(3, pattern.getDescrs().size());
    ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
    assertEquals("\"Mark\"", fcd.getExpression());
    assertEquals(0, fcd.getPosition());
    assertEquals(ExprConstraintDescr.Type.POSITIONAL, fcd.getType());
    fcd = (ExprConstraintDescr) pattern.getDescrs().get(1);
    assertEquals("42", fcd.getExpression());
    assertEquals(1, fcd.getPosition());
    assertEquals(ExprConstraintDescr.Type.POSITIONAL, fcd.getType());
    fcd = (ExprConstraintDescr) pattern.getDescrs().get(2);
    assertEquals("location == \"atlanta\"", fcd.getExpression());
    assertEquals(2, fcd.getPosition());
    assertEquals(ExprConstraintDescr.Type.NAMED, fcd.getType());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 69 with ExprConstraintDescr

use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.

the class RuleParserTest method testConstraintOrConnective.

@Test
public void testConstraintOrConnective() throws Exception {
    final String text = "rule X when Person( age < 42 || location==\"atlanta\") then end";
    PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
    assertEquals(1, pattern.getDescrs().size());
    ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
    assertEquals("age < 42 || location==\"atlanta\"", fcd.getExpression());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 70 with ExprConstraintDescr

use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.

the class RuleParserTest method testPredicate2.

@Test
public void testPredicate2() throws Exception {
    // predicates are also prefixed by the eval keyword
    final RuleDescr rule = (RuleDescr) parse("rule", "rule X when Foo(eval( $var.equals(\"xyz\") )) then end");
    final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    final List<?> constraints = pattern.getConstraint().getDescrs();
    assertEquals(1, constraints.size());
    final ExprConstraintDescr predicate = (ExprConstraintDescr) constraints.get(0);
    assertEquals("eval( $var.equals(\"xyz\") )", predicate.getExpression());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Aggregations

ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)75 PatternDescr (org.drools.drl.ast.descr.PatternDescr)65 Test (org.junit.Test)56 RuleDescr (org.drools.drl.ast.descr.RuleDescr)37 AndDescr (org.drools.drl.ast.descr.AndDescr)34 PackageDescr (org.drools.drl.ast.descr.PackageDescr)23 BaseDescr (org.drools.drl.ast.descr.BaseDescr)11 BindingDescr (org.drools.drl.ast.descr.BindingDescr)10 Cheese (org.drools.mvel.compiler.Cheese)9 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)8 GlobalDescr (org.drools.drl.ast.descr.GlobalDescr)5 NotDescr (org.drools.drl.ast.descr.NotDescr)5 Declaration (org.drools.core.rule.Declaration)4 KiePMMLFieldOperatorValue (org.kie.pmml.models.drools.ast.KiePMMLFieldOperatorValue)4 KiePMMLOperatorValue (org.kie.pmml.models.drools.tuples.KiePMMLOperatorValue)4 Element (org.w3c.dom.Element)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)3 PredicateConstraint (org.drools.core.rule.PredicateConstraint)3