use of org.kie.soup.project.datamodel.commons.types.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.kie.soup.project.datamodel.commons.types.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testResolvePrimtiveTypes.
@Test
public void testResolvePrimtiveTypes() 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"));
}
use of org.kie.soup.project.datamodel.commons.types.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
}
}
use of org.kie.soup.project.datamodel.commons.types.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.kie.soup.project.datamodel.commons.types.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testResolveObjectNotFromImport.
@Test
public void testResolveObjectNotFromImport() 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