Search in sources :

Example 86 with DMNContext

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

the class DMNDecisionTableHitPolicyTest method testSimpleDecisionTableHitPolicyOutputOrder.

@Test
public void testSimpleDecisionTableHitPolicyOutputOrder() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0004-simpletable-O.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0004-simpletable-O");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = getSimpleTableContext(BigDecimal.valueOf(70), "Medium", true);
    final DMNContext result = evaluateSimpleTableWithContext(dmnModel, runtime, context);
    final List<String> decisionResults = (List<String>) result.get("Approval Status");
    assertThat(decisionResults, hasSize(3));
    assertThat(decisionResults, contains("Declined", "Declined", "Approved"));
}
Also used : DMNContext(org.kie.dmn.api.core.DMNContext) List(java.util.List) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 87 with DMNContext

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

the class DMNDecisionTableHitPolicyTest method testSimpleDecisionTableHitPolicyPriorityMultipleOutputs.

@Test
public void testSimpleDecisionTableHitPolicyPriorityMultipleOutputs() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0004-simpletable-P-multiple-outputs.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0004-simpletable-P-multiple-outputs");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = getSimpleTableContext(BigDecimal.valueOf(18), "Medium", true);
    final DMNContext result = evaluateSimpleTableWithContext(dmnModel, runtime, context);
    final Map<String, Object> decisionResult = (Map<String, Object>) result.get("Decision Result");
    assertThat(decisionResult.values(), hasSize(2));
    assertThat(decisionResult, hasEntry(is("Approval Status"), is("Declined")));
    assertThat(decisionResult, hasEntry(is("Decision Review"), is("Needs verification")));
}
Also used : 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 88 with DMNContext

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

the class DMNDecisionTableHitPolicyTest method testDecisionTableHitPolicyCollect.

@Test
public void testDecisionTableHitPolicyCollect() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Collect_Hit_Policy.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_da1a4dcb-01bf-4dee-9be8-f498bc68178c", "Collect Hit Policy");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = DMNFactory.newContext();
    context.set("Input", 20);
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.hasErrors(), is(false));
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("Collect"), is(BigDecimal.valueOf(50)));
}
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 89 with DMNContext

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

the class DMNDecisionTableHitPolicyTest method getSimpleTableContext.

private DMNContext getSimpleTableContext(final BigDecimal age, final String riskCategory, final boolean isAffordable) {
    final DMNContext context = DMNFactory.newContext();
    context.set("Age", age);
    context.set("RiskCategory", riskCategory);
    context.set("isAffordable", isAffordable);
    return context;
}
Also used : DMNContext(org.kie.dmn.api.core.DMNContext)

Example 90 with DMNContext

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

the class DMNDecisionTableHitPolicyTest method testSimpleDecisionTableHitPolicyCollectAggregateFunction.

private void testSimpleDecisionTableHitPolicyCollectAggregateFunction(final String resourceName, final String modelName, final BigDecimal expectedResult, final DMNContext context) {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime(resourceName, this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", modelName);
    assertThat(dmnModel, notNullValue());
    final DMNContext result = evaluateSimpleTableWithContext(dmnModel, runtime, context);
    assertThat(result.get("Status number"), is(expectedResult));
}
Also used : DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel)

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