Search in sources :

Example 6 with ClassTypeResolver

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

Example 7 with ClassTypeResolver

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

Example 8 with ClassTypeResolver

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

Example 9 with ClassTypeResolver

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

Example 10 with ClassTypeResolver

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[][]"));
}
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