use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testDecisionTableWithCalculatedResult.
@Test
public void testDecisionTableWithCalculatedResult() {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("calculation1.dmn", this.getClass());
checkDecisionTableWithCalculatedResult(runtime);
}
use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testEmptyOutputCell.
@Test
public void testEmptyOutputCell() {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("DT_empty_output_cell.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_77ae284e-ce52-4579-a50f-f3cc584d7f4b", "Calculation1");
assertThat(dmnModel, notNullValue());
final DMNContext context = DMNFactory.newContext();
context.set("MonthlyDeptPmt", BigDecimal.valueOf(1));
context.set("MonthlyPmt", BigDecimal.valueOf(1));
context.set("MonthlyIncome", BigDecimal.valueOf(1));
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(dmnResult.hasErrors(), is(false));
assertNull(dmnResult.getContext().get("Logique de décision 1"));
}
use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testDecisionTableOutputDMNTypeCollectionWithLOV.
@Test
public void testDecisionTableOutputDMNTypeCollectionWithLOV() {
// DROOLS-2359
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("DecisionTableOutputDMNTypeCollectionWithLOV.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_ae5d2033-c6d0-411f-a394-da33a70e5638", "List of Words in DT");
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", "a")));
}
use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNInputRuntimeTest method testInputStringNotAllowedValuesEvaluateAll.
public void testInputStringNotAllowedValuesEvaluateAll(final Object inputValue) {
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", inputValue);
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(dmnResult.getDecisionResults().size(), is(1));
assertThat(dmnResult.getDecisionResultByName("Employment Status Statement").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));
}
use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNInputRuntimeTest method testDMNInputDataNodeTypeTest.
@Test
public void testDMNInputDataNodeTypeTest() {
// DROOLS-1569
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("DMNInputDataNodeTypeTest.dmn", this.getClass());
final String MODEL_NAMESPACE = "http://www.trisotech.com/definitions/_17396034-163a-48aa-9a7f-c6eb17f9cc6c";
final String FEEL_NAMESPACE = "http://www.omg.org/spec/FEEL/20140401";
final DMNModel dmnModel = runtime.getModel(MODEL_NAMESPACE, "DMNInputDataNodeTypeTest");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
final InputDataNode idnMembership = dmnModel.getInputs().stream().filter(idn -> idn.getName().equals("Membership Level")).findFirst().get();
assertThat(idnMembership.getType().getBaseType().getNamespace(), is(FEEL_NAMESPACE));
assertThat(idnMembership.getType().getBaseType().getName(), is("string"));
assertThat(idnMembership.getType().isCollection(), is(false));
assertThat(idnMembership.getType().isComposite(), is(false));
assertThat(idnMembership.getType().getAllowedValues().size(), is(3));
assertThat(idnMembership.getType().getAllowedValues().get(0).toString(), is("\"Gold\""));
assertThat(idnMembership.getType().getAllowedValues().get(1).toString(), is("\"Silver\""));
assertThat(idnMembership.getType().getAllowedValues().get(2).toString(), is("\"None\""));
final InputDataNode idnMembershipLevels = dmnModel.getInputs().stream().filter(idn -> idn.getName().equals("Membership Levels")).findFirst().get();
assertThat(idnMembershipLevels.getType().getBaseType().getNamespace(), is(MODEL_NAMESPACE));
assertThat(idnMembershipLevels.getType().getBaseType().getName(), is("tMembershipLevel"));
assertThat(idnMembershipLevels.getType().isCollection(), is(true));
assertThat(idnMembershipLevels.getType().isComposite(), is(false));
assertThat(idnMembershipLevels.getType().getAllowedValues().isEmpty(), is(true));
final InputDataNode idnPercent = dmnModel.getInputs().stream().filter(idn -> idn.getName().equals("Percent")).findFirst().get();
assertThat(idnPercent.getType().getBaseType().getNamespace(), is(FEEL_NAMESPACE));
assertThat(idnPercent.getType().getBaseType().getName(), is("number"));
assertThat(idnPercent.getType().isCollection(), is(false));
assertThat(idnPercent.getType().isComposite(), is(false));
assertThat(idnPercent.getType().getAllowedValues().size(), is(1));
assertThat(idnPercent.getType().getAllowedValues().get(0).toString(), is("[0..100]"));
final InputDataNode idnCarDamageResponsibility = dmnModel.getInputs().stream().filter(idn -> idn.getName().equals("Car Damage Responsibility")).findFirst().get();
assertThat(idnCarDamageResponsibility.getType().getBaseType(), is(nullValue()));
assertThat(idnCarDamageResponsibility.getType().isCollection(), is(false));
assertThat(idnCarDamageResponsibility.getType().isComposite(), is(true));
}
Aggregations