Search in sources :

Example 91 with DMNContext

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

the class DMNDecisionTableRuntimeTest method testDecisionTableNonexistingInputErrorMessage.

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

Example 92 with DMNContext

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

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

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

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

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