Search in sources :

Example 51 with DMNContext

use of org.kie.dmn.api.core.DMNContext 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 52 with DMNContext

use of org.kie.dmn.api.core.DMNContext 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)

Example 53 with DMNContext

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

the class DMNInputRuntimeTest method testInputStringNotAllowedValuesEvaluateAll.

public void testInputStringNotAllowedValuesEvaluateAll(final Object inputValue) {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0003-input-data-string-allowed-values.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0003-input-data-string-allowed-values");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = DMNFactory.newContext();
    context.set("Employment Status", inputValue);
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultByName("Employment Status Statement").getResult(), is((String) null));
    assertThat(dmnResult.getMessages().size(), is(1));
    assertThat(dmnResult.getMessages().get(0).getSeverity(), is(DMNMessage.Severity.ERROR));
    assertThat(dmnResult.getDecisionResults().get(0).getMessages().size(), is(1));
    assertThat(dmnResult.getDecisionResults().get(0).getMessages().get(0).getSeverity(), is(DMNMessage.Severity.ERROR));
}
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)

Example 54 with DMNContext

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

the class DMNInputRuntimeTest method testAllowedValuesChecks.

@Test
public void testAllowedValuesChecks() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("AllowedValuesChecks.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_238bd96d-47cd-4746-831b-504f3e77b442", "AllowedValuesChecks");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final DMNContext ctx1 = runtime.newContext();
    ctx1.set("p1", prototype(entry("Name", "P1"), entry("Interests", Arrays.asList("Golf"))));
    final DMNResult dmnResult1 = runtime.evaluateAll(dmnModel, ctx1);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult1.getMessages()), dmnResult1.hasErrors(), is(false));
    assertThat(dmnResult1.getContext().get("MyDecision"), is("The Person P1 likes 1 thing(s)."));
    final DMNContext ctx2 = runtime.newContext();
    ctx2.set("p1", prototype(entry("Name", "P2"), entry("Interests", Arrays.asList("x"))));
    final DMNResult dmnResult2 = runtime.evaluateAll(dmnModel, ctx2);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult2.getMessages()), dmnResult2.hasErrors(), is(true));
    assertThat(dmnResult2.getMessages().stream().anyMatch(m -> m.getMessageType().equals(DMNMessageType.ERROR_EVAL_NODE)), is(true));
    final DMNContext ctx3 = runtime.newContext();
    ctx3.set("p1", prototype(entry("Name", "P3"), entry("Interests", Arrays.asList("Golf", "Computer"))));
    final DMNResult dmnResult3 = runtime.evaluateAll(dmnModel, ctx3);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult3.getMessages()), dmnResult3.hasErrors(), is(false));
    assertThat(dmnResult3.getContext().get("MyDecision"), is("The Person P3 likes 2 thing(s)."));
    final DMNContext ctx4 = runtime.newContext();
    ctx4.set("p1", prototype(entry("Name", "P4"), entry("Interests", Arrays.asList("Golf", "x"))));
    final DMNResult dmnResult4 = runtime.evaluateAll(dmnModel, ctx4);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult4.getMessages()), dmnResult4.hasErrors(), is(true));
    assertThat(dmnResult4.getMessages().stream().anyMatch(m -> m.getMessageType().equals(DMNMessageType.ERROR_EVAL_NODE)), is(true));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) DMNFactory(org.kie.dmn.core.api.DMNFactory) DynamicTypeUtils.prototype(org.kie.dmn.core.util.DynamicTypeUtils.prototype) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNResult(org.kie.dmn.api.core.DMNResult) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) DynamicTypeUtils.entry(org.kie.dmn.core.util.DynamicTypeUtils.entry) Set(java.util.Set) Test(org.junit.Test) DMNRuntimeUtil(org.kie.dmn.core.util.DMNRuntimeUtil) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) BigDecimal(java.math.BigDecimal) DMNModel(org.kie.dmn.api.core.DMNModel) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) Assert(org.junit.Assert) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) 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 55 with DMNContext

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

the class DMNInputRuntimeTest method testInputDataTypeRefWithAllowedValues.

@Test
public void testInputDataTypeRefWithAllowedValues() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("actualInputMatchInputValues-forTypeRef.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://www.drools.org/kie-dmn/definitions", "definitions");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final DMNContext context = runtime.newContext();
    // <<< `zzz` is NOT in the list of allowed value as declared by the typeRef for this inputdata
    context.set("MyInput", "zzz");
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
    assertThat(dmnResult.getMessages().size(), is(1));
    assertThat(dmnResult.getMessages().get(0).getSourceId(), is("_3d560678-a126-4654-a686-bc6d941fe40b"));
}
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

DMNContext (org.kie.dmn.api.core.DMNContext)142 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)130 DMNModel (org.kie.dmn.api.core.DMNModel)129 Test (org.junit.Test)127 DMNResult (org.kie.dmn.api.core.DMNResult)123 HashMap (java.util.HashMap)24 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)24 BigDecimal (java.math.BigDecimal)23 ArrayList (java.util.ArrayList)20 List (java.util.List)20 Map (java.util.Map)20 KieServices (org.kie.api.KieServices)19 KieContainer (org.kie.api.runtime.KieContainer)19 DMNMessage (org.kie.dmn.api.core.DMNMessage)13 DMNRuntimeEventListener (org.kie.dmn.api.core.event.DMNRuntimeEventListener)11 CoreMatchers.is (org.hamcrest.CoreMatchers.is)10 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)10 AfterEvaluateDecisionTableEvent (org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent)10 Collection (java.util.Collection)8 UUID (java.util.UUID)8