use of org.kie.dmn.typesafe.DMNAllTypesIndex in project drools by kiegroup.
the class VariantTest method createTypeSafeInput.
private void createTypeSafeInput(DMNRuntime runtime) {
String prefix = String.format("%s%s", testName, testConfig.name());
factory = new DMNTypeSafePackageName.ModelFactory(prefix);
DMNAllTypesIndex index = new DMNAllTypesIndex(factory, runtime.getModels().toArray(new DMNModel[] {}));
allSources = new HashMap<>();
for (DMNModel m : runtime.getModels()) {
Map<String, String> allTypesSourceCode = new DMNTypeSafeTypeGenerator(m, index, factory).withJacksonAnnotation().withMPAnnotation().withIOSwaggerOASv3().processTypes().generateSourceCodeOfAllTypes();
allSources.putAll(allTypesSourceCode);
}
if (!allSources.isEmpty()) {
allCompiledClasses = KieMemoryCompiler.compile(allSources, this.getClass().getClassLoader());
}
}
use of org.kie.dmn.typesafe.DMNAllTypesIndex in project drools by kiegroup.
the class DMNTypeSafeTest method generateSourceCodeAndCreateInput.
public static Map<String, Class<?>> generateSourceCodeAndCreateInput(DMNModel dmnModel, DMNTypeSafePackageName.ModelFactory packageName, ClassLoader classLoader) {
DMNAllTypesIndex index = new DMNAllTypesIndex(packageName, dmnModel);
Map<String, String> allTypesSourceCode = new DMNTypeSafeTypeGenerator(dmnModel, index, packageName).processTypes().generateSourceCodeOfAllTypes();
return KieMemoryCompiler.compile(allTypesSourceCode, classLoader);
}
use of org.kie.dmn.typesafe.DMNAllTypesIndex 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));
}
Aggregations