Search in sources :

Example 11 with DMNModel

use of org.kie.dmn.api.core.DMNModel 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));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) HashMap(java.util.HashMap) DMNContext(org.kie.dmn.api.core.DMNContext) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 12 with DMNModel

use of org.kie.dmn.api.core.DMNModel 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)))));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 13 with DMNModel

use of org.kie.dmn.api.core.DMNModel 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'"));
}
Also used : DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 14 with DMNModel

use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.

the class DMNRuntimeTest method testSingletonlist_function_call.

@Test
public void testSingletonlist_function_call() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("singletonlist_fuction_call.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_0768879b-5ee1-410f-92f0-7732573b069d", "expression function subst [a] with a");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext ctx = runtime.newContext();
    ctx.set("InputLineItem", prototype(entry("Line", "0015"), entry("Description", "additional Battery")));
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, ctx);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("The Battery"), is(prototype(entry("Line", "0010"), entry("Description", "Battery"))));
    assertThat((List<?>) result.get("Remove Battery"), contains(prototype(entry("Line", "0020"), entry("Description", "Case")), prototype(entry("Line", "0030"), entry("Description", "Power Supply"))));
    assertThat((List<?>) result.get("Remove Battery"), not(contains(prototype(entry("Line", "0010"), entry("Description", "Battery")))));
    assertThat((List<?>) result.get("Insert before Line 0020"), contains(prototype(entry("Line", "0010"), entry("Description", "Battery")), prototype(entry("Line", "0015"), entry("Description", "additional Battery")), prototype(entry("Line", "0020"), entry("Description", "Case")), prototype(entry("Line", "0030"), entry("Description", "Power Supply"))));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 15 with DMNModel

use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.

the class DMNRuntimeTest method testFiltering.

@Test
public void testFiltering() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Person_filtering_by_age.dmn", getClass());
    runtime.addListener(DMNRuntimeUtil.createListener());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_e215ed7a-701b-4c53-b8df-4b4d23d5fe32", "Person filtering by age");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("Min Age", 50);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), ((List) dmnResult.getContext().get("Filtering")).size(), is(2));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Aggregations

DMNModel (org.kie.dmn.api.core.DMNModel)163 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)152 Test (org.junit.Test)143 DMNContext (org.kie.dmn.api.core.DMNContext)131 DMNResult (org.kie.dmn.api.core.DMNResult)123 BigDecimal (java.math.BigDecimal)26 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26 HashMap (java.util.HashMap)25 ArrayList (java.util.ArrayList)22 List (java.util.List)22 Map (java.util.Map)22 KieServices (org.kie.api.KieServices)21 KieContainer (org.kie.api.runtime.KieContainer)21 DMNMessage (org.kie.dmn.api.core.DMNMessage)16 CoreMatchers.is (org.hamcrest.CoreMatchers.is)13 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)13 AfterEvaluateDecisionTableEvent (org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent)13 DMNRuntimeEventListener (org.kie.dmn.api.core.event.DMNRuntimeEventListener)13 UUID (java.util.UUID)11 CoreMatchers.nullValue (org.hamcrest.CoreMatchers.nullValue)11