Search in sources :

Example 1 with MVELDumperContext

use of org.drools.compiler.lang.MVELDumper.MVELDumperContext 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)

Example 2 with MVELDumperContext

use of org.drools.compiler.lang.MVELDumper.MVELDumperContext in project drools by kiegroup.

the class MVELDumperTest method testDumpBindingsComplexOp2.

@Test
public void testDumpBindingsComplexOp2() throws Exception {
    String input = "$x : age not 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)

Example 3 with MVELDumperContext

use of org.drools.compiler.lang.MVELDumper.MVELDumperContext in project drools by kiegroup.

the class MVELDumperTest method testDumpBindingsWithRestriction.

@Test
public void testDumpBindingsWithRestriction() throws Exception {
    String input = "$x : age > 10 && < 20 || > 30";
    String expected = "( age > 10 && age < 20 || age > 30 )";
    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)

Example 4 with MVELDumperContext

use of org.drools.compiler.lang.MVELDumper.MVELDumperContext in project drools by kiegroup.

the class MVELDumperTest method testDumpBindings2.

@Test
public void testDumpBindings2() throws Exception {
    String input = "( $a : a > $b : b[10].prop || 10 != 20 ) && $x : someMethod(10) == 20";
    String expected = "( a > b[10].prop || 10 != 20 ) && someMethod(10) == 20";
    ConstraintConnectiveDescr descr = parse(input);
    MVELDumperContext ctx = new MVELDumperContext();
    String result = dumper.dump(descr, ctx);
    assertEquals(expected, result);
    assertEquals(3, ctx.getBindings().size());
    BindingDescr bind = ctx.getBindings().get(0);
    assertEquals("$a", bind.getVariable());
    assertEquals("a", bind.getExpression());
    bind = ctx.getBindings().get(1);
    assertEquals("$b", bind.getVariable());
    assertEquals("b[10].prop", bind.getExpression());
    bind = ctx.getBindings().get(2);
    assertEquals("$x", bind.getVariable());
    assertEquals("someMethod(10)", 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)

Example 5 with MVELDumperContext

use of org.drools.compiler.lang.MVELDumper.MVELDumperContext in project drools by kiegroup.

the class MVELDumperTest method testDumpBindings.

@Test
public void testDumpBindings() throws Exception {
    String input = "$x : property > value";
    String expected = "property > value";
    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("property", 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

MVELDumperContext (org.drools.compiler.lang.MVELDumper.MVELDumperContext)5 BindingDescr (org.drools.compiler.lang.descr.BindingDescr)5 ConstraintConnectiveDescr (org.drools.compiler.lang.descr.ConstraintConnectiveDescr)5 Test (org.junit.Test)5