Search in sources :

Example 21 with ClassTypeResolver

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"));
}
Also used : ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with ClassTypeResolver

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"));
}
Also used : ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with ClassTypeResolver

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
    }
}
Also used : ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with ClassTypeResolver

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"));
}
Also used : ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with ClassTypeResolver

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"));
}
Also used : ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)28 Test (org.junit.Test)21 HashSet (java.util.HashSet)19 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)9 FactAssignmentField (org.drools.workbench.models.testscenarios.shared.FactAssignmentField)3 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)3 KieSession (org.kie.api.runtime.KieSession)3 HashMap (java.util.HashMap)2 Cheese (org.drools.core.test.model.Cheese)2 FirstClass (org.drools.core.test.model.FirstClass)2 Mouse (org.drools.workbench.models.testscenarios.backend.Mouse)2 FactData (org.drools.workbench.models.testscenarios.shared.FactData)2 Before (org.junit.Before)2 Date (java.util.Date)1 ClassFieldAccessorCache (org.drools.core.base.ClassFieldAccessorCache)1 InternalAgendaGroup (org.drools.core.common.InternalAgendaGroup)1 ProjectClassLoader (org.drools.core.common.ProjectClassLoader)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1