Search in sources :

Example 16 with ClassTypeResolver

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"));
}
Also used : ClassTypeResolver(org.drools.core.addon.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with ClassTypeResolver

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"));
}
Also used : ClassTypeResolver(org.drools.core.addon.ClassTypeResolver) TypeResolver(org.drools.core.addon.TypeResolver) ClassTypeResolver(org.drools.core.addon.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with ClassTypeResolver

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"));
}
Also used : ClassTypeResolver(org.drools.core.addon.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with ClassTypeResolver

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
    }
}
Also used : ClassTypeResolver(org.drools.core.addon.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with ClassTypeResolver

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
    }
}
Also used : ClassTypeResolver(org.drools.core.addon.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ClassTypeResolver (org.drools.core.addon.ClassTypeResolver)24 HashSet (java.util.HashSet)22 Test (org.junit.Test)16 TypeResolver (org.drools.core.addon.TypeResolver)6 MvelCompilerContext (org.drools.mvelcompiler.context.MvelCompilerContext)3 Gender (org.drools.Gender)2 Person (org.drools.Person)2 Cheese (org.drools.core.test.model.Cheese)2 FirstClass (org.drools.core.test.model.FirstClass)2 PackageModel (org.drools.modelcompiler.builder.PackageModel)2 Before (org.junit.Before)2 Map (java.util.Map)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 RuleUnitDescriptionLoader (org.drools.core.ruleunit.RuleUnitDescriptionLoader)1 SecondClass (org.drools.core.test.model.SecondClass)1 RuleContext (org.drools.modelcompiler.builder.generator.RuleContext)1 ConstraintCompiler (org.drools.mvelcompiler.ConstraintCompiler)1 MvelCompiler (org.drools.mvelcompiler.MvelCompiler)1