Search in sources :

Example 16 with ExprConstraintDescr

use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.

the class RuleParserTest method testMemberof.

@Test
public void testMemberof() throws Exception {
    final String text = "rule X when Country( $cities : city )\nPerson( city memberOf $cities )\n then end";
    AndDescr descrs = ((RuleDescr) parse("rule", text)).getLhs();
    assertEquals(2, descrs.getDescrs().size());
    PatternDescr pat = (PatternDescr) descrs.getDescrs().get(1);
    ExprConstraintDescr fieldConstr = (ExprConstraintDescr) pat.getConstraint().getDescrs().get(0);
    assertEquals("city memberOf $cities", fieldConstr.getExpression());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 17 with ExprConstraintDescr

use of org.drools.compiler.lang.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.compiler.lang.descr.PatternDescr) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 18 with ExprConstraintDescr

use of org.drools.compiler.lang.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.compiler.lang.descr.PatternDescr) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 19 with ExprConstraintDescr

use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.

the class RuleParserTest method testRestrictions.

@Test
public void testRestrictions() throws Exception {
    final String text = "rule X when Foo( bar > 1 || == 1 ) then end\n";
    AndDescr descrs = (AndDescr) ((RuleDescr) parse("rule", text)).getLhs();
    assertEquals(1, descrs.getDescrs().size());
    PatternDescr pat = (PatternDescr) descrs.getDescrs().get(0);
    ExprConstraintDescr fieldConstr = (ExprConstraintDescr) pat.getConstraint().getDescrs().get(0);
    assertEquals("bar > 1 || == 1", fieldConstr.getExpression());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 20 with ExprConstraintDescr

use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.

the class RuleParserTest method testBigLiterals.

@Test
public void testBigLiterals() throws Exception {
    final String text = "rule X when Primitives( bigInteger == (10I), " + "                        bigDecimal == (10B), " + "                        bigInteger < 50I, " + "                        bigDecimal < 50B ) then end";
    PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
    assertEquals(4, pattern.getDescrs().size());
    ExprConstraintDescr ecd = (ExprConstraintDescr) pattern.getDescrs().get(0);
    assertEquals("bigInteger == (10I)", ecd.getExpression());
    ecd = (ExprConstraintDescr) pattern.getDescrs().get(1);
    assertEquals("bigDecimal == (10B)", ecd.getExpression());
    ecd = (ExprConstraintDescr) pattern.getDescrs().get(2);
    assertEquals("bigInteger < 50I", ecd.getExpression());
    ecd = (ExprConstraintDescr) pattern.getDescrs().get(3);
    assertEquals("bigDecimal < 50B", ecd.getExpression());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) Test(org.junit.Test)

Aggregations

ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)65 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)57 Test (org.junit.Test)49 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)37 AndDescr (org.drools.compiler.lang.descr.AndDescr)27 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)23 Cheese (org.drools.compiler.Cheese)9 BindingDescr (org.drools.compiler.lang.descr.BindingDescr)9 GlobalDescr (org.drools.compiler.lang.descr.GlobalDescr)5 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)5 List (java.util.List)4 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)4 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)4 Element (org.w3c.dom.Element)4 ArrayList (java.util.ArrayList)3 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)3 ConstraintConnectiveDescr (org.drools.compiler.lang.descr.ConstraintConnectiveDescr)3 QueryDescr (org.drools.compiler.lang.descr.QueryDescr)3 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)3 Declaration (org.drools.core.rule.Declaration)3