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"));
}
}
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"));
}
}
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"));
}
}
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"));
}
}
use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.
the class DMNRuntimeTypesTest method testDecisionService.
@Test
public void testDecisionService() {
final DMNRuntime runtime = createRuntime("DecisionServiceABC_DMN12.dmn", DMNDecisionServicesTest.class);
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_2443d3f5-f178-47c6-a0c9-b1fd1c933f60", "Drawing 1");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
// DecisionService only
final DMNContext context = DMNFactory.newContext();
final DMNResult dmnResult1 = evaluateDecisionService(runtime, dmnModel, context, "Decision Service ABC");
LOG.debug("{}", dmnResult1);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult1.getMessages()), dmnResult1.hasErrors(), is(false));
final DMNContext result = dmnResult1.getContext();
// assertThat(result.getAll(), not(hasEntry(is("Invoking Decision"), anything()))); // we invoked only the Decision Service, not this other Decision in the model.
assertThat(result.get("Invoking Decision"), nullValue());
assertThat(result.get("ABC"), is("abc"));
if (isTypeSafe()) {
FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult1.getContext()).getFpa();
Map<String, Object> allProperties = outputSet.allFEELProperties();
assertThat(allProperties.get("Invoking Decision"), nullValue());
Object abc = allProperties.get("ABC");
assertThat(abc, instanceOf(String.class));
assertThat(abc, is("abc"));
}
// evaluateAll
final DMNContext context2 = DMNFactory.newContext();
final DMNResult dmnResult2 = evaluateModel(runtime, dmnModel, context2);
LOG.debug("{}", dmnResult2);
dmnResult2.getDecisionResults().forEach(x -> LOG.debug("{}", x));
assertThat(DMNRuntimeUtil.formatMessages(dmnResult2.getMessages()), dmnResult2.hasErrors(), is(false));
final DMNContext result2 = dmnResult2.getContext();
assertThat(result2.get("ABC"), is("abc"));
assertThat(result2.get("Invoking Decision"), is("abc"));
if (isTypeSafe()) {
FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult2.getContext()).getFpa();
Map<String, Object> allProperties = outputSet.allFEELProperties();
Object decisionService = allProperties.get("Decision Service ABC");
assertThat(decisionService, instanceOf(FEELFunction.class));
assertThat(((FEELFunction) decisionService).getName(), is("Decision Service ABC"));
Object invokingDecision = allProperties.get("Invoking Decision");
assertThat(invokingDecision, instanceOf(String.class));
assertThat(invokingDecision, is("abc"));
Object abc = allProperties.get("ABC");
assertThat(abc, instanceOf(String.class));
assertThat(abc, is("abc"));
}
}
Aggregations