Search in sources :

Example 21 with DMNContextFPAImpl

use of org.kie.dmn.core.impl.DMNContextFPAImpl in project drools by kiegroup.

the class DMN13specificTest method testDMNv1_3_ch11.

@Test
public void testDMNv1_3_ch11() {
    testName = "testDMNv1_3_ch11";
    final DMNRuntime runtime = createRuntimeWithAdditionalResources("Chapter 11 Example.dmn", this.getClass(), "Financial.dmn");
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_9d01a0c4-f529-4ad8-ad8e-ec5fb5d96ad4", "Chapter 11 Example");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final DMNContext context = DMNFactory.newContext();
    context.set("Applicant data", mapOf(entry("Age", new BigDecimal(51)), // typo is present in DMNv1.3
    entry("MartitalStatus", "M"), entry("EmploymentStatus", "EMPLOYED"), entry("ExistingCustomer", false), entry("Monthly", mapOf(entry("Income", new BigDecimal(100_000)), entry("Repayments", new BigDecimal(2_500)), entry("Expenses", new BigDecimal(10_000))))));
    context.set("Bureau data", mapOf(entry("Bankrupt", false), entry("CreditScore", new BigDecimal(600))));
    context.set("Requested product", mapOf(entry("ProductType", "STANDARD LOAN"), entry("Rate", new BigDecimal(0.08)), entry("Term", new BigDecimal(36)), entry("Amount", new BigDecimal(100_000))));
    context.set("Supporting documents", null);
    final DMNResult dmnResult = evaluateModel(runtime, dmnModel, context);
    LOG.debug("{}", dmnResult);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("Strategy"), is("THROUGH"));
    assertThat(result.get("Routing"), is("ACCEPT"));
    if (isTypeSafe()) {
        FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult.getContext()).getFpa();
        Map<String, Object> allProperties = outputSet.allFEELProperties();
        assertThat(allProperties.get("Strategy"), is("THROUGH"));
        assertThat(allProperties.get("Routing"), is("ACCEPT"));
    }
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContextFPAImpl(org.kie.dmn.core.impl.DMNContextFPAImpl) FEELPropertyAccessible(org.kie.dmn.api.core.FEELPropertyAccessible) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) BaseVariantTest(org.kie.dmn.core.BaseVariantTest)

Example 22 with DMNContextFPAImpl

use of org.kie.dmn.core.impl.DMNContextFPAImpl in project drools by kiegroup.

the class DMN13specificTest method testDMNv1_3_simple.

@Test
public void testDMNv1_3_simple() {
    final DMNRuntime runtime = createRuntime("simple.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_9d01a0c4-f529-4ad8-ad8e-ec5fb5d96ad4", "Chapter 11 Example");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final DMNContext context = DMNFactory.newContext();
    context.set("name", "John");
    final DMNResult dmnResult = evaluateModel(runtime, dmnModel, context);
    LOG.debug("{}", dmnResult);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("salutation"), is("Hello, John"));
    if (isTypeSafe()) {
        FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult.getContext()).getFpa();
        Map<String, Object> allProperties = outputSet.allFEELProperties();
        assertThat(allProperties.get("salutation"), is("Hello, John"));
    }
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContextFPAImpl(org.kie.dmn.core.impl.DMNContextFPAImpl) FEELPropertyAccessible(org.kie.dmn.api.core.FEELPropertyAccessible) 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) BaseVariantTest(org.kie.dmn.core.BaseVariantTest)

Example 23 with DMNContextFPAImpl

use of org.kie.dmn.core.impl.DMNContextFPAImpl in project drools by kiegroup.

the class DMN13specificTest method testBKMencapsulatedlogictyperef.

@Test
public void testBKMencapsulatedlogictyperef() {
    final DMNRuntime runtime = createRuntime("bkmELTyperef.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_a49df6fc-c936-467a-9762-9aa3c9a93c06", "Drawing 1");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final DMNContext context = DMNFactory.newContext();
    final DMNResult dmnResult = evaluateModel(runtime, dmnModel, context);
    LOG.debug("{}", dmnResult);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("Decision1"), is(new BigDecimal("3")));
    if (isTypeSafe()) {
        FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult.getContext()).getFpa();
        Map<String, Object> allProperties = outputSet.allFEELProperties();
        assertThat(allProperties.get("Decision1"), is(new BigDecimal("3")));
    }
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContextFPAImpl(org.kie.dmn.core.impl.DMNContextFPAImpl) FEELPropertyAccessible(org.kie.dmn.api.core.FEELPropertyAccessible) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) BaseVariantTest(org.kie.dmn.core.BaseVariantTest)

Example 24 with DMNContextFPAImpl

use of org.kie.dmn.core.impl.DMNContextFPAImpl in project drools by kiegroup.

the class VariantTest method evaluateByNameTypeSafe.

private DMNResult evaluateByNameTypeSafe(DMNRuntime runtime, DMNModel dmnModel, DMNContext context, String... decisionNames) {
    Map<String, Object> inputMap = context.getAll();
    FEELPropertyAccessible outputSet;
    try {
        outputSet = createOutputSetInstance(dmnModel);
        outputSet.fromMap(inputMap);
        DMNContext contextFpa = new DMNContextFPAImpl(outputSet);
        DMNResult result = runtime.evaluateByName(dmnModel, contextFpa, decisionNames);
        return convertContext(result, createOutputSetInstance(dmnModel));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DMNContextFPAImpl(org.kie.dmn.core.impl.DMNContextFPAImpl) DMNResult(org.kie.dmn.api.core.DMNResult) FEELPropertyAccessible(org.kie.dmn.api.core.FEELPropertyAccessible) DMNContext(org.kie.dmn.api.core.DMNContext)

Example 25 with DMNContextFPAImpl

use of org.kie.dmn.core.impl.DMNContextFPAImpl in project drools by kiegroup.

the class VariantTest method evaluateDecisionServiceTypeSafe.

private DMNResult evaluateDecisionServiceTypeSafe(DMNRuntime runtime, DMNModel dmnModel, DMNContext context, String decisionServiceName) {
    Map<String, Object> inputMap = context.getAll();
    FEELPropertyAccessible outputSet;
    try {
        outputSet = createOutputSetInstance(dmnModel);
        outputSet.fromMap(inputMap);
        DMNContext contextFpa = new DMNContextFPAImpl(outputSet);
        DMNResult result = runtime.evaluateDecisionService(dmnModel, contextFpa, decisionServiceName);
        return convertContext(result, createOutputSetInstance(dmnModel));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DMNContextFPAImpl(org.kie.dmn.core.impl.DMNContextFPAImpl) DMNResult(org.kie.dmn.api.core.DMNResult) FEELPropertyAccessible(org.kie.dmn.api.core.FEELPropertyAccessible) DMNContext(org.kie.dmn.api.core.DMNContext)

Aggregations

DMNContext (org.kie.dmn.api.core.DMNContext)42 DMNContextFPAImpl (org.kie.dmn.core.impl.DMNContextFPAImpl)42 FEELPropertyAccessible (org.kie.dmn.api.core.FEELPropertyAccessible)41 DMNResult (org.kie.dmn.api.core.DMNResult)40 Test (org.junit.Test)36 DMNModel (org.kie.dmn.api.core.DMNModel)34 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)34 BaseVariantTest (org.kie.dmn.core.BaseVariantTest)31 DMNRuntimeTest (org.kie.dmn.core.DMNRuntimeTest)23 DMNDecisionServicesTest (org.kie.dmn.core.v1_2.DMNDecisionServicesTest)23 BigDecimal (java.math.BigDecimal)16 HashMap (java.util.HashMap)14 Map (java.util.Map)10 ArrayList (java.util.ArrayList)6 List (java.util.List)6 JsonMapper (com.fasterxml.jackson.databind.json.JsonMapper)3 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)3 FEELFunction (org.kie.dmn.feel.runtime.FEELFunction)3 Field (java.lang.reflect.Field)1 Duration (java.time.Duration)1