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);
}
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")));
}
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"));
}
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));
}
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"));
}
Aggregations