Search in sources :

Example 16 with ExprConstraintDescr

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

the class RuleParserTest method testPluggableOperators2.

@Test
public void testPluggableOperators2() throws Exception {
    final String text = "rule \"tt\"\n" + "    dialect \"mvel\"\n" + "when\n" + "    exists (TelephoneCall( this finishes [1m] \"25-May-2011\" ))\n" + "then\n" + "end";
    PatternDescr pattern = (PatternDescr) ((ExistsDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0)).getDescrs().get(0);
    assertEquals("TelephoneCall", pattern.getObjectType());
    ExprConstraintDescr constr = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0);
    assertEquals("this finishes [1m] \"25-May-2011\"", constr.getText());
}
Also used : ExistsDescr(org.drools.drl.ast.descr.ExistsDescr) PatternDescr(org.drools.drl.ast.descr.PatternDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 17 with ExprConstraintDescr

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

the class RuleParserTest method testWithRetval.

@Test
public void testWithRetval() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "with_retval.drl");
    assertEquals(1, pkg.getRules().size());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals(1, rule.getLhs().getDescrs().size());
    final PatternDescr col = (PatternDescr) rule.getLhs().getDescrs().get(0);
    assertEquals(1, col.getConstraint().getDescrs().size());
    assertEquals("Foo", col.getObjectType());
    final ExprConstraintDescr fld = (ExprConstraintDescr) col.getConstraint().getDescrs().get(0);
    assertEquals("name== (a + b)", fld.getExpression());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 18 with ExprConstraintDescr

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

the class RuleParserTest method testUnificationBinding.

@Test
public void testUnificationBinding() throws Exception {
    final String text = "rule X when $p := Person( $name := name, $loc : location ) then end";
    PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
    assertEquals("$p", pattern.getIdentifier());
    assertTrue(pattern.isUnification());
    assertEquals(2, pattern.getDescrs().size());
    ExprConstraintDescr bindingDescr = (ExprConstraintDescr) pattern.getDescrs().get(0);
    assertEquals("$name := name", bindingDescr.getExpression());
    bindingDescr = (ExprConstraintDescr) pattern.getDescrs().get(1);
    assertEquals("$loc : location", bindingDescr.getExpression());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 19 with ExprConstraintDescr

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

the class RuleParserTest method testNullConstraints.

@Test
public void testNullConstraints() throws Exception {
    final String text = "rule X when Person( name == null ) 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("name == null", fcd.getExpression());
    assertEquals(0, 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 20 with ExprConstraintDescr

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

the class RuleParserTest method testRuleOldSyntax2.

@Test
public void testRuleOldSyntax2() throws Exception {
    final String source = "rule \"Test\" when ( $r :LiteralRestriction( operator == Operator.EQUAL ) ) then end";
    PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals("Test", rule.getName());
    assertEquals(1, rule.getLhs().getDescrs().size());
    PatternDescr patternDescr = (PatternDescr) rule.getLhs().getDescrs().get(0);
    assertEquals("$r", patternDescr.getIdentifier());
    assertEquals(1, patternDescr.getDescrs().size());
    ExprConstraintDescr fieldConstraintDescr = (ExprConstraintDescr) patternDescr.getDescrs().get(0);
    assertEquals("operator == Operator.EQUAL", fieldConstraintDescr.getExpression());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) 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