Search in sources :

Example 21 with CompiledExpression

use of org.kie.dmn.feel.lang.CompiledExpression in project drools by kiegroup.

the class CompileEvaluateTest method test2OK.

@Test
public void test2OK() {
    CompilerContext ctx = feel.newCompilerContext();
    ctx.addInputVariableType("MyPerson", new MapBackedType().addField("FullName", BuiltInType.STRING));
    CompiledExpression compiledExpression = feel.compile("MyPerson.FullName", ctx);
    Map<String, Object> inputs = new HashMap<>();
    inputs.put("MyPerson", prototype(entry("FullName", "John Doe")));
    Object result = feel.evaluate(compiledExpression, inputs);
    assertThat(result, is("John Doe"));
}
Also used : HashMap(java.util.HashMap) CompilerContext(org.kie.dmn.feel.lang.CompilerContext) MapBackedType(org.kie.dmn.feel.lang.impl.MapBackedType) CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression) Test(org.junit.Test)

Example 22 with CompiledExpression

use of org.kie.dmn.feel.lang.CompiledExpression in project drools by kiegroup.

the class CompileEvaluateTest method testExternalFnMissingMethodString.

@Test
public void testExternalFnMissingMethodString() {
    CompiledExpression compiledExpression = feel.compile("{ fn : function( p1 ) external { java : { class : \"" + SomeTestUtilClass.class.getCanonicalName() + "\", method signature: \"greet(String)\" } }, r : fn( \"John Doe\" ) }.r", feel.newCompilerContext());
    Object result = feel.evaluate(compiledExpression, new HashMap<>());
    assertThat(errors).anyMatch(fe -> fe.getMessage().contains("greet(java.lang.String)"));
}
Also used : CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression) Test(org.junit.Test)

Example 23 with CompiledExpression

use of org.kie.dmn.feel.lang.CompiledExpression in project drools by kiegroup.

the class CompileEvaluateTest method testHyphenInProperty.

@Test
public void testHyphenInProperty() {
    CompilerContext ctx = feel.newCompilerContext();
    ctx.addInputVariableType("input", new MapBackedType().addField("Primary-Key", BuiltInType.STRING).addField("Value", BuiltInType.STRING));
    CompiledExpression compiledExpression = feel.compile("input.Primary-Key", ctx);
    assertTrue(errors.isEmpty());
    Map<String, Object> inputs = new HashMap<>();
    inputs.put("input", prototype(entry("Primary-Key", "k987")));
    Object result = feel.evaluate(compiledExpression, inputs);
    assertThat(result, is("k987"));
    assertTrue(errors.isEmpty());
}
Also used : HashMap(java.util.HashMap) CompilerContext(org.kie.dmn.feel.lang.CompilerContext) MapBackedType(org.kie.dmn.feel.lang.impl.MapBackedType) CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression) Test(org.junit.Test)

Aggregations

CompiledExpression (org.kie.dmn.feel.lang.CompiledExpression)23 CompilerContext (org.kie.dmn.feel.lang.CompilerContext)12 Test (org.junit.Test)11 HashMap (java.util.HashMap)7 MapBackedType (org.kie.dmn.feel.lang.impl.MapBackedType)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Collections (java.util.Collections)3 Collectors (java.util.stream.Collectors)3 DMNType (org.kie.dmn.api.core.DMNType)3 DMNLiteralExpressionEvaluator (org.kie.dmn.core.ast.DMNLiteralExpressionEvaluator)3 Map (java.util.Map)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 Collectors.toList (java.util.stream.Collectors.toList)2 QName (javax.xml.namespace.QName)2 ParseTree (org.antlr.v4.runtime.tree.ParseTree)2 DMNMessage (org.kie.dmn.api.core.DMNMessage)2 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)2 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)2