use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.
the class DMNRuntimeTypesTest method testInnerCompositeCollection.
@Test
public void testInnerCompositeCollection() {
final DMNRuntime runtime = createRuntime("innerCompositeCollection.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("https://kiegroup.org/dmn/_D8AE5AF4-1F9E-4423-873A-B8F3C3BE5FE5", "new-file");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
final DMNContext context = DMNFactory.newContext();
List<?> pairs = Arrays.asList(mapOf(entry("letter", "A"), entry("num", new BigDecimal(1))), mapOf(entry("letter", "B"), entry("num", new BigDecimal(2))), mapOf(entry("letter", "C"), entry("num", new BigDecimal(3))));
Map<String, Object> person = mapOf(entry("full name", "John Doe"), entry("pairs", pairs));
context.set("person", person);
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("John Doe has 3 pairs."));
if (isTypeSafe()) {
FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult.getContext()).getFpa();
Map<String, Object> allProperties = outputSet.allFEELProperties();
assertThat(allProperties.get("Decision-1"), is("John Doe has 3 pairs."));
}
}
use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.
the class DMNTypeSafeTest method test.
@Test
public void test() throws Exception {
assertValidDmnModel(dmnModel);
DMNAllTypesIndex index = new DMNAllTypesIndex(new DMNTypeSafePackageName.ModelFactory(), dmnModel);
Map<String, String> allTypesSourceCode = new DMNTypeSafeTypeGenerator(dmnModel, index, modelFactory).processTypes().generateSourceCodeOfAllTypes();
ClassLoader thisDMNClassLoader = this.getClass().getClassLoader();
Map<String, Class<?>> compiledClasses = KieMemoryCompiler.compile(allTypesSourceCode, thisDMNClassLoader);
FEELPropertyAccessible street1 = tAddress(compiledClasses, "Street1", 1);
FEELPropertyAccessible street2 = tAddress(compiledClasses, "Street2", 2);
FEELPropertyAccessible tPersonInstance = tPerson(compiledClasses, asList(street1, street2));
FEELPropertyAccessible context = outputSet(compiledClasses, tPersonInstance);
DMNResult evaluateAll = evaluateTyped(context, runtime, dmnModel);
convertContext(evaluateAll, createInstanceFromCompiledClasses(compiledClasses, packageName, "OutputSet"));
DMNContext result = evaluateAll.getContext();
Map<String, Object> d = (Map<String, Object>) result.get("d");
assertThat(d.get("Hello"), is("Hello Mr. x"));
FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) result).getFpa();
assertThat(outputSet.getFEELProperty("p").toOptional().get(), equalTo(tPersonInstance));
Map<String, Object> dContext = (Map<String, Object>) outputSet.getFEELProperty("d").toOptional().get();
assertThat(dContext.get("Hello"), is("Hello Mr. x"));
assertThat(dContext.get("the person"), equalTo(tPersonInstance));
}
use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.
the class DMNTypeSafeTest method tAddress.
private FEELPropertyAccessible tAddress(Map<String, Class<?>> compile, String streetName, int streetNumber) throws Exception {
FEELPropertyAccessible feelPropertyAccessible = createInstanceFromCompiledClasses(compile, packageName, "TAddress");
feelPropertyAccessible.setFEELProperty("streetName", streetName);
feelPropertyAccessible.setFEELProperty("streetNumber", streetNumber);
return feelPropertyAccessible;
}
use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.
the class DMNTypeSafeTest method tPerson.
private FEELPropertyAccessible tPerson(Map<String, Class<?>> compile, List<FEELPropertyAccessible> addresses) throws Exception {
FEELPropertyAccessible feelPropertyAccessible = createInstanceFromCompiledClasses(compile, packageName, "TPerson");
feelPropertyAccessible.setFEELProperty("name", "Mr. x");
feelPropertyAccessible.setFEELProperty("addresses", addresses);
return feelPropertyAccessible;
}
use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.
the class DMNTypeSafeTest method outputSet.
private FEELPropertyAccessible outputSet(Map<String, Class<?>> compile, FEELPropertyAccessible tPersonInstance) throws Exception {
FEELPropertyAccessible feelPropertyAccessible = createInstanceFromCompiledClasses(compile, packageName, "OutputSet");
feelPropertyAccessible.setFEELProperty("p", tPersonInstance);
return feelPropertyAccessible;
}
Aggregations