Search in sources :

Example 96 with DMNContext

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

the class DMNInputRuntimeTest method testInputStringAllowedValuesEvaluateAll.

@Test
public void testInputStringAllowedValuesEvaluateAll() {
    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", "SELF-EMPLOYED");
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("Employment Status Statement"), is("You are SELF-EMPLOYED"));
}
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 97 with DMNContext

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

the class DMNInputRuntimeTest method testInputStringEvaluateDecisionById.

@Test
public void testInputStringEvaluateDecisionById() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0001-input-data-string.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/drools/kie-dmn", "_0001-input-data-string");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = DMNFactory.newContext();
    context.set("Full Name", "John Doe");
    DMNResult dmnResult = runtime.evaluateById(dmnModel, context, "d_GreetingMessage");
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultById("d_GreetingMessage").getResult(), is("Hello John Doe"));
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("Greeting Message"), is("Hello John Doe"));
    dmnResult = runtime.evaluateById(dmnModel, context, "nonExistantId");
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultByName("Greeting Message").getEvaluationStatus(), is(DMNDecisionResult.DecisionEvaluationStatus.NOT_EVALUATED));
    dmnResult = runtime.evaluateById(dmnModel, context, "");
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultByName("Greeting Message").getEvaluationStatus(), is(DMNDecisionResult.DecisionEvaluationStatus.NOT_EVALUATED));
    dmnResult = runtime.evaluateById(dmnModel, context, (String) null);
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultByName("Greeting Message").getEvaluationStatus(), is(DMNDecisionResult.DecisionEvaluationStatus.NOT_EVALUATED));
}
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 98 with DMNContext

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

the class DMNInputRuntimeTest method testInputNumberEvaluateAll.

@Test
public void testInputNumberEvaluateAll() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0002-input-data-number.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0002-input-data-number");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = DMNFactory.newContext();
    context.set("Monthly Salary", new BigDecimal(1000));
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("Yearly Salary"), is(new BigDecimal(12000)));
}
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) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 99 with DMNContext

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

the class DMNInputRuntimeTest method testNonexistantInputNodeName.

@Test
public void testNonexistantInputNodeName() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0001-input-data-string.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/drools/kie-dmn", "_0001-input-data-string");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = DMNFactory.newContext();
    context.set("Nonexistant Input", "John Doe");
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultByName("Greeting Message").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) Test(org.junit.Test)

Example 100 with DMNContext

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

the class DMNInputRuntimeTest method testInputStringEvaluateDecisionByName.

@Test
public void testInputStringEvaluateDecisionByName() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0001-input-data-string.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/drools/kie-dmn", "_0001-input-data-string");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = DMNFactory.newContext();
    context.set("Full Name", "John Doe");
    DMNResult dmnResult = runtime.evaluateByName(dmnModel, context, "Greeting Message");
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultByName("Greeting Message").getResult(), is("Hello John Doe"));
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("Greeting Message"), is("Hello John Doe"));
    dmnResult = runtime.evaluateByName(dmnModel, context, "nonExistantName");
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultByName("Greeting Message").getEvaluationStatus(), is(DMNDecisionResult.DecisionEvaluationStatus.NOT_EVALUATED));
    dmnResult = runtime.evaluateByName(dmnModel, context, "");
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultByName("Greeting Message").getEvaluationStatus(), is(DMNDecisionResult.DecisionEvaluationStatus.NOT_EVALUATED));
    dmnResult = runtime.evaluateByName(dmnModel, context, (String) null);
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultByName("Greeting Message").getEvaluationStatus(), is(DMNDecisionResult.DecisionEvaluationStatus.NOT_EVALUATED));
}
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