Search in sources :

Example 6 with FEELPropertyAccessible

use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.

the class DMNRuntimeTypesTest method testComponentCollectionPassTypedObject.

@Test
public void testComponentCollectionPassTypedObject() {
    final DMNRuntime runtime = createRuntime("collectionsPassTypedObject.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://kiegroup.org/dmn/_10C4DB2B-1DCA-4B4F-A994-FA046AE5C7B0", "collectionsPassTypedObject");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final DMNContext context = DMNFactory.newContext();
    final Map<String, Object> addr1 = prototype(entry("city", "city1"), entry("street", "street1"));
    final Map<String, Object> addr2 = prototype(entry("city", "city2"), entry("street", "street2"));
    final Map<String, Object> person = prototype(entry("name", "John"), entry("addressList", Arrays.asList(addr1, addr2)));
    context.set("inputPerson", person);
    final DMNResult dmnResult = evaluateModel(runtime, dmnModel, context);
    assertThat(dmnResult.hasErrors(), is(false));
    if (isTypeSafe()) {
        FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult.getContext()).getFpa();
        Map<String, Object> allProperties = outputSet.allFEELProperties();
        FEELPropertyAccessible typedOutputPerson = (FEELPropertyAccessible) allProperties.get("outputPerson");
        assertThat(typedOutputPerson.getClass().getSimpleName(), is("TPerson"));
        assertThat(typedOutputPerson.getFEELProperty("name").toOptional().get(), is("Paul"));
        List<FEELPropertyAccessible> addressList = (List<FEELPropertyAccessible>) typedOutputPerson.getFEELProperty("addressList").toOptional().get();
        FEELPropertyAccessible typedOutputAddr1 = addressList.get(0);
        FEELPropertyAccessible typedOutputAddr2 = addressList.get(1);
        assertThat(typedOutputAddr1.getFEELProperty("city").toOptional().get(), anyOf(is("city1"), is("city2")));
        assertThat(typedOutputAddr1.getFEELProperty("street").toOptional().get(), anyOf(is("street1"), is("street2")));
        assertThat(typedOutputAddr2.getFEELProperty("city").toOptional().get(), anyOf(is("city1"), is("city2")));
        assertThat(typedOutputAddr2.getFEELProperty("street").toOptional().get(), anyOf(is("street1"), is("street2")));
    } else {
        Map<String, Object> outputPerson = (Map<String, Object>) dmnResult.getContext().get("outputPerson");
        assertThat(outputPerson.get("name"), is("Paul"));
        Map<String, Object> outputAddr1 = (Map<String, Object>) ((List) outputPerson.get("addressList")).get(0);
        Map<String, Object> outputAddr2 = (Map<String, Object>) ((List) outputPerson.get("addressList")).get(1);
        assertThat(outputAddr1.get("city"), anyOf(is("city1"), is("city2")));
        assertThat(outputAddr1.get("street"), anyOf(is("street1"), is("street2")));
        assertThat(outputAddr2.get("city"), anyOf(is("city1"), is("city2")));
        assertThat(outputAddr2.get("street"), anyOf(is("street1"), is("street2")));
    }
}
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) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) BaseVariantTest(org.kie.dmn.core.BaseVariantTest) DMNRuntimeTest(org.kie.dmn.core.DMNRuntimeTest) Test(org.junit.Test) DMNDecisionServicesTest(org.kie.dmn.core.v1_2.DMNDecisionServicesTest)

Example 7 with FEELPropertyAccessible

use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.

the class DMNRuntimeTypesTest method testSameTypeNameMultiple.

@Test
public void testSameTypeNameMultiple() {
    final DMNRuntime runtime = createRuntimeWithAdditionalResources("class_imported.dmn", this.getClass(), "class_importing.dmn");
    final DMNModel dmnModel0 = runtime.getModel("http://www.trisotech.com/definitions/_b3deed2b-245f-4cc4-a4bf-1e95cd240664", "imported");
    assertThat(dmnModel0, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel0.getMessages()), dmnModel0.hasErrors(), is(false));
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_17540606-3d41-40f4-85f6-ad9e8faa8a87", "importing");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final DMNContext context = DMNFactory.newContext();
    Map<String, Object> importedClass = mapOf(entry("L1name", "L1name"), entry("class", mapOf(entry("L2name", "L2name"))));
    context.set("imported class", importedClass);
    Map<String, Object> class_ = mapOf(entry("name", "name"));
    context.set("class", class_);
    final DMNResult dmnResult = evaluateModel(runtime, dmnModel, context);
    LOG.debug("{}", dmnResult);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    assertThat(dmnResult.getDecisionResultByName("decision1").getResult(), is("L1nameL2namename"));
    if (isTypeSafe()) {
        FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult.getContext()).getFpa();
        Map<String, Object> allProperties = outputSet.allFEELProperties();
        assertThat(allProperties.get("decision1"), is("L1nameL2namename"));
    }
}
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) BaseVariantTest(org.kie.dmn.core.BaseVariantTest) DMNRuntimeTest(org.kie.dmn.core.DMNRuntimeTest) Test(org.junit.Test) DMNDecisionServicesTest(org.kie.dmn.core.v1_2.DMNDecisionServicesTest)

Example 8 with FEELPropertyAccessible

use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.

the class DMNRuntimeTypesTest method testCapitalLetterConflictWithInputAndDecision.

@Test
public void testCapitalLetterConflictWithInputAndDecision() {
    final DMNRuntime runtime = createRuntime("capitalLetterConflictWithInputAndDecision.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://kiegroup.org/dmn/_EE9DAFC0-D50D-4D23-8676-FF8A40E02919", "capitalLetterConflictWithInputAndDecision");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final Map<String, Object> person = new HashMap<>();
    person.put("name", "John");
    person.put("age", 28);
    final DMNContext context = DMNFactory.newContext();
    context.set("myNode", person);
    final DMNResult dmnResult = evaluateModel(runtime, dmnModel, context);
    assertThat(dmnResult.hasErrors(), is(false));
    assertThat(dmnResult.getContext().get("MyNode"), is("MyNode is John"));
    if (isTypeSafe()) {
        FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult.getContext()).getFpa();
        Map<String, Object> allProperties = outputSet.allFEELProperties();
        FEELPropertyAccessible myPersonOut = (FEELPropertyAccessible) allProperties.get("myNode");
        assertThat(myPersonOut.getClass().getSimpleName(), is("TPerson"));
        assertThat(myPersonOut.getFEELProperty("name").toOptional().get(), is("John"));
        assertThat(EvalHelper.coerceNumber(myPersonOut.getFEELProperty("age").toOptional().get()), is(EvalHelper.coerceNumber(28)));
        Object myDecision = (String) allProperties.get("MyNode");
        assertThat(myDecision, is("MyNode is John"));
    }
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContextFPAImpl(org.kie.dmn.core.impl.DMNContextFPAImpl) FEELPropertyAccessible(org.kie.dmn.api.core.FEELPropertyAccessible) HashMap(java.util.HashMap) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) BaseVariantTest(org.kie.dmn.core.BaseVariantTest) DMNRuntimeTest(org.kie.dmn.core.DMNRuntimeTest) Test(org.junit.Test) DMNDecisionServicesTest(org.kie.dmn.core.v1_2.DMNDecisionServicesTest)

Example 9 with FEELPropertyAccessible

use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.

the class DMNRuntimeTypesTest method testCapitalLetterConflict.

@Test
public void testCapitalLetterConflict() {
    final DMNRuntime runtime = createRuntime("capitalLetterConflict.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://kiegroup.org/dmn/_B321C9B1-856E-45DE-B05D-5B4D4D301D37", "capitalLetterConflict");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final Map<String, Object> myPerson = new HashMap<>();
    myPerson.put("name", "John");
    myPerson.put("age", 28);
    final Map<String, Object> myPersonCapital = new HashMap<>();
    myPersonCapital.put("name", "Paul");
    myPersonCapital.put("age", 26);
    final DMNContext context = DMNFactory.newContext();
    context.set("myPerson", myPerson);
    context.set("MyPerson", myPersonCapital);
    final DMNResult dmnResult = evaluateModel(runtime, dmnModel, context);
    assertThat(dmnResult.hasErrors(), is(false));
    assertThat(dmnResult.getContext().get("myDecision"), is("myDecision is John"));
    assertThat(dmnResult.getContext().get("MyDecision"), is("MyDecision is Paul"));
    if (isTypeSafe()) {
        FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult.getContext()).getFpa();
        Map<String, Object> allProperties = outputSet.allFEELProperties();
        FEELPropertyAccessible myPersonOut = (FEELPropertyAccessible) allProperties.get("myPerson");
        assertThat(myPersonOut.getClass().getSimpleName(), is("TPerson"));
        assertThat(myPersonOut.getFEELProperty("name").toOptional().get(), is("John"));
        assertThat(EvalHelper.coerceNumber(myPersonOut.getFEELProperty("age").toOptional().get()), is(EvalHelper.coerceNumber(28)));
        FEELPropertyAccessible myPersonCapitalOut = (FEELPropertyAccessible) allProperties.get("MyPerson");
        assertThat(myPersonCapitalOut.getClass().getSimpleName(), is("TPerson"));
        assertThat(myPersonCapitalOut.getFEELProperty("name").toOptional().get(), is("Paul"));
        assertThat(EvalHelper.coerceNumber(myPersonCapitalOut.getFEELProperty("age").toOptional().get()), is(EvalHelper.coerceNumber(26)));
        Object myDecision = (String) allProperties.get("myDecision");
        assertThat(myDecision, is("myDecision is John"));
        Object myDecisionCapital = (String) allProperties.get("MyDecision");
        assertThat(myDecisionCapital, is("MyDecision is Paul"));
    }
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContextFPAImpl(org.kie.dmn.core.impl.DMNContextFPAImpl) FEELPropertyAccessible(org.kie.dmn.api.core.FEELPropertyAccessible) HashMap(java.util.HashMap) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) BaseVariantTest(org.kie.dmn.core.BaseVariantTest) DMNRuntimeTest(org.kie.dmn.core.DMNRuntimeTest) Test(org.junit.Test) DMNDecisionServicesTest(org.kie.dmn.core.v1_2.DMNDecisionServicesTest)

Example 10 with FEELPropertyAccessible

use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.

the class DMNRuntimeTypesTest method testInputAny.

@Test
public void testInputAny() {
    final DMNRuntime runtime = createRuntime("inputAny.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://kiegroup.org/dmn/_7D9140EF-DC52-4DC1-8983-9C2EC5B89BAE", "new-file");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final DMNContext context = DMNFactory.newContext();
    context.set("Input Any", "John Doe");
    final DMNResult dmnResult = evaluateModel(runtime, dmnModel, context);
    LOG.debug("{}", dmnResult);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    assertThat(dmnResult.getDecisionResultByName("Decision-1").getResult(), is("Decision: John Doe"));
    if (isTypeSafe()) {
        FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult.getContext()).getFpa();
        Map<String, Object> allProperties = outputSet.allFEELProperties();
        assertThat(allProperties.get("Decision-1"), is("Decision: John Doe"));
    }
}
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) BaseVariantTest(org.kie.dmn.core.BaseVariantTest) DMNRuntimeTest(org.kie.dmn.core.DMNRuntimeTest) Test(org.junit.Test) DMNDecisionServicesTest(org.kie.dmn.core.v1_2.DMNDecisionServicesTest)

Aggregations

FEELPropertyAccessible (org.kie.dmn.api.core.FEELPropertyAccessible)44 DMNContext (org.kie.dmn.api.core.DMNContext)41 DMNContextFPAImpl (org.kie.dmn.core.impl.DMNContextFPAImpl)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