Search in sources :

Example 76 with DMNResult

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

the class DMNDecisionTableRuntimeTest method testDecisionTableOutputDMNTypeCollection.

@Test
public void testDecisionTableOutputDMNTypeCollection() {
    // DROOLS-2359
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("DecisionTableOutputDMNTypeCollection.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_ae5d2033-c6d0-411f-a394-da33a70e5638", "Drawing 1");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("selector", "asd");
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("a decision"), is(Arrays.asList("abc", "xyz")));
}
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 77 with DMNResult

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

the class DMNDecisionTableRuntimeTest method testTwoDecisionTables.

@Test
public void testTwoDecisionTables() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("two_decision_tables.dmn", this.getClass());
    final DMNRuntimeEventListener listener = Mockito.mock(DMNRuntimeEventListener.class);
    runtime.addListener(listener);
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_bbb692e7-3d95-407a-bf39-353085bf57f0", "Invocation with two decision table as parameters");
    assertThat(dmnModel, notNullValue());
    assertThat(dmnModel.getMessages().toString(), dmnModel.hasErrors(), is(false));
    final DMNContext context = DMNFactory.newContext();
    context.set("Number", 50);
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.getMessages().toString(), dmnResult.hasErrors(), is(false));
    final DMNContext result = dmnResult.getContext();
    assertThat((Map<String, Object>) result.get("Decision Logic 2"), hasEntry("the 5 analysis", "A number greater than 5"));
    assertThat((Map<String, Object>) result.get("Decision Logic 2"), hasEntry("the 100 analysis", "A number smaller than 100"));
    final ArgumentCaptor<AfterEvaluateDecisionTableEvent> captor = ArgumentCaptor.forClass(AfterEvaluateDecisionTableEvent.class);
    verify(listener, times(2)).afterEvaluateDecisionTable(captor.capture());
    assertThat(captor.getAllValues().get(0).getDecisionTableName(), is("a"));
    assertThat(captor.getAllValues().get(1).getDecisionTableName(), is("b"));
}
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) DMNRuntimeEventListener(org.kie.dmn.api.core.event.DMNRuntimeEventListener) Test(org.junit.Test)

Example 78 with DMNResult

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

the class DMNDecisionTableRuntimeTest method testDecisionTableInvalidInput.

private void testDecisionTableInvalidInput(final DMNContext inputContext) {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("InvalidInput.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_cdf29af2-959b-4004-8271-82a9f5a62147", "Dessin 1");
    assertThat(dmnModel, notNullValue());
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, inputContext);
    assertThat(dmnResult.hasErrors(), is(true));
    final DMNContext result = dmnResult.getContext();
    assertThat(result.isDefined("Branches distribution"), is(false));
}
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 79 with DMNResult

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

the class DMNInputRuntimeTest method testInputStringEvaluateAll.

@Test
public void testInputStringEvaluateAll() {
    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");
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    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"));
}
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 80 with DMNResult

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

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