use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testResolveObjectFromImportMultipleClassesDifferentPackages.
@Test
public void testResolveObjectFromImportMultipleClassesDifferentPackages() 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 testResolveFullTypeName.
@Test
public void testResolveFullTypeName() throws Exception {
final TypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
resolver.addImport("org.drools.core.test.model.Cheese");
resolver.addImport("org.drools.core.test.model.FirstClass");
assertEquals("org.drools.core.test.model.Cheese", resolver.getFullTypeName("Cheese"));
assertEquals("org.drools.core.test.model.FirstClass", resolver.getFullTypeName("FirstClass"));
}
use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testNestedClassResolving.
@Test
public void testNestedClassResolving() throws Exception {
final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
// single nesting
resolver.addImport("org.drools.core.test.model.Person.Nested1");
assertEquals(org.drools.core.test.model.Person.Nested1.class, resolver.resolveType("Nested1"));
// double nesting
resolver.addImport("org.drools.core.test.model.Person.Nested1.Nested2");
assertEquals(org.drools.core.test.model.Person.Nested1.Nested2.class, resolver.resolveType("Nested2"));
// triple nesting
resolver.addImport("org.drools.core.test.model.Person.Nested1.Nested2.Nested3");
assertEquals(org.drools.core.test.model.Person.Nested1.Nested2.Nested3.class, resolver.resolveType("Nested3"));
}
use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testDefaultPackageImport.
@Test
public void testDefaultPackageImport() throws Exception {
final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
resolver.addImport("Goo");
try {
resolver.resolveType("Goo");
fail("Can't import default namespace classes");
} catch (ClassNotFoundException e) {
// swallow as this should be thrown
}
}
use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testMacOSXClassLoaderBehavior.
@Test
public void testMacOSXClassLoaderBehavior() throws Exception {
SimulateMacOSXClassLoader simulatedMacOSXClassLoader = new SimulateMacOSXClassLoader(Thread.currentThread().getContextClassLoader(), new HashSet());
simulatedMacOSXClassLoader.addClassInScope(org.drools.core.test.model.Cheese.class);
final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), simulatedMacOSXClassLoader);
resolver.addImport("org.drools.core.test.model.*");
assertEquals(org.drools.core.test.model.Cheese.class, resolver.resolveType("Cheese"));
try {
// <<- on Mac/OSX throws NoClassDefFoundError which escapes the try/catch and fail the test.
resolver.resolveType("cheese");
// while on say Linux, it passes the test (catched as ClassNotFoundException)
fail("the type cheese (lower-case c) should not exists at all");
} catch (ClassNotFoundException e) {
// swallow as this should be thrown
}
}
Aggregations