use of org.kie.dmn.feel.lang.impl.MapBackedType in project drools by kiegroup.
the class DirectCompilerTest method testQualifiedName.
@Test
public void testQualifiedName() {
String inputExpression = "My Person.Full Name";
Type personType = new MapBackedType("Person", mapOf(entry("Full Name", BuiltInType.STRING), entry("Age", BuiltInType.NUMBER)));
CompiledFEELExpression qualRef = parse(inputExpression, mapOf(entry("My Person", personType)));
LOG.debug("{}", qualRef);
EvaluationContext context = CodegenTestUtil.newEmptyEvaluationContext();
context.setValue("My Person", mapOf(entry("Full Name", "John Doe"), entry("Age", 47)));
Object result = qualRef.apply(context);
LOG.debug("{}", result);
assertThat(result, is("John Doe"));
// check number coercion for qualified name
CompiledFEELExpression personAgeExpression = parse("My Person.Age", mapOf(entry("My Person", personType)));
LOG.debug("{}", personAgeExpression);
// Please notice input variable in context is a Map containing and entry value for int 47.
Object resultPersonAge = personAgeExpression.apply(context);
LOG.debug("{}", resultPersonAge);
assertThat(resultPersonAge, is(BigDecimal.valueOf(47)));
}
use of org.kie.dmn.feel.lang.impl.MapBackedType in project drools by kiegroup.
the class CompositeTypeImpl method addField.
public void addField(String name, DMNType type) {
this.fields.put(name, type);
MapBackedType mbType = !isCollection() ? (MapBackedType) getFeelType() : (MapBackedType) ((GenListType) getFeelType()).getGen();
mbType.addField(name, ((BaseDMNTypeImpl) type).getFeelType());
}
use of org.kie.dmn.feel.lang.impl.MapBackedType 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"));
}
use of org.kie.dmn.feel.lang.impl.MapBackedType 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());
}
Aggregations