Search in sources :

Example 96 with DMNModel

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));
}
Also used : EvaluationContextImpl(org.kie.dmn.feel.lang.impl.EvaluationContextImpl) SimpleTypeImpl(org.kie.dmn.core.impl.SimpleTypeImpl) ItemDefNode(org.kie.dmn.api.core.ast.ItemDefNode) EvaluationContext(org.kie.dmn.feel.lang.EvaluationContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) DMNType(org.kie.dmn.api.core.DMNType) Test(org.junit.Test)

Example 97 with DMNModel

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));
}
Also used : ItemDefNode(org.kie.dmn.api.core.ast.ItemDefNode) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) CompositeTypeImpl(org.kie.dmn.core.impl.CompositeTypeImpl) DMNType(org.kie.dmn.api.core.DMNType) Test(org.junit.Test)

Example 98 with DMNModel

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);
}
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 99 with DMNModel

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"));
}
Also used : DMNContext(org.kie.dmn.api.core.DMNContext) List(java.util.List) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 100 with DMNModel

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;
}
Also used : DMNContext(org.kie.dmn.api.core.DMNContext) List(java.util.List) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) BigDecimal(java.math.BigDecimal)

Aggregations

DMNModel (org.kie.dmn.api.core.DMNModel)163 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)152 Test (org.junit.Test)143 DMNContext (org.kie.dmn.api.core.DMNContext)131 DMNResult (org.kie.dmn.api.core.DMNResult)123 BigDecimal (java.math.BigDecimal)26 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26 HashMap (java.util.HashMap)25 ArrayList (java.util.ArrayList)22 List (java.util.List)22 Map (java.util.Map)22 KieServices (org.kie.api.KieServices)21 KieContainer (org.kie.api.runtime.KieContainer)21 DMNMessage (org.kie.dmn.api.core.DMNMessage)16 CoreMatchers.is (org.hamcrest.CoreMatchers.is)13 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)13 AfterEvaluateDecisionTableEvent (org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent)13 DMNRuntimeEventListener (org.kie.dmn.api.core.event.DMNRuntimeEventListener)13 UUID (java.util.UUID)11 CoreMatchers.nullValue (org.hamcrest.CoreMatchers.nullValue)11