Search in sources :

Example 61 with DMNRuntime

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

Example 62 with DMNRuntime

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"));
}
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 63 with DMNRuntime

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")));
}
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 64 with DMNRuntime

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

Example 65 with DMNRuntime

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

Aggregations

DMNRuntime (org.kie.dmn.api.core.DMNRuntime)178 Test (org.junit.Test)164 DMNModel (org.kie.dmn.api.core.DMNModel)152 DMNContext (org.kie.dmn.api.core.DMNContext)132 DMNResult (org.kie.dmn.api.core.DMNResult)128 KieContainer (org.kie.api.runtime.KieContainer)34 KieServices (org.kie.api.KieServices)30 BigDecimal (java.math.BigDecimal)26 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26 HashMap (java.util.HashMap)25 List (java.util.List)22 ArrayList (java.util.ArrayList)21 Map (java.util.Map)21 DMNMessage (org.kie.dmn.api.core.DMNMessage)16 CoreMatchers.is (org.hamcrest.CoreMatchers.is)13 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)13 Results (org.kie.api.builder.Results)13 AfterEvaluateDecisionTableEvent (org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent)13 DMNRuntimeEventListener (org.kie.dmn.api.core.event.DMNRuntimeEventListener)13 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)13