use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNCompilerTest method testItemDefAllowedValuesString.
@Test
public void testItemDefAllowedValuesString() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0003-input-data-string-allowed-values.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0003-input-data-string-allowed-values");
assertThat(dmnModel, notNullValue());
ItemDefNode itemDef = dmnModel.getItemDefinitionByName("tEmploymentStatus");
assertThat(itemDef.getName(), is("tEmploymentStatus"));
assertThat(itemDef.getId(), is(nullValue()));
DMNType type = itemDef.getType();
assertThat(type, is(notNullValue()));
assertThat(type.getName(), is("tEmploymentStatus"));
assertThat(type.getId(), is(nullValue()));
assertThat(type, is(instanceOf(SimpleTypeImpl.class)));
SimpleTypeImpl feelType = (SimpleTypeImpl) type;
EvaluationContext ctx = new EvaluationContextImpl(null);
assertThat(feelType.getFeelType(), is(BuiltInType.STRING));
assertThat(feelType.getAllowedValuesFEEL().size(), is(4));
assertThat(feelType.getAllowedValuesFEEL().get(0).apply(ctx, "UNEMPLOYED"), is(true));
assertThat(feelType.getAllowedValuesFEEL().get(1).apply(ctx, "EMPLOYED"), is(true));
assertThat(feelType.getAllowedValuesFEEL().get(2).apply(ctx, "SELF-EMPLOYED"), is(true));
assertThat(feelType.getAllowedValuesFEEL().get(3).apply(ctx, "STUDENT"), is(true));
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNCompilerTest method testCompositeItemDefinition.
@Test
public void testCompositeItemDefinition() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0008-LX-arithmetic.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0008-LX-arithmetic");
assertThat(dmnModel, notNullValue());
ItemDefNode itemDef = dmnModel.getItemDefinitionByName("tLoan");
assertThat(itemDef.getName(), is("tLoan"));
assertThat(itemDef.getId(), is("tLoan"));
DMNType type = itemDef.getType();
assertThat(type, is(notNullValue()));
assertThat(type.getName(), is("tLoan"));
assertThat(type.getId(), is("tLoan"));
assertThat(type, is(instanceOf(CompositeTypeImpl.class)));
CompositeTypeImpl compType = (CompositeTypeImpl) type;
assertThat(compType.getFields().size(), is(3));
DMNType principal = compType.getFields().get("principal");
assertThat(principal, is(notNullValue()));
assertThat(principal.getName(), is("number"));
assertThat(((SimpleTypeImpl) principal).getFeelType(), is(BuiltInType.NUMBER));
DMNType rate = compType.getFields().get("rate");
assertThat(rate, is(notNullValue()));
assertThat(rate.getName(), is("number"));
assertThat(((SimpleTypeImpl) rate).getFeelType(), is(BuiltInType.NUMBER));
DMNType termMonths = compType.getFields().get("termMonths");
assertThat(termMonths, is(notNullValue()));
assertThat(termMonths.getName(), is("number"));
assertThat(((SimpleTypeImpl) termMonths).getFeelType(), is(BuiltInType.NUMBER));
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNDecisionTableHitPolicyTest method testSimpleDecisionTableHitPolicyUniqueSatisfies.
@Test
public void testSimpleDecisionTableHitPolicyUniqueSatisfies() {
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), "ASD", false);
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
final DMNContext result = dmnResult.getContext();
assertThat(result.get("Approval Status"), nullValue());
assertTrue(dmnResult.getMessages().size() > 0);
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNDecisionTableHitPolicyTest method testSimpleDecisionTableHitPolicyRuleOrder.
@Test
public void testSimpleDecisionTableHitPolicyRuleOrder() {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0004-simpletable-R.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0004-simpletable-R");
assertThat(dmnModel, notNullValue());
final DMNContext context = getSimpleTableContext(BigDecimal.valueOf(70), "Medium", true);
final DMNContext result = evaluateSimpleTableWithContext(dmnModel, runtime, context);
final List<String> decisionResults = (List<String>) result.get("Approval Status");
assertThat(decisionResults, hasSize(3));
assertThat(decisionResults, contains("Approved", "Needs review", "Declined"));
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNDecisionTableHitPolicyTest method executeTestDecisionTableHitPolicyCollect.
private List<BigDecimal> executeTestDecisionTableHitPolicyCollect(DMNContext context) {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0004-simpletable-C.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0004-simpletable-C");
assertThat(dmnModel, notNullValue());
final DMNContext result = evaluateSimpleTableWithContext(dmnModel, runtime, context);
final List<BigDecimal> decisionResults = (List<BigDecimal>) result.get("Status number");
return decisionResults;
}
Aggregations