use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class DMNDecisionTableHitPolicyTest method testSimpleDecisionTableHitPolicyUnique.
@Test
public void testSimpleDecisionTableHitPolicyUnique() {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0004-simpletable-U.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0004-simpletable-U");
assertThat(dmnModel, notNullValue());
final DMNContext context = getSimpleTableContext(BigDecimal.valueOf(18), "Medium", true);
final DMNContext result = evaluateSimpleTableWithContext(dmnModel, runtime, context);
assertThat(result.get("Approval Status"), is("Approved"));
}
use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class DMNDecisionTableHitPolicyTest method testSimpleDecisionTableHitPolicyAny.
private void testSimpleDecisionTableHitPolicyAny(final String resurceName, final String modelName, final boolean equalRules) {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime(resurceName, this.getClass());
final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", modelName);
assertThat(dmnModel, notNullValue());
final DMNContext context = getSimpleTableContext(BigDecimal.valueOf(18), "Medium", true);
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
final DMNContext result = dmnResult.getContext();
if (equalRules) {
assertThat(result.get("Approval Status"), is("Approved"));
} else {
assertThat(dmnResult.hasErrors(), is(true));
assertThat((String) result.get("Approval Status"), isEmptyOrNullString());
}
}
use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testDecisionTableInvalidInputTypeErrorMessage.
@Test
public void testDecisionTableInvalidInputTypeErrorMessage() {
final DMNContext context = DMNFactory.newContext();
context.set("Branches dispersion", 1);
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 testDecisionTableDefaultValue.
@Test
public void testDecisionTableDefaultValue() {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("decisiontable-default-value.dmn", this.getClass());
final DMNRuntimeEventListener listener = Mockito.mock(DMNRuntimeEventListener.class);
runtime.addListener(listener);
final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "decisiontable-default-value");
assertThat(dmnModel, notNullValue());
assertThat(dmnModel.getMessages().toString(), dmnModel.hasErrors(), is(false));
final DMNContext context = DMNFactory.newContext();
context.set("Age", new BigDecimal(16));
context.set("RiskCategory", "Medium");
context.set("isAffordable", true);
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(dmnResult.getMessages().toString(), dmnResult.hasErrors(), is(false));
final DMNContext result = dmnResult.getContext();
assertThat(result.get("Approval Status"), is("Declined"));
final ArgumentCaptor<AfterEvaluateDecisionTableEvent> captor = ArgumentCaptor.forClass(AfterEvaluateDecisionTableEvent.class);
verify(listener).afterEvaluateDecisionTable(captor.capture());
assertThat(captor.getValue().getMatches(), is(empty()));
assertThat(captor.getValue().getSelected(), is(empty()));
}
use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testDecisionTableInvalidInputErrorMessage.
@Test
public void testDecisionTableInvalidInputErrorMessage() {
final DMNContext context = DMNFactory.newContext();
context.set("Branches dispersion", "Province");
context.set("Number of Branches", BigDecimal.valueOf(10));
testDecisionTableInvalidInput(context);
}
Aggregations