Search in sources :

Example 1 with BindingDescr

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

the class DRLExprParserTest method testBinding.

@Test
public void testBinding() throws Exception {
    String source = "$x : property";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(1, result.getDescrs().size());
    BindingDescr bind = (BindingDescr) result.getDescrs().get(0);
    assertEquals("$x", bind.getVariable());
    assertEquals("property", bind.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 2 with BindingDescr

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

the class DRLExprParserTest method testBindingConstraint.

@Test
public void testBindingConstraint() throws Exception {
    String source = "$x : property > value";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(1, result.getDescrs().size());
    RelationalExprDescr rel = (RelationalExprDescr) result.getDescrs().get(0);
    assertEquals(">", rel.getOperator());
    BindingDescr bind = (BindingDescr) rel.getLeft();
    assertEquals("$x", bind.getVariable());
    assertEquals("property", bind.getExpression());
    AtomicExprDescr right = (AtomicExprDescr) rel.getRight();
    assertEquals("value", right.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) RelationalExprDescr(org.drools.compiler.lang.descr.RelationalExprDescr) Test(org.junit.Test)

Example 3 with BindingDescr

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

the class DRLExprParserTest method testBindingWithRestrictions.

@Test
public void testBindingWithRestrictions() throws Exception {
    String source = "$x : property > value && < 20";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(2, result.getDescrs().size());
    RelationalExprDescr rel = (RelationalExprDescr) result.getDescrs().get(0);
    assertEquals(">", rel.getOperator());
    BindingDescr bind = (BindingDescr) rel.getLeft();
    assertEquals("$x", bind.getVariable());
    assertEquals("property", bind.getExpression());
    AtomicExprDescr right = (AtomicExprDescr) rel.getRight();
    assertEquals("value", right.getExpression());
    rel = (RelationalExprDescr) result.getDescrs().get(1);
    assertEquals("<", rel.getOperator());
    AtomicExprDescr left = (AtomicExprDescr) rel.getLeft();
    assertEquals("property", left.getExpression());
    right = (AtomicExprDescr) rel.getRight();
    assertEquals("20", right.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) RelationalExprDescr(org.drools.compiler.lang.descr.RelationalExprDescr) Test(org.junit.Test)

Example 4 with BindingDescr

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

the class DRLExprParserTest method testDoubleBinding.

@Test
public void testDoubleBinding() throws Exception {
    String source = "$x : x.m( 1, a ) && $y : y[z].foo";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(2, result.getDescrs().size());
    BindingDescr bind = (BindingDescr) result.getDescrs().get(0);
    assertEquals("$x", bind.getVariable());
    assertEquals("x.m( 1, a )", bind.getExpression());
    bind = (BindingDescr) result.getDescrs().get(1);
    assertEquals("$y", bind.getVariable());
    assertEquals("y[z].foo", bind.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 5 with BindingDescr

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

the class MVELDumperTest method testDumpBindingsComplexOp.

@Test
public void testDumpBindingsComplexOp() throws Exception {
    String input = "$x : age in (10, 20, $someVal)";
    String expected = "( age == 10 || age == 20 || age == $someVal )";
    ConstraintConnectiveDescr descr = parse(input);
    MVELDumperContext ctx = new MVELDumperContext();
    String result = dumper.dump(descr, ctx);
    assertEquals(expected, result);
    assertEquals(1, ctx.getBindings().size());
    BindingDescr bind = ctx.getBindings().get(0);
    assertEquals("$x", bind.getVariable());
    assertEquals("age", bind.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) MVELDumperContext(org.drools.compiler.lang.MVELDumper.MVELDumperContext) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Aggregations

BindingDescr (org.drools.compiler.lang.descr.BindingDescr)41 ConstraintConnectiveDescr (org.drools.compiler.lang.descr.ConstraintConnectiveDescr)17 Test (org.junit.Test)17 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)12 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)11 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)11 AtomicExprDescr (org.drools.compiler.lang.descr.AtomicExprDescr)10 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)9 Cheese (org.drools.compiler.Cheese)8 AndDescr (org.drools.compiler.lang.descr.AndDescr)8 AnnotatedBaseDescr (org.drools.compiler.lang.descr.AnnotatedBaseDescr)8 RelationalExprDescr (org.drools.compiler.lang.descr.RelationalExprDescr)8 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)7 GlobalDescr (org.drools.compiler.lang.descr.GlobalDescr)6 MVELDumperContext (org.drools.compiler.lang.MVELDumper.MVELDumperContext)5 ClassObjectType (org.drools.core.base.ClassObjectType)5 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)5 Declaration (org.drools.core.rule.Declaration)5 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)5 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)4