Search in sources :

Example 81 with DMNResult

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

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

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

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

Example 85 with DMNResult

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

the class DMNInputRuntimeTest method testInputClauseTypeRefWithAllowedValues.

@Test
public void testInputClauseTypeRefWithAllowedValues() {
    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();
    context.set("MyInput", "a");
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("MyDecision"), is("Decision taken"));
}
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

DMNResult (org.kie.dmn.api.core.DMNResult)127 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)125 DMNContext (org.kie.dmn.api.core.DMNContext)122 DMNModel (org.kie.dmn.api.core.DMNModel)120 Test (org.junit.Test)119 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)23 BigDecimal (java.math.BigDecimal)22 HashMap (java.util.HashMap)22 KieServices (org.kie.api.KieServices)19 KieContainer (org.kie.api.runtime.KieContainer)19 ArrayList (java.util.ArrayList)16 List (java.util.List)15 Map (java.util.Map)15 DMNMessage (org.kie.dmn.api.core.DMNMessage)12 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 DMNModelImpl (org.kie.dmn.core.impl.DMNModelImpl)10