Search in sources :

Example 11 with BuiltInType

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

the class DMNRuntimeTest method testYearsAndMonthsDuration.

@Test
public void testYearsAndMonthsDuration() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("yearMonthDuration.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_6eda1490-21ca-441e-8a26-ab3ca800e43c", "Drawing 1");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final BuiltInType feelType = (BuiltInType) BuiltInType.determineTypeFromName("yearMonthDuration");
    final ChronoPeriod period = (ChronoPeriod) feelType.fromString("P2Y1M");
    final DMNContext context = runtime.newContext();
    context.set("iDuration", period);
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("How long"), is("Longer than a year"));
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Aggregations

BuiltInType (org.kie.dmn.feel.lang.types.BuiltInType)11 DMNType (org.kie.dmn.api.core.DMNType)6 Type (org.kie.dmn.feel.lang.Type)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 DMNModel (org.kie.dmn.api.core.DMNModel)3 CompositeTypeImpl (org.kie.dmn.core.impl.CompositeTypeImpl)3 SimpleTypeImpl (org.kie.dmn.core.impl.SimpleTypeImpl)3 InputStream (java.io.InputStream)2 ChronoPeriod (java.time.chrono.ChronoPeriod)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 OutputField (org.dmg.pmml.OutputField)2 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)2 InputDataNode (org.kie.dmn.api.core.ast.InputDataNode)2 BaseDMNTypeImpl (org.kie.dmn.core.impl.BaseDMNTypeImpl)2 DMNModelImpl (org.kie.dmn.core.impl.DMNModelImpl)2