Search in sources :

Example 16 with DMNResult

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

the class DMNDecisionTableRuntimeTest method testDTInContext.

@Test
public void testDTInContext() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("DT_in_context.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_4acdcb25-b298-435e-abd5-efd00ed686a5", "Drawing 1");
    assertThat(dmnModel, notNullValue());
    DMNContext context = DMNFactory.newContext();
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultByName("D1").getResult(), is(instanceOf(Map.class)));
    DMNContext result = dmnResult.getContext();
    assertThat(((Map) result.get("D1")).get("Text color"), is("red"));
}
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 17 with DMNResult

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

the class DMNDecisionTableRuntimeTest method testDecisionTableOutputDMNTypeCollectionWithLOV_NOtypecheck.

@Test
public void testDecisionTableOutputDMNTypeCollectionWithLOV_NOtypecheck() {
    // DROOLS-2359
    // do NOT use the DMNRuntimeUtil as that enables typeSafe check override for runtime.
    KieServices ks = KieServices.Factory.get();
    final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.0"), ks.getResources().newClassPathResource("DecisionTableOutputDMNTypeCollectionWithLOV.dmn", this.getClass()));
    DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_ae5d2033-c6d0-411f-a394-da33a70e5638", "List of Words in DT");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("selector", "asd");
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("a decision"), is(Arrays.asList("abc", "a")));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) KieServices(org.kie.api.KieServices) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 18 with DMNResult

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

the class DMNDecisionTableRuntimeTest method testDTUsingEqualsUnaryTestWithVariable1.

@Test
public void testDTUsingEqualsUnaryTestWithVariable1() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("DT_using_variables.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_ed1ec15b-40aa-424d-b1d0-4936df80b135", "DT Using variables");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    Map<String, Object> complex = new HashMap<>();
    complex.put("aBoolean", true);
    complex.put("aNumber", 10);
    complex.put("aString", "bar");
    DMNContext context = DMNFactory.newContext();
    context.set("Complex", complex);
    context.set("Another boolean", true);
    context.set("Another String", "bar");
    context.set("Another number", 10);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Compare Boolean"), is("Same boolean"));
    assertThat(result.get("Compare Number"), is("Equals"));
    assertThat(result.get("Compare String"), is("Same String"));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) HashMap(java.util.HashMap) 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 19 with DMNResult

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

the class DMNDecisionTableRuntimeTest method testEmptyOutputCell.

@Test
public void testEmptyOutputCell() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("DT_empty_output_cell.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_77ae284e-ce52-4579-a50f-f3cc584d7f4b", "Calculation1");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = DMNFactory.newContext();
    context.set("MonthlyDeptPmt", BigDecimal.valueOf(1));
    context.set("MonthlyPmt", BigDecimal.valueOf(1));
    context.set("MonthlyIncome", BigDecimal.valueOf(1));
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.hasErrors(), is(false));
    assertNull(dmnResult.getContext().get("Logique de décision 1"));
}
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 20 with DMNResult

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

the class DMNDecisionTableRuntimeTest method testDecisionTableOutputDMNTypeCollectionWithLOV.

@Test
public void testDecisionTableOutputDMNTypeCollectionWithLOV() {
    // DROOLS-2359
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("DecisionTableOutputDMNTypeCollectionWithLOV.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_ae5d2033-c6d0-411f-a394-da33a70e5638", "List of Words in DT");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("selector", "asd");
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("a decision"), is(Arrays.asList("abc", "a")));
}
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

DMNResult (org.kie.dmn.api.core.DMNResult)139 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)135 DMNContext (org.kie.dmn.api.core.DMNContext)134 DMNModel (org.kie.dmn.api.core.DMNModel)130 Test (org.junit.Test)127 HashMap (java.util.HashMap)24 BigDecimal (java.math.BigDecimal)23 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)23 KieServices (org.kie.api.KieServices)22 KieContainer (org.kie.api.runtime.KieContainer)22 ArrayList (java.util.ArrayList)19 List (java.util.List)17 Map (java.util.Map)17 DMNDecisionResult (org.kie.dmn.api.core.DMNDecisionResult)16 DMNMessage (org.kie.dmn.api.core.DMNMessage)13 CoreMatchers.is (org.hamcrest.CoreMatchers.is)10 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)10 AfterEvaluateDecisionTableEvent (org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent)10 DMNRuntimeEventListener (org.kie.dmn.api.core.event.DMNRuntimeEventListener)10 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)10