[jboss-cvs] JBossAS SVN: r95697 - 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 13:18:03 EDT 2009
Author: alesj
Date: 2009-10-28 13:18:03 -0400 (Wed, 28 Oct 2009)
New Revision: 95697
Modified:
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ReflectTest.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/TypeInfoTest.java
Log:
Add more CL use cases.
TODO for Flavia - fix isolated usage for JavassistTIF.
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ReflectTest.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ReflectTest.java 2009-10-28 17:14:14 UTC (rev 95696)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ReflectTest.java 2009-10-28 17:18:03 UTC (rev 95697)
@@ -28,8 +28,13 @@
import org.jboss.classloader.plugins.jdk.AbstractJDKChecker;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataFactoryVisitor;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
import org.jboss.reflect.spi.TypeInfo;
import org.jboss.reflect.spi.TypeInfoFactory;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.MethodInfo;
import org.jboss.test.deployers.BootstrapDeployersTest;
import org.jboss.test.deployers.vfs.reflect.support.jar.PlainJavaBean;
import org.jboss.test.deployers.vfs.reflect.support.ejb.MySLSBean;
@@ -42,6 +47,8 @@
import org.jboss.test.deployers.vfs.reflect.support.ext.External;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.AssembledDirectory;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ExportAll;
/**
* Abstract test for Reflect.
@@ -79,6 +86,14 @@
protected abstract TypeInfoFactory createTypeInfoFactory();
+ protected TypeInfo assertReturnType(TypeInfo ti, String method)
+ {
+ ClassInfo ci = assertInstanceOf(ti, ClassInfo.class);
+ MethodInfo mi = ci.getDeclaredMethod(method);
+ assertNotNull("No such '" + method + "' method on " + ci, mi);
+ return mi.getReturnType();
+ }
+
protected void assertTypeInfo(VirtualFile file, Class<?> ... classes) throws Exception
{
Map<Class<?>, String> map = new HashMap<Class<?>, String>();
@@ -124,8 +139,13 @@
protected AssembledDirectory createJar() throws Exception
{
- AssembledDirectory jar = createAssembledDirectory("simple.jar", "simple.jar");
- addPackage(jar, PlainJavaBean.class);
+ return createJar("simple.jar", PlainJavaBean.class);
+ }
+
+ protected AssembledDirectory createJar(String name, Class<?> reference) throws Exception
+ {
+ AssembledDirectory jar = createAssembledDirectory(name, name);
+ addPackage(jar, reference);
return jar;
}
@@ -239,4 +259,22 @@
return ear;
}
+
+ protected Deployment createIsolatedDeployment(String name) throws Exception
+ {
+ return createIsolatedDeployment(name, null, PlainJavaBean.class);
+ }
+
+ protected Deployment createIsolatedDeployment(String name, String parentDomain, Class<?> reference) throws Exception
+ {
+ AssembledDirectory jar = createJar(name, reference);
+ Deployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(jar);
+ MutableAttachments attachments = (MutableAttachments)deployment.getPredeterminedManagedObjects();
+ ClassLoadingMetaData clmd1 = new ClassLoadingMetaData();
+ clmd1.setDomain(name + "_Domain");
+ clmd1.setParentDomain(parentDomain);
+ clmd1.setExportAll(ExportAll.NON_EMPTY);
+ attachments.addAttachment(ClassLoadingMetaData.class, clmd1);
+ return deployment;
+ }
}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/TypeInfoTest.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/TypeInfoTest.java 2009-10-28 17:14:14 UTC (rev 95696)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/TypeInfoTest.java 2009-10-28 17:18:03 UTC (rev 95697)
@@ -25,9 +25,9 @@
import java.util.HashMap;
import java.util.Map;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.structure.spi.DeploymentUnit;
-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.reflect.support.crm.CrmFacade;
@@ -123,10 +123,7 @@
DeploymentUnit child = getDeploymentUnit(unit, "simple.war");
ClassLoader cl = getClassLoader(child);
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 rt = assertReturnType(ti, "getBean");
TypeInfo cti = typeInfoFactory.getTypeInfo(PlainJavaBean.class.getName(), getClassLoader(unit));
assertSame(rt, cti);
}
@@ -135,4 +132,76 @@
undeploy(unit);
}
}
+
+ public void testIsolatedJars() throws Exception
+ {
+ Deployment d1 = createIsolatedDeployment("j1.jar");
+ Deployment d2 = createIsolatedDeployment("j2.jar");
+ DeployerClient main = getDeployerClient();
+ main.deploy(d1, d2);
+ try
+ {
+ DeploymentUnit du1 = getMainDeployerStructure().getDeploymentUnit(d1.getName(), true);
+ DeploymentUnit du2 = getMainDeployerStructure().getDeploymentUnit(d2.getName(), true);
+ ClassLoader cl1 = getClassLoader(du1);
+ ClassLoader cl2 = getClassLoader(du2);
+ assertFalse(cl1.equals(cl2));
+ Class<?> clazz1 = assertLoadClass(PlainJavaBean.class.getName(), cl1, cl1);
+ Class<?> clazz2 = assertLoadClass(PlainJavaBean.class.getName(), cl2, cl2);
+ assertNoClassEquality(clazz1, clazz2);
+
+ TypeInfoFactory factory = createTypeInfoFactory();
+ TypeInfo ti1 = factory.getTypeInfo(PlainJavaBean.class.getName(), cl1);
+ TypeInfo ti2 = factory.getTypeInfo(PlainJavaBean.class.getName(), cl2);
+ assertNotSame(ti1, ti2);
+ TypeInfo ti3 = factory.getTypeInfo(clazz1);
+ assertSame(ti1, ti3); // FIXME - fails with JavassistTIF
+ TypeInfo ti4 = factory.getTypeInfo(clazz2);
+ assertSame(ti2, ti4);
+ assertNotSame(ti3, ti4);
+ }
+ finally
+ {
+ main.undeploy(d1, d2);
+ }
+ }
+
+ public void testDomainHierarchy() throws Exception
+ {
+ Deployment top = createIsolatedDeployment("top.jar", null, PlainJavaBean.class);
+ Deployment left = createIsolatedDeployment("left.jar", "top.jar_Domain", AnyServlet.class);
+ Deployment right = createIsolatedDeployment("right.jar", "top.jar_Domain", AnyServlet.class);
+ DeployerClient main = getDeployerClient();
+ main.deploy(top, left, right);
+ try
+ {
+ DeploymentUnit duTop = getMainDeployerStructure().getDeploymentUnit(top.getName(), true);
+ DeploymentUnit duLeft = getMainDeployerStructure().getDeploymentUnit(left.getName(), true);
+ DeploymentUnit duRight = getMainDeployerStructure().getDeploymentUnit(right.getName(), true);
+ ClassLoader topCL = getClassLoader(duTop);
+ ClassLoader leftCL = getClassLoader(duLeft);
+ ClassLoader rightCL = getClassLoader(duRight);
+ Class<?> asL = assertLoadClass(AnyServlet.class.getName(), leftCL);
+ Class<?> asR = assertLoadClass(AnyServlet.class.getName(), rightCL);
+ assertFalse(asL.equals(asR));
+ Class<?> pjbL = assertLoadClass(PlainJavaBean.class.getName(), leftCL, topCL);
+ Class<?> pjbR = assertLoadClass(PlainJavaBean.class.getName(), rightCL, topCL);
+ assertEquals(pjbL, pjbR);
+
+ TypeInfoFactory factory = createTypeInfoFactory();
+ TypeInfo pjbTI = factory.getTypeInfo(PlainJavaBean.class.getName(), topCL);
+ TypeInfo asTIL = factory.getTypeInfo(AnyServlet.class.getName(), leftCL);
+ TypeInfo asTIR = factory.getTypeInfo(AnyServlet.class.getName(), rightCL);
+
+ TypeInfo rtL = assertReturnType(asTIL, "getBean");
+ assertSame(pjbTI, rtL);
+
+ TypeInfo rtR = assertReturnType(asTIR, "getBean");
+ assertSame(pjbTI, rtR);
+ }
+ finally
+ {
+ main.undeploy(top, left, right);
+ }
+ }
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list