use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testResolveObjectFromImport.
@Test
public void testResolveObjectFromImport() throws Exception {
final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
resolver.addImport("org.drools.core.test.model.Cheese");
resolver.addImport("org.drools.core.test.model.FirstClass");
resolver.addImport("org.drools.core.test.model.FirstClass.AlternativeKey");
resolver.addImport("org.drools.core.test.model.SecondClass");
resolver.addImport("org.drools.core.test.model.SecondClass.AlternativeKey");
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"));
assertEquals(FirstClass.class, resolver.resolveType("org.drools.core.test.model.FirstClass"));
assertEquals(FirstClass.AlternativeKey.class, resolver.resolveType("org.drools.core.test.model.FirstClass.AlternativeKey"));
assertEquals(SecondClass.class, resolver.resolveType("org.drools.core.test.model.SecondClass"));
assertEquals(SecondClass.AlternativeKey.class, resolver.resolveType("org.drools.core.test.model.SecondClass.AlternativeKey"));
}
use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testResolveObjectFromImportNested.
@Test
public void testResolveObjectFromImportNested() throws Exception {
final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
resolver.addImport("org.drools.core.test.model.FirstClass");
assertEquals(FirstClass.AlternativeKey.class, resolver.resolveType("FirstClass.AlternativeKey"));
}
use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testMacOSXClassLoaderBehaviorNested.
@Test
public void testMacOSXClassLoaderBehaviorNested() throws Exception {
SimulateMacOSXClassLoader simulatedMacOSXClassLoader = new SimulateMacOSXClassLoader(Thread.currentThread().getContextClassLoader(), new HashSet());
simulatedMacOSXClassLoader.addClassInScope(org.drools.core.test.model.Person.Nested1.Nested2.class);
final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), simulatedMacOSXClassLoader);
resolver.addImport("org.drools.core.test.model.*");
assertEquals(org.drools.core.test.model.Person.Nested1.Nested2.class, resolver.resolveType("Person.Nested1.Nested2"));
try {
// <<- on Mac/OSX throws NoClassDefFoundError which escapes the try/catch and fail the test.
resolver.resolveType("Person.nested1.nested2");
// while on say Linux, it passes the test (catched as ClassNotFoundException)
fail("should have resolved nothing.");
} 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 testResolveMultidimensionnalArrayOfObjectsFromImport.
@Test
public void testResolveMultidimensionnalArrayOfObjectsFromImport() 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 testResolveMultidimensionnalArrayOfObjectsNotFromImport.
@Test
public void testResolveMultidimensionnalArrayOfObjectsNotFromImport() throws Exception {
final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
assertEquals(String[][].class, resolver.resolveType("String[][]"));
assertEquals(String[][].class, resolver.resolveType("java.lang.String[][]"));
try {
assertEquals(Cheese[][].class, resolver.resolveType("Cheese[][]"));
fail("Should raise a ClassNotFoundException");
} catch (final ClassNotFoundException e) {
// success
}
assertEquals(Cheese[][].class, resolver.resolveType("org.drools.core.test.model.Cheese[][]"));
}
Aggregations