[jboss-cvs] JBossAS SVN: r95656 - projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 28 00:46:51 EDT 2009
Author: flavia.rainone at jboss.com
Date: 2009-10-28 00:46:51 -0400 (Wed, 28 Oct 2009)
New Revision: 95656
Modified:
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ClassPoolTest.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ClassPoolTestCase.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/JavassistTypeInfoTestCase.java
Log:
Filled in classpool and javassist type info test cases.
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ClassPoolTest.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ClassPoolTest.java 2009-10-28 04:44:21 UTC (rev 95655)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ClassPoolTest.java 2009-10-28 04:46:51 UTC (rev 95656)
@@ -24,10 +24,14 @@
import java.util.HashMap;
import java.util.Map;
+import javassist.ClassPool;
+import javassist.CtClass;
+
+import org.jboss.classpool.spi.ClassPoolRepository;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
+import org.jboss.reflect.spi.TypeInfoFactory;
import org.jboss.virtual.VirtualFile;
-import org.jboss.reflect.spi.TypeInfoFactory;
-import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
/**
* Abstract test for ClassPool.
@@ -64,7 +68,21 @@
DeploymentUnit unit = assertDeploy(file);
try
{
- // TODO - actually test *just* classpools
+ for (Map.Entry<Class<?>, String> entry : classes.entrySet())
+ {
+ DeploymentUnit du = getDeploymentUnit(unit, entry.getValue());
+ ClassLoader classLoader = getClassLoader(du);
+ Class<?> clazz = entry.getKey();
+ String className = clazz.getName();
+ // sanity check
+ Class<?> loadedClass = assertLoadClass(className, classLoader);
+ ClassPoolRepository repository = ClassPoolRepository.getInstance();
+ ClassPool classPool = repository.registerClassLoader(classLoader);
+ CtClass ctClass = classPool.getCtClass(className);
+ assertEquals(className, clazz.getName());
+ ClassLoader cl = ctClass.getClassPool().getClassLoader();
+ assertEquals(loadedClass.getClassLoader(), cl);
+ }
}
finally
{
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ClassPoolTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ClassPoolTestCase.java 2009-10-28 04:44:21 UTC (rev 95655)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ClassPoolTestCase.java 2009-10-28 04:46:51 UTC (rev 95656)
@@ -25,8 +25,16 @@
import java.util.HashMap;
import java.util.Map;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtMethod;
import junit.framework.Test;
+
+import org.jboss.classpool.spi.ClassPoolRepository;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
import org.jboss.test.deployers.vfs.reflect.support.crm.CrmFacade;
import org.jboss.test.deployers.vfs.reflect.support.ejb.MySLSBean;
import org.jboss.test.deployers.vfs.reflect.support.ext.External;
@@ -114,16 +122,23 @@
assertClassPool(directory, PlainJavaBean.class);
}
- /**
- * FIXME -- classpools issue?
- */
public void testHierarchyCLUsage() throws Exception
{
AssembledDirectory directory = createBasicEar();
DeploymentUnit unit = assertDeploy(directory);
try
{
- // TODO - test just classpools
+ DeploymentUnit child = getDeploymentUnit(unit, "simple.war");
+ ClassLoader cl = getClassLoader(child);
+ ClassPoolRepository repository = ClassPoolRepository.getInstance();
+ ClassPool classPool = repository.registerClassLoader(cl);
+ CtClass ctClass = classPool.getCtClass(AnyServlet.class.getName());
+ CtMethod ctMethod = ctClass.getDeclaredMethod("getBean");
+ assertNotNull("No such 'getBean' method on " + ctClass, ctMethod);
+ CtClass returnCtClass = ctMethod.getReturnType();
+ classPool = repository.registerClassLoader(getClassLoader(unit));
+ CtClass returnCtClass2 = classPool.getCtClass(PlainJavaBean.class.getName());
+ assertSame(returnCtClass, returnCtClass2);
}
finally
{
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/JavassistTypeInfoTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/JavassistTypeInfoTestCase.java 2009-10-28 04:44:21 UTC (rev 95655)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/JavassistTypeInfoTestCase.java 2009-10-28 04:46:51 UTC (rev 95656)
@@ -22,8 +22,16 @@
package org.jboss.test.deployers.vfs.reflect.test;
import junit.framework.Test;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.reflect.spi.TypeInfo;
import org.jboss.reflect.spi.TypeInfoFactory;
+import org.jboss.test.deployers.vfs.classpool.support.jar.PlainJavaBean;
+import org.jboss.test.deployers.vfs.classpool.support.web.AnyServlet;
+import org.jboss.virtual.AssembledDirectory;
/**
* Javassist test case for TypeInfo.
@@ -52,6 +60,37 @@
@Override
public void testHierarchyCLUsage() throws Exception
{
- // FIXME -- fix Classpool's hierarchy usage
+ AssembledDirectory directory = createBasicEar();
+ DeploymentUnit unit = assertDeploy(directory);
+ try
+ {
+ TypeInfoFactory typeInfoFactory = new JavassistTypeInfoFactory();
+ DeploymentUnit child = getDeploymentUnit(unit, "simple.war");
+ ClassLoader cl = getClassLoader(child);
+
+ try
+ {
+ cl.loadClass(PlainJavaBean.class.getName());
+ } catch (ClassNotFoundException e) {}
+
+
+ ClassLoader cl1 = getClassLoader(unit);
+ try
+ {
+ cl1.loadClass(PlainJavaBean.class.getName());
+ } catch (ClassNotFoundException e) {}
+
+ TypeInfo ti = typeInfoFactory.getTypeInfo(AnyServlet.class.getName(), cl);
+ ClassInfo ci = assertInstanceOf(ti, ClassInfo.class);
+ MethodInfo mi = ci.getDeclaredMethod("getBean");
+ assertNotNull("No such 'getBean' method on " + ci, mi);
+ TypeInfo rt = mi.getReturnType();
+ TypeInfo cti = typeInfoFactory.getTypeInfo(PlainJavaBean.class.getName(), getClassLoader(unit));
+ assertSame(rt, cti);
+ }
+ finally
+ {
+ undeploy(unit);
+ }
}
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list