use of org.drools.compiler.lang.DumperContext in project drools by kiegroup.
the class DescrDumperTest 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);
DumperContext ctx = new DumperContext();
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());
}
use of org.drools.compiler.lang.DumperContext in project drools by kiegroup.
the class DescrDumperTest method testDumpBindings.
@Test
public void testDumpBindings() throws Exception {
String input = "$x : property > value";
String expected = "property > value";
ConstraintConnectiveDescr descr = parse(input);
DumperContext ctx = new DumperContext();
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());
}
use of org.drools.compiler.lang.DumperContext in project drools by kiegroup.
the class QueryElementBuilder method getLiteralQueryArgument.
private QueryArgument getLiteralQueryArgument(RuleBuildContext context, BaseDescr descr, ConstraintConnectiveDescr result) {
DumperContext mvelCtx = new DumperContext();
String expr = DescrDumper.getInstance().dump(result, mvelCtx);
try {
Object value = CoreComponentsBuilder.get().evaluateMvelExpression(context.getPkg().getDialectRuntimeRegistry().getDialectData("mvel"), context.getKnowledgeBuilder().getRootClassLoader(), expr);
return new QueryArgument.Literal(value);
} catch (Exception e) {
context.addError(new DescrBuildError(context.getParentDescr(), descr, null, "Unable to compile expression: " + expr));
}
return null;
}
Aggregations