Search in sources :

Example 36 with DMNContext

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

the class DMNDecisionTableHitPolicyTest method testSimpleDecisionTableHitPolicyUnique.

@Test
public void testSimpleDecisionTableHitPolicyUnique() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0004-simpletable-U.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0004-simpletable-U");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = getSimpleTableContext(BigDecimal.valueOf(18), "Medium", true);
    final DMNContext result = evaluateSimpleTableWithContext(dmnModel, runtime, context);
    assertThat(result.get("Approval Status"), is("Approved"));
}
Also used : 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 37 with DMNContext

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

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

the class DMNDecisionTableRuntimeTest method testDecisionTableInvalidInputTypeErrorMessage.

@Test
public void testDecisionTableInvalidInputTypeErrorMessage() {
    final DMNContext context = DMNFactory.newContext();
    context.set("Branches dispersion", 1);
    context.set("Number of Branches", BigDecimal.valueOf(10));
    testDecisionTableInvalidInput(context);
}
Also used : DMNContext(org.kie.dmn.api.core.DMNContext) Test(org.junit.Test)

Example 39 with DMNContext

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

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

the class DMNDecisionTableRuntimeTest method testDecisionTableInvalidInputErrorMessage.

@Test
public void testDecisionTableInvalidInputErrorMessage() {
    final DMNContext context = DMNFactory.newContext();
    context.set("Branches dispersion", "Province");
    context.set("Number of Branches", BigDecimal.valueOf(10));
    testDecisionTableInvalidInput(context);
}
Also used : DMNContext(org.kie.dmn.api.core.DMNContext) 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