use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class CompilerTest method test.
default void test(Consumer<MvelCompilerContext> testFunction, String inputExpression, String expectedResult, Consumer<CompiledBlockResult> resultAssert) {
Set<String> imports = new HashSet<>();
imports.add("java.util.List");
imports.add("java.util.ArrayList");
imports.add("java.util.HashMap");
imports.add("java.util.Map");
imports.add("java.math.BigDecimal");
imports.add("org.drools.Address");
imports.add(Person.class.getCanonicalName());
imports.add(Gender.class.getCanonicalName());
TypeResolver typeResolver = new ClassTypeResolver(imports, this.getClass().getClassLoader());
MvelCompilerContext mvelCompilerContext = new MvelCompilerContext(typeResolver);
testFunction.accept(mvelCompilerContext);
CompiledBlockResult compiled = new MvelCompiler(mvelCompilerContext).compileStatement(inputExpression);
verifyBodyWithBetterDiff(expectedResult, compiled.resultAsString());
resultAssert.accept(compiled);
}
use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class ConstraintCompilerTest method testExpression.
public void testExpression(Consumer<MvelCompilerContext> testFunction, String inputExpression, String expectedResult, Consumer<CompiledExpressionResult> resultAssert) {
Set<String> imports = new HashSet<>();
imports.add("java.util.List");
imports.add("java.util.ArrayList");
imports.add("java.util.HashMap");
imports.add("java.util.Map");
imports.add("java.math.BigDecimal");
imports.add("org.drools.Address");
imports.add(Person.class.getCanonicalName());
imports.add(Gender.class.getCanonicalName());
TypeResolver typeResolver = new ClassTypeResolver(imports, this.getClass().getClassLoader());
MvelCompilerContext mvelCompilerContext = new MvelCompilerContext(typeResolver);
testFunction.accept(mvelCompilerContext);
CompiledExpressionResult compiled = new ConstraintCompiler(mvelCompilerContext).compileExpression(inputExpression);
verifyBodyWithBetterDiff(expectedResult, compiled.resultAsString());
resultAssert.accept(compiled);
}
use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class KnowledgePackageImpl method setClassLoader.
public void setClassLoader(ClassLoader classLoader) {
if (typeResolver != null && typeResolver.getClassLoader() == classLoader) {
return;
}
this.typeResolver = new ClassTypeResolver(new HashSet<>(getImports().keySet()), classLoader, getName());
typeResolver.addImport(getName() + ".*");
for (String implicitImport : getImplicitImports()) {
typeResolver.addImplicitImport(implicitImport);
}
this.ruleUnitDescriptionLoader = new RuleUnitDescriptionLoader(this);
}
use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testResolveArrayOfObjectsFromImport.
@Test
public void testResolveArrayOfObjectsFromImport() throws Exception {
final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
resolver.addImport("org.drools.core.test.model.Cheese");
assertEquals(String[].class, resolver.resolveType("String[]"));
assertEquals(String[].class, resolver.resolveType("java.lang.String[]"));
assertEquals(Cheese[].class, resolver.resolveType("Cheese[]"));
assertEquals(Cheese[].class, resolver.resolveType("org.drools.core.test.model.Cheese[]"));
}
use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testResolveArrayOfPrimitiveTypes.
@Test
public void testResolveArrayOfPrimitiveTypes() throws Exception {
final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
assertEquals(boolean[].class, resolver.resolveType("boolean[]"));
assertEquals(double[].class, resolver.resolveType("double[]"));
assertEquals(float[].class, resolver.resolveType("float[]"));
assertEquals(int[].class, resolver.resolveType("int[]"));
assertEquals(char[].class, resolver.resolveType("char[]"));
assertEquals(long[].class, resolver.resolveType("long[]"));
assertEquals(byte[].class, resolver.resolveType("byte[]"));
assertEquals(short[].class, resolver.resolveType("short[]"));
}
Aggregations