use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNRuntimeTest method testVerifyExtendedKieFEELFunction_now.
@Test
public void testVerifyExtendedKieFEELFunction_now() {
// DROOLS-2322
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("just_now.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_56fd6445-ff6a-4c28-8206-71fce7f80436", "just now");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext emptyContext = DMNFactory.newContext();
DMNResult dmnResult = runtime.evaluateAll(dmnModel, emptyContext);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
assertThat(dmnResult.getDecisionResultByName("a decision just now").getResult(), notNullValue());
}
use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNRuntimeTest method testFunctionDefAndInvocation.
@Test
public void testFunctionDefAndInvocation() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("FunctionDefinition.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_0de36357-fec0-4b4e-b7f1-382d381e06e9", "Dessin 1");
assertThat(dmnModel, notNullValue());
assertThat(dmnModel.getMessages().toString(), dmnModel.hasErrors(), is(false));
DMNContext context = DMNFactory.newContext();
context.set("a", 10);
context.set("b", 5);
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(dmnResult.hasErrors(), is(false));
assertThat((Map<String, Object>) dmnResult.getContext().get("Math"), hasEntry("Sum", BigDecimal.valueOf(15)));
}
use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNRuntimeTest method testDecisionResultTypeCheck.
@Test
public void testDecisionResultTypeCheck() {
// DROOLS-1513
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("LoanRecommendationWrongOutputType.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_591d49d0-26e1-4a1c-9f72-b65bec09964a", "Loan Recommendation Multi-step");
assertThat(dmnModel, notNullValue());
System.out.println(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()));
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext context = runtime.newContext();
Map<String, Number> loan = new HashMap<>();
loan.put("Amount", 100);
loan.put("Rate", 12);
loan.put("Term", 1);
context.set("Loan", loan);
DMNResult dmnResult = runtime.evaluateByName(dmnModel, context, "Loan Payment");
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
assertThat(dmnResult.getMessages().size(), is(1));
assertThat(dmnResult.getMessages().get(0).getSourceId(), is("_93062144-ebc7-4ef7-a156-c342aeffac49"));
assertThat(dmnResult.getMessages().get(0).getMessageType(), is(DMNMessageType.ERROR_EVAL_NODE));
}
use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNRuntimeTest method testTypeInferenceForNestedContextAnonymousEntry.
@Test
public void testTypeInferenceForNestedContextAnonymousEntry() {
// DROOLS-1585
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("PersonListHelloBKM2.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_7e41a76e-2df6-4899-bf81-ae098757a3b6", "PersonListHelloBKM2");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext context = runtime.newContext();
Map<String, Object> p1 = prototype(entry("Full Name", "John Doe"), entry("Age", 33));
Map<String, Object> p2 = prototype(entry("Full Name", "47"), entry("Age", 47));
context.set("My Input Data", Arrays.asList(new Object[] { p1, p2 }));
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
DMNContext result = dmnResult.getContext();
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
assertThat((List<?>) result.get("My Decision"), contains(prototype(entry("Full Name", "Prof. John Doe"), entry("Age", EvalHelper.coerceNumber(33))), prototype(entry("Full Name", "Prof. 47"), entry("Age", EvalHelper.coerceNumber(47)))));
}
use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNRuntimeTest method testUnknownVariable2.
@Test
public void testUnknownVariable2() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("unknown_variable2.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_9105d4a6-6049-4ace-a9cd-88f18d29bc8f", "Loan Recommendation - context");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.getMessages().size(), is(1));
assertThat(dmnModel.getMessages().get(0).getMessageType(), is(DMNMessageType.ERR_COMPILING_FEEL));
assertThat(dmnModel.getMessages().get(0).getMessage(), containsString("Unknown variable 'Borrower.liquidAssetsAmt'"));
}
Aggregations