use of org.kie.dmn.api.core.DMNResult in project drools by kiegroup.
the class DMNRuntimeTest method testNowFunction.
@Test
public void testNowFunction() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("today_function_test.dmn", getClass());
runtime.addListener(DMNRuntimeUtil.createListener());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_4ad80959-5fd8-46b7-8c9a-ab2fa58cb5b4", "When is it");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext context = DMNFactory.newContext();
context.set("The date", LocalDate.of(2017, 01, 12));
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.getContext().get("When is it"), is("It is in the past"));
}
use of org.kie.dmn.api.core.DMNResult in project drools by kiegroup.
the class DMNRuntimeTest method testInvokeFunctionCallerError.
@Test
public void testInvokeFunctionCallerError() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("Caller.dmn", this.getClass(), "Calling.dmn");
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_b0a696d6-3d57-4e97-b5d4-b44a63909d67", "Caller");
assertThat(dmnModel, notNullValue());
DMNContext wrongContext = DMNFactory.newContext();
wrongContext.set("My Name", "John Doe");
wrongContext.set("My Number", "<not a number>");
wrongContext.set("Call ns", "http://www.trisotech.com/definitions/_88156d21-3acc-43b6-8b81-385caf0bb6ca");
wrongContext.set("Call name", "Calling");
wrongContext.set("Invoke decision", "Final Result");
DMNResult dmnResult = runtime.evaluateAll(dmnModel, wrongContext);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
// total of: 2. x1 error in calling external decision, and x1 error in making final decision as it depends on the former.
// please notice it will print 4 lines in the log, 2x are the "external invocation" and then 2x are the one by the caller, checked herebelow:
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.getMessages().size(), is(2));
}
use of org.kie.dmn.api.core.DMNResult in project drools by kiegroup.
the class DMNRuntimeTest method testOutputReuse.
@Test
public void testOutputReuse() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Input_reuse_in_output.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_098bb607-eff7-4772-83ac-6ded8b371fa7", "Input reuse in output");
assertThat(dmnModel, notNullValue());
DMNContext context = DMNFactory.newContext();
context.set("Age", 40);
context.set("Requested Product", "Fixed30");
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(dmnResult.hasErrors(), is(false));
DMNContext result = dmnResult.getContext();
assertThat(result.get("My Decision"), is("Fixed30"));
}
use of org.kie.dmn.api.core.DMNResult in project drools by kiegroup.
the class DMNRuntimeTest method testEx_4_3simplifiedASD.
@Test
public void testEx_4_3simplifiedASD() {
// DROOLS-2117 improve Msg.ERROR_EVAL_NODE_DEP_WRONG_TYPE
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Ex_4_3simplified.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_5c5a9c72-627e-4666-ae85-31356fed3658", "Ex_4_3simplified");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext context = DMNFactory.newContext();
context.set("number", "ciao");
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
System.out.println(dmnResult);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
// we want the error message to include not only which value was incompatible, but the type which was expected.
// in this case the value is `ciao` for a String
// but should have been a FEEL:number.
assertThat(dmnResult.getMessages().stream().filter(m -> m.getMessageType() == DMNMessageType.ERROR_EVAL_NODE).anyMatch(m -> m.getMessage().endsWith("is not allowed by the declared type (DMNType{ http://www.omg.org/spec/FEEL/20140401 : number })")), is(true));
}
use of org.kie.dmn.api.core.DMNResult in project drools by kiegroup.
the class DMNRuntimeTest method testRelation.
@Test
public void testRelation() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("relation-expression.dmn", getClass());
// runtime.addListener( DMNRuntimeUtil.createListener() );
DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "relation-expression");
assertThat(dmnModel, notNullValue());
assertThat(dmnModel.getMessages().toString(), dmnModel.hasErrors(), is(false));
DMNContext context = DMNFactory.newContext();
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(dmnResult.hasErrors(), is(false));
assertThat(dmnResult.getContext().get("Employee Relation"), is(instanceOf(List.class)));
List<Map<String, Object>> employees = (List<Map<String, Object>>) dmnResult.getContext().get("Employee Relation");
Map<String, Object> e = employees.get(0);
assertThat(e.get("Name"), is("John"));
assertThat(e.get("Dept"), is("Sales"));
assertThat(e.get("Salary"), is(BigDecimal.valueOf(100000)));
e = employees.get(1);
assertThat(e.get("Name"), is("Mary"));
assertThat(e.get("Dept"), is("Finances"));
assertThat(e.get("Salary"), is(BigDecimal.valueOf(120000)));
}
Aggregations