Search in sources :

Example 6 with DMNResult

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

the class DMNDecisionTableHitPolicyTest method testSimpleDecisionTableHitPolicyCollectSumMultipleOutputs.

@Test
public void testSimpleDecisionTableHitPolicyCollectSumMultipleOutputs() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0004-simpletable-C-sum-multiple-outputs.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0004-simpletable-C-sum-multiple-outputs");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = getSimpleTableContext(BigDecimal.valueOf(70), "Medium", true);
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    final DMNContext result = dmnResult.getContext();
    final Map<String, Object> decisionResult = (Map<String, Object>) result.get("Decision Result");
    assertThat(decisionResult.values(), hasSize(2));
    assertThat(decisionResult, hasEntry("Value1", BigDecimal.valueOf(25)));
    assertThat(decisionResult, hasEntry("Value2", BigDecimal.valueOf(32)));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Map(java.util.Map) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 7 with DMNResult

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

the class DMNDecisionTableHitPolicyTest method testSimpleDecisionTableHitPolicyAny.

private void testSimpleDecisionTableHitPolicyAny(final String resurceName, final String modelName, final boolean equalRules) {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime(resurceName, this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", modelName);
    assertThat(dmnModel, notNullValue());
    final DMNContext context = getSimpleTableContext(BigDecimal.valueOf(18), "Medium", true);
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    final DMNContext result = dmnResult.getContext();
    if (equalRules) {
        assertThat(result.get("Approval Status"), is("Approved"));
    } else {
        assertThat(dmnResult.hasErrors(), is(true));
        assertThat((String) result.get("Approval Status"), isEmptyOrNullString());
    }
}
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 8 with DMNResult

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

the class DMNDecisionTableRuntimeTest method testDecisionTableDefaultValue.

@Test
public void testDecisionTableDefaultValue() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("decisiontable-default-value.dmn", this.getClass());
    final DMNRuntimeEventListener listener = Mockito.mock(DMNRuntimeEventListener.class);
    runtime.addListener(listener);
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "decisiontable-default-value");
    assertThat(dmnModel, notNullValue());
    assertThat(dmnModel.getMessages().toString(), dmnModel.hasErrors(), is(false));
    final DMNContext context = DMNFactory.newContext();
    context.set("Age", new BigDecimal(16));
    context.set("RiskCategory", "Medium");
    context.set("isAffordable", true);
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.getMessages().toString(), dmnResult.hasErrors(), is(false));
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("Approval Status"), is("Declined"));
    final ArgumentCaptor<AfterEvaluateDecisionTableEvent> captor = ArgumentCaptor.forClass(AfterEvaluateDecisionTableEvent.class);
    verify(listener).afterEvaluateDecisionTable(captor.capture());
    assertThat(captor.getValue().getMatches(), is(empty()));
    assertThat(captor.getValue().getSelected(), is(empty()));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) AfterEvaluateDecisionTableEvent(org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) BigDecimal(java.math.BigDecimal) DMNRuntimeEventListener(org.kie.dmn.api.core.event.DMNRuntimeEventListener) Test(org.junit.Test)

Example 9 with DMNResult

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

the class DMNDecisionTableRuntimeTest method testDTUsingEqualsUnaryTestWithVariable2.

@Test
public void testDTUsingEqualsUnaryTestWithVariable2() {
    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(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", false);
    context.set("Another String", "foo");
    context.set("Another number", 20);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Compare Boolean"), is("Not same boolean"));
    assertThat(result.get("Compare Number"), is("Bigger"));
    assertThat(result.get("Compare String"), is("Different 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 10 with DMNResult

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

the class DMNDecisionTableRuntimeTest method checkDecisionTableWithCalculatedResult.

private void checkDecisionTableWithCalculatedResult(final DMNRuntime runtime) {
    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(200));
    context.set("MonthlyPmt", BigDecimal.valueOf(100));
    context.set("MonthlyIncome", BigDecimal.valueOf(600));
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.hasErrors(), is(false));
    final DMNContext result = dmnResult.getContext();
    assertThat(((BigDecimal) result.get("Logique de décision 1")).setScale(1, RoundingMode.CEILING), is(BigDecimal.valueOf(0.5)));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNModel(org.kie.dmn.api.core.DMNModel)

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