[jboss-cvs] JBossAS SVN: r96135 - 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
Sun Nov 8 16:32:56 EST 2009


Author: alesj
Date: 2009-11-08 16:32:55 -0500 (Sun, 08 Nov 2009)
New Revision: 96135

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
   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:
Refactor tests - no duplication.

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-11-08 17:34:07 UTC (rev 96134)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ClassPoolTest.java	2009-11-08 21:32:55 UTC (rev 96135)
@@ -21,17 +21,18 @@
  */
 package org.jboss.test.deployers.vfs.reflect.test;
 
-import java.util.HashMap;
 import java.util.Map;
 
 import javassist.ClassPool;
 import javassist.CtClass;
-
+import javassist.CtMethod;
 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.test.deployers.vfs.reflect.support.web.AnyServlet;
+import org.jboss.test.deployers.vfs.reflect.support.jar.PlainJavaBean;
 
 /**
  * Abstract test for ClassPool.
@@ -53,18 +54,8 @@
       return new JavassistTypeInfoFactory();
    }
 
-   protected void assertClassPool(VirtualFile file, Class<?> ... classes) throws Exception
+   protected void assertReflect(VirtualFile file, Map<Class<?>, String> classes) throws Exception
    {
-      Map<Class<?>, String> map = new HashMap<Class<?>, String>();
-      for (Class<?> clazz : classes)
-      {
-         map.put(clazz, null);
-      }
-      assertClassPool(file, map);
-   }
-
-   protected void assertClassPool(VirtualFile file, Map<Class<?>, String> classes) throws Exception
-   {
       DeploymentUnit unit = assertDeploy(file);
       try
       {
@@ -89,4 +80,38 @@
          undeploy(unit);
       }
    }
+
+   protected void assertSimpleHierarchy(ClassLoader topCL, ClassLoader childCL) throws Exception
+   {
+      ClassPoolRepository repository = ClassPoolRepository.getInstance();
+      ClassPool classPool = repository.registerClassLoader(childCL);
+      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(topCL);
+      CtClass returnCtClass2 = classPool.getCtClass(PlainJavaBean.class.getName());
+      assertSame(returnCtClass, returnCtClass2);
+   }
+
+   protected void assertNonDeploymentModule(ClassLoader cl, Class<?> anysClass) throws Exception
+   {
+      // TODO
+   }
+
+   protected void assertNonDeploymentModule(ClassLoader cl, Class<?> anysClass, Class<?> tifClass) throws Exception
+   {
+      // TODO
+   }
+
+   protected void assertIsolated(ClassLoader cl1, ClassLoader cl2, Class<?> clazz1, Class<?> clazz2) throws Exception
+   {
+      // TODO
+   }
+
+   protected void assertDomainHierarchy(ClassLoader topCL, ClassLoader leftCL, ClassLoader rightCL) throws Exception
+   {
+      // TODO
+   }
 }
\ No newline at end of file

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-11-08 17:34:07 UTC (rev 96134)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ClassPoolTestCase.java	2009-11-08 21:32:55 UTC (rev 96135)
@@ -21,35 +21,13 @@
  */
 package org.jboss.test.deployers.vfs.reflect.test;
 
-import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
 import junit.framework.Test;
 
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtMethod;
-import org.jboss.classpool.spi.ClassPoolRepository;
-import org.jboss.deployers.client.spi.DeployerClient;
-import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-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;
-import org.jboss.test.deployers.vfs.reflect.support.jar.PlainJavaBean;
-import org.jboss.test.deployers.vfs.reflect.support.jsf.JsfBean;
-import org.jboss.test.deployers.vfs.reflect.support.service.SomeMBean;
-import org.jboss.test.deployers.vfs.reflect.support.ui.UIBean;
-import org.jboss.test.deployers.vfs.reflect.support.util.SomeUtil;
-import org.jboss.test.deployers.vfs.reflect.support.web.AnyServlet;
-import org.jboss.virtual.AssembledDirectory;
-
 /**
  * Test case for ClassPool.
  * 
  * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
  *
  * @version $Revision$
  */
@@ -64,173 +42,4 @@
    {
       return suite(ClassPoolTestCase.class);
    }
-
-   public void testJar() throws Exception
-   {
-      AssembledDirectory directory = createJar();
-      assertClassPool(directory, PlainJavaBean.class);
-   }
-
-   public void testEjbJar() throws Exception
-   {
-      AssembledDirectory directory = createEjbJar();
-      assertClassPool(directory, MySLSBean.class);
-   }
-   
-   public void testWar() throws Exception
-   {
-      AssembledDirectory directory = createWar();
-      assertClassPool(directory, AnyServlet.class);
-   }
-   
-   public void testSar() throws Exception
-   {
-      AssembledDirectory directory = createSar();
-      assertClassPool(directory, SomeMBean.class);
-   }
-      
-   public void testBasicEar() throws Exception
-   {
-      AssembledDirectory directory = createBasicEar();
-      Map<Class<?>, String> classes = new HashMap<Class<?>, String>();
-      classes.put(SomeUtil.class, null);
-      classes.put(PlainJavaBean.class, null);
-      classes.put(MySLSBean.class, null);
-      classes.put(AnyServlet.class, "simple.war");
-      classes.put(UIBean.class, "simple.war");
-      classes.put(JsfBean.class, "jsfapp.war");
-      classes.put(CrmFacade.class, "jsfapp.war");
-      classes.put(SomeMBean.class, null);
-      assertClassPool(directory, classes);
-   }
-   
-   public void testTopLevelWithUtil() throws Exception 
-   {
-      AssembledDirectory directory = createTopLevelWithUtil("/reflect/earutil");
-      assertClassPool(directory, SomeUtil.class, External.class);
-   }
-   
-   public void testWarInEar() throws Exception 
-   {
-      AssembledDirectory directory = createWarInEar();
-      assertClassPool(directory, Collections.<Class<?>, String>singletonMap(AnyServlet.class, "simple.war"));
-   }
-   
-   public void testJarInEar() throws Exception 
-   {
-      AssembledDirectory directory = createJarInEar();
-      assertClassPool(directory, PlainJavaBean.class);
-   }
-
-   public void testHierarchyCLUsage() throws Exception
-   {
-      AssembledDirectory directory = createBasicEar();
-      DeploymentUnit unit = assertDeploy(directory);
-      try
-      {
-         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
-      {
-         undeploy(unit);
-      }
-   }
-
-   public void testNonDeploymentModule() throws Exception
-   {
-      URL location = AnyServlet.class.getProtectionDomain().getCodeSource().getLocation();
-      System.setProperty("jboss.tests.url", location.toExternalForm());
-      try
-      {
-         AssembledDirectory jar = createJar();
-         addPath(jar, "/reflect/module", "META-INF");
-
-         Deployment deployment = createVFSDeployment(jar);
-         DeployerClient main = getDeployerClient();
-         main.deploy(deployment);
-         try
-         {
-            Object anys = assertBean("AnyServlet", Object.class);
-            Class<?> anysClass = anys.getClass();
-            ClassLoader anysCL = anysClass.getClassLoader();
-
-            DeploymentUnit du = getMainDeployerStructure().getDeploymentUnit(deployment.getName(), true);
-            ClassLoader cl = getClassLoader(du);
-
-            assertNotSame(cl, anysCL);
-
-            // TODO - Flavia, apply ClassPool tests
-         }
-         finally
-         {
-            main.undeploy(deployment);
-         }
-      }
-      finally
-      {
-         System.clearProperty("jboss.tests.url");
-      }
-   }
-
-   public void testHierarchyNonDeploymentModule() throws Exception
-   {
-      testHierarchy("tif");
-   }
-
-   public void testClassLoadingMetaDataModule() throws Exception
-   {
-      testHierarchy("clmd");
-   }
-
-   public void testHierarchy(String name) throws Exception
-   {
-      URL location = AnyServlet.class.getProtectionDomain().getCodeSource().getLocation();
-      System.setProperty("jboss.tests.url", location.toExternalForm());
-      try
-      {
-         AssembledDirectory jar = createJar();
-         addPath(jar, "/reflect/" + name, "META-INF");
-
-         Deployment deployment = createVFSDeployment(jar);
-         DeployerClient main = getDeployerClient();
-         main.deploy(deployment);
-         try
-         {
-            Object anys = assertBean("AnyServlet", Object.class);
-            Class<?> anysClass = anys.getClass();
-            ClassLoader anysCL = anysClass.getClassLoader();
-
-            Object tif = assertBean("TifTester", Object.class);
-            Class<?> tifClass = tif.getClass();
-            ClassLoader tifCL = tifClass.getClassLoader();
-
-            DeploymentUnit du = getMainDeployerStructure().getDeploymentUnit(deployment.getName(), true);
-            ClassLoader cl = getClassLoader(du);
-
-            assertNotSame(cl, anysCL);
-            assertNotSame(cl, tifCL);
-            assertNotSame(anysCL, tifCL);
-
-            // TODO - Flavia, apply ClassPool tests
-         }
-         finally
-         {
-            main.undeploy(deployment);
-         }
-      }
-      finally
-      {
-         System.clearProperty("jboss.tests.url");
-      }
-   }
 }
\ No newline at end of file

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-11-08 17:34:07 UTC (rev 96134)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/JavassistTypeInfoTestCase.java	2009-11-08 21:32:55 UTC (rev 96135)
@@ -58,4 +58,7 @@
    protected void assertNotEquals(TypeInfo ti1, TypeInfo ti2)
    {
    }
+   protected void assertNonDeploymentModule(ClassLoader cl, Class<?> anysClass, Class<?> tifClass) throws Exception
+   {
+   }
 }
\ No newline at end of file

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-11-08 17:34:07 UTC (rev 96134)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/ReflectTest.java	2009-11-08 21:32:55 UTC (rev 96135)
@@ -24,12 +24,15 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
+import java.util.Collections;
+import java.net.URL;
 
 import org.jboss.classloader.plugins.jdk.AbstractJDKChecker;
 import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
 import org.jboss.classloading.spi.metadata.ExportAll;
 import org.jboss.classloading.spi.version.Version;
 import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.DeployerClient;
 import org.jboss.deployers.spi.attachments.MutableAttachments;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataFactoryVisitor;
@@ -85,51 +88,307 @@
       excluded.remove(BeanMetaDataFactoryVisitor.class);
    }
 
-   protected abstract TypeInfoFactory createTypeInfoFactory();
+   public void testJar() throws Exception
+   {
+      AssembledDirectory directory = createJar();
+      assertReflect(directory, PlainJavaBean.class);
+   }
 
-   protected TypeInfo assertReturnType(TypeInfo ti, String method)
+   public void testEjbJar() throws Exception
    {
-      ClassInfo ci = assertInstanceOf(ti, ClassInfo.class);
-      MethodInfo mi = ci.getDeclaredMethod(method);
-      assertNotNull("No such '" + method + "' method on " + ci, mi);
-      return mi.getReturnType();      
+      AssembledDirectory directory = createEjbJar();
+      assertReflect(directory, MySLSBean.class);
    }
 
-   protected void assertTypeInfo(VirtualFile file, Class<?> ... classes) throws Exception
+   public void testWar() throws Exception
    {
-      Map<Class<?>, String> map = new HashMap<Class<?>, String>();
-      for (Class<?> clazz : classes)
+      AssembledDirectory directory = createWar();
+      assertReflect(directory, AnyServlet.class);
+   }
+
+   public void testSar() throws Exception
+   {
+      AssembledDirectory directory = createSar();
+      assertReflect(directory, SomeMBean.class);
+   }
+
+   public void testBasicEar() throws Exception
+   {
+      AssembledDirectory directory = createBasicEar();
+      Map<Class<?>, String> classes = new HashMap<Class<?>, String>();
+      classes.put(SomeUtil.class, null);
+      classes.put(PlainJavaBean.class, null);
+      classes.put(MySLSBean.class, null);
+      classes.put(AnyServlet.class, "simple.war");
+      classes.put(UIBean.class, "simple.war");
+      classes.put(JsfBean.class, "jsfapp.war");
+      classes.put(CrmFacade.class, "jsfapp.war");
+      classes.put(SomeMBean.class, null);
+      assertReflect(directory, classes);
+   }
+
+   public void testTopLevelWithUtil() throws Exception
+   {
+      AssembledDirectory directory = createTopLevelWithUtil("/reflect/earutil");
+      assertReflect(directory, SomeUtil.class, External.class);
+   }
+
+   public void testWarInEar() throws Exception
+   {
+      AssembledDirectory directory = createWarInEar();
+      assertReflect(directory, Collections.<Class<?>, String>singletonMap(AnyServlet.class, "simple.war"));
+   }
+
+   public void testJarInEar() throws Exception
+   {
+      AssembledDirectory directory = createJarInEar();
+      assertReflect(directory, PlainJavaBean.class);
+   }
+
+   public void testHierarchyCLUsage() throws Exception
+   {
+      AssembledDirectory directory = createBasicEar();
+      DeploymentUnit unit = assertDeploy(directory);
+      try
       {
-         map.put(clazz, null);
+         ClassLoader topCL = getClassLoader(unit);
+         DeploymentUnit child = getDeploymentUnit(unit, "simple.war");
+         ClassLoader childCL = getClassLoader(child);
+         assertSimpleHierarchy(topCL, childCL);
       }
-      assertTypeInfo(file, map);
+      finally
+      {
+         undeploy(unit);
+      }
    }
 
-   protected void assertTypeInfo(VirtualFile file, Map<Class<?>, String> classes) throws Exception
+   public void testIsolatedJars() throws Exception
    {
-      DeploymentUnit unit = assertDeploy(file);
+      Deployment d1 = createIsolatedDeployment("j1.jar");
+      Deployment d2 = createIsolatedDeployment("j2.jar");
+      testIsolatedJars(d1, d2);
+   }
+
+   public void testHierarchyJarsChildFirst() throws Exception
+   {
+      Deployment d1 = createIsolatedDeployment("j1.jar");
+      ClassLoadingMetaData clmd = createDefaultClassLoadingMetaData("j2.jar", "j1.jar_Domain");
+      clmd.setJ2seClassLoadingCompliance(false);
+      Deployment d2 = createIsolatedDeployment("j2.jar", "j1.jar_Domain", PlainJavaBean.class, clmd);
+      testIsolatedJars(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);
+      testDomainHierarchy(top.getName(), left.getName(), right.getName(), top, left, right);
+   }
+
+   public void testEar2War() throws Exception
+   {
+      AssembledDirectory ear = createAssembledDirectory("ptd-ear-1.0-SNAPSHOT.ear", "ptd-ear-1.0-SNAPSHOT.ear");
+      addPath(ear, "/reflect/ear2war", "META-INF");
+      AssembledDirectory lib = ear.mkdir("lib");
+      AssembledDirectory common = lib.mkdir("common.jar");
+      addPackage(common, PlainJavaBean.class);
+
+      AssembledDirectory war1 = ear.mkdir("ptd-jsf-1.0-SNAPSHOT.war");
+      AssembledDirectory webinf1 = war1.mkdir("WEB-INF");
+      addPath(war1, "/reflect/ear2war/war1/", "WEB-INF");
+      AssembledDirectory lib1 = webinf1.mkdir("lib");
+      AssembledDirectory wj1 = lib1.mkdir("wj1.jar");
+      addPackage(wj1, AnyServlet.class);
+      addPath(wj1, "/reflect/ear2war/manifest/", "META-INF");
+
+      AssembledDirectory war2 = ear.mkdir("ptd-ws-1.0-SNAPSHOT.war");
+      AssembledDirectory webinf2 = war2.mkdir("WEB-INF");
+      addPath(war2, "/reflect/ear2war/war2/", "WEB-INF");
+      AssembledDirectory lib2 = webinf2.mkdir("lib");
+      AssembledDirectory wj2 = lib2.mkdir("wj2.jar");
+      addPackage(wj2, AnyServlet.class);
+      addPath(wj2, "/reflect/ear2war/manifest/", "META-INF");
+
+      Deployment deployment = createVFSDeployment(ear);
+      String top = deployment.getName();
+      String left = top + "ptd-jsf-1.0-SNAPSHOT.war/";
+      String right = top + "ptd-ws-1.0-SNAPSHOT.war/";
+      testDomainHierarchy(top, left, right, deployment);
+   }
+
+   public void testNonDeploymentModule() throws Exception
+   {
+      URL location = AnyServlet.class.getProtectionDomain().getCodeSource().getLocation();
+      System.setProperty("jboss.tests.url", location.toExternalForm());
       try
       {
-         TypeInfoFactory typeInfoFactory = createTypeInfoFactory();
-         for (Map.Entry<Class<?>, String> entry : classes.entrySet())
+         AssembledDirectory jar = createJar();
+         addPath(jar, "/reflect/module", "META-INF");
+
+         Deployment deployment = createVFSDeployment(jar);
+         DeployerClient main = getDeployerClient();
+         main.deploy(deployment);
+         try
          {
-            DeploymentUnit du = getDeploymentUnit(unit, entry.getValue());
-            ClassLoader classLoader = getClassLoader(du);
-            Class<?> clazz = entry.getKey();
-            String className = clazz.getName();
-            assertLoadClass(className, classLoader);
-            TypeInfo typeInfo = typeInfoFactory.getTypeInfo(className, classLoader);
-            assertEquals(className, typeInfo.getName());
-            ClassLoader cl = typeInfo.getClassLoader();
-            assertEquals(classLoader, cl);
+            Object anys = assertBean("AnyServlet", Object.class);
+            Class<?> anysClass = anys.getClass();
+            ClassLoader anysCL = anysClass.getClassLoader();
+
+            DeploymentUnit du = getMainDeployerStructure().getDeploymentUnit(deployment.getName(), true);
+            ClassLoader cl = getClassLoader(du);
+
+            assertNotSame(cl, anysCL);
+
+            assertNonDeploymentModule(cl, anysClass);
          }
+         finally
+         {
+            main.undeploy(deployment);
+         }
       }
       finally
       {
-         undeploy(unit);
+         System.clearProperty("jboss.tests.url");
       }
    }
 
+   public void testHierarchyNonDeploymentModule() throws Exception
+   {
+      testHierarchy("tif");
+   }
+
+   public void testClassLoadingMetaDataModule() throws Exception
+   {
+      testHierarchy("clmd");
+   }
+
+   //-------------------- helpers --------------------
+
+   protected abstract void assertSimpleHierarchy(ClassLoader topCL, ClassLoader childCL) throws Exception;
+
+   protected abstract void assertNonDeploymentModule(ClassLoader cl, Class<?> anysClass) throws Exception;
+
+   protected  abstract void assertNonDeploymentModule(ClassLoader cl, Class<?> anysClass, Class<?> tifClass) throws Exception;
+
+   protected abstract void assertIsolated(ClassLoader cl1, ClassLoader cl2, Class<?> clazz1, Class<?> clazz2) throws Exception;
+
+   protected abstract void assertDomainHierarchy(ClassLoader topCL, ClassLoader leftCL, ClassLoader rightCL) throws Exception;
+
+   protected void testHierarchy(String name) throws Exception
+   {
+      URL location = AnyServlet.class.getProtectionDomain().getCodeSource().getLocation();
+      System.setProperty("jboss.tests.url", location.toExternalForm());
+      try
+      {
+         AssembledDirectory jar = createJar();
+         addPath(jar, "/reflect/" + name, "META-INF");
+
+         Deployment deployment = createVFSDeployment(jar);
+         DeployerClient main = getDeployerClient();
+         main.deploy(deployment);
+         try
+         {
+            Object anys = assertBean("AnyServlet", Object.class);
+            Class<?> anysClass = anys.getClass();
+            ClassLoader anysCL = anysClass.getClassLoader();
+
+            Object tif = assertBean("TifTester", Object.class);
+            Class<?> tifClass = tif.getClass();
+            ClassLoader tifCL = tifClass.getClassLoader();
+
+            DeploymentUnit du = getMainDeployerStructure().getDeploymentUnit(deployment.getName(), true);
+            ClassLoader cl = getClassLoader(du);
+
+            assertNotSame(cl, anysCL);
+            assertNotSame(cl, tifCL);
+            assertNotSame(anysCL, tifCL);
+
+            assertNonDeploymentModule(cl, anysClass, tifClass);
+         }
+         finally
+         {
+            main.undeploy(deployment);
+         }
+      }
+      finally
+      {
+         System.clearProperty("jboss.tests.url");
+      }
+   }
+
+   protected void testIsolatedJars(Deployment d1, Deployment d2) throws Exception
+   {
+      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);
+
+         assertIsolated(cl1, cl2, clazz1, clazz2);
+      }
+      finally
+      {
+         main.undeploy(d1, d2);
+      }
+   }
+
+   protected void testDomainHierarchy(String top, String left, String right, Deployment... deployments) throws Exception
+   {
+      DeployerClient main = getDeployerClient();
+      main.deploy(deployments);
+      try
+      {
+         DeploymentUnit duTop = getMainDeployerStructure().getDeploymentUnit(top, true);
+         DeploymentUnit duLeft = getMainDeployerStructure().getDeploymentUnit(left, true);
+         DeploymentUnit duRight = getMainDeployerStructure().getDeploymentUnit(right, 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);
+
+         assertDomainHierarchy(topCL, leftCL, rightCL);
+      }
+      finally
+      {
+         main.undeploy(deployments);
+      }
+   }
+
+   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 assertReflect(VirtualFile file, Class<?> ... classes) throws Exception
+   {
+      Map<Class<?>, String> map = new HashMap<Class<?>, String>();
+      for (Class<?> clazz : classes)
+      {
+         map.put(clazz, null);
+      }
+      assertReflect(file, map);
+   }
+
+   protected abstract void assertReflect(VirtualFile file, Map<Class<?>, String> classes) throws Exception;
+
    protected void assertEquals(TypeInfo ti1, TypeInfo ti2)
    {
       assertSame(ti1, ti2);

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-11-08 17:34:07 UTC (rev 96134)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/reflect/test/TypeInfoTest.java	2009-11-08 21:32:55 UTC (rev 96135)
@@ -21,28 +21,14 @@
  */
 package org.jboss.test.deployers.vfs.reflect.test;
 
-import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
 
-import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
-import org.jboss.deployers.client.spi.DeployerClient;
-import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 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;
-import org.jboss.test.deployers.vfs.reflect.support.jar.PlainJavaBean;
-import org.jboss.test.deployers.vfs.reflect.support.jsf.JsfBean;
-import org.jboss.test.deployers.vfs.reflect.support.service.SomeMBean;
-import org.jboss.test.deployers.vfs.reflect.support.ui.UIBean;
-import org.jboss.test.deployers.vfs.reflect.support.util.SomeUtil;
+import org.jboss.virtual.VirtualFile;
 import org.jboss.test.deployers.vfs.reflect.support.web.AnyServlet;
-import org.jboss.virtual.AssembledDirectory;
+import org.jboss.test.deployers.vfs.reflect.support.jar.PlainJavaBean;
 
 /**
  * Test case for TypeInfo.
@@ -59,76 +45,24 @@
       super(name);
    }
 
-   public void testJar() throws Exception
+   protected void assertReflect(VirtualFile file, Map<Class<?>, String> classes) throws Exception
    {
-      AssembledDirectory directory = createJar();
-      assertTypeInfo(directory, PlainJavaBean.class);
-   }
-
-   public void testEjbJar() throws Exception
-   {
-      AssembledDirectory directory = createEjbJar();
-      assertTypeInfo(directory, MySLSBean.class);
-   }
-
-   public void testWar() throws Exception
-   {
-      AssembledDirectory directory = createWar();
-      assertTypeInfo(directory, AnyServlet.class);
-   }
-
-   public void testSar() throws Exception
-   {
-      AssembledDirectory directory = createSar();
-      assertTypeInfo(directory, SomeMBean.class);
-   }
-
-   public void testBasicEar() throws Exception
-   {
-      AssembledDirectory directory = createBasicEar();
-      Map<Class<?>, String> classes = new HashMap<Class<?>, String>();
-      classes.put(SomeUtil.class, null);
-      classes.put(PlainJavaBean.class, null);
-      classes.put(MySLSBean.class, null);
-      classes.put(AnyServlet.class, "simple.war");
-      classes.put(UIBean.class, "simple.war");
-      classes.put(JsfBean.class, "jsfapp.war");
-      classes.put(CrmFacade.class, "jsfapp.war");
-      classes.put(SomeMBean.class, null);
-      assertTypeInfo(directory, classes);
-   }
-
-   public void testTopLevelWithUtil() throws Exception
-   {
-      AssembledDirectory directory = createTopLevelWithUtil("/reflect/earutil");
-      assertTypeInfo(directory, SomeUtil.class, External.class);
-   }
-
-   public void testWarInEar() throws Exception
-   {
-      AssembledDirectory directory = createWarInEar();
-      assertTypeInfo(directory, Collections.<Class<?>, String>singletonMap(AnyServlet.class, "simple.war"));
-   }
-
-   public void testJarInEar() throws Exception
-   {
-      AssembledDirectory directory = createJarInEar();
-      assertTypeInfo(directory, PlainJavaBean.class);
-   }
-
-   public void testHierarchyCLUsage() throws Exception
-   {
-      AssembledDirectory directory = createBasicEar();
-      DeploymentUnit unit = assertDeploy(directory);
+      DeploymentUnit unit = assertDeploy(file);
       try
       {
          TypeInfoFactory typeInfoFactory = createTypeInfoFactory();
-         DeploymentUnit child = getDeploymentUnit(unit, "simple.war");
-         ClassLoader cl = getClassLoader(child);
-         TypeInfo ti = typeInfoFactory.getTypeInfo(AnyServlet.class.getName(), cl);
-         TypeInfo rt = assertReturnType(ti, "getBean");
-         TypeInfo cti = typeInfoFactory.getTypeInfo(PlainJavaBean.class.getName(), getClassLoader(unit));
-         assertSame(rt, cti);
+         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();
+            assertLoadClass(className, classLoader);
+            TypeInfo typeInfo = typeInfoFactory.getTypeInfo(className, classLoader);
+            assertEquals(className, typeInfo.getName());
+            ClassLoader cl = typeInfo.getClassLoader();
+            assertEquals(classLoader, cl);
+         }
       }
       finally
       {
@@ -136,224 +70,60 @@
       }
    }
 
-   public void testIsolatedJars(Deployment d1, Deployment d2) throws Exception
+   protected void assertSimpleHierarchy(ClassLoader topCL, ClassLoader childCL) throws Exception
    {
-      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);
-         assertNotEquals(ti1, ti2);
-         TypeInfo ti3 = factory.getTypeInfo(clazz1);
-         assertEquals(ti1, ti3);
-         TypeInfo ti4 = factory.getTypeInfo(clazz2);
-         assertEquals(ti2, ti4);
-         assertNotEquals(ti3, ti4);
-      }
-      finally
-      {
-         main.undeploy(d1, d2);
-      }
+      TypeInfoFactory typeInfoFactory = createTypeInfoFactory();
+      TypeInfo ti = typeInfoFactory.getTypeInfo(AnyServlet.class.getName(), childCL);
+      TypeInfo rt = assertReturnType(ti, "getBean");
+      TypeInfo cti = typeInfoFactory.getTypeInfo(PlainJavaBean.class.getName(), topCL);
+      assertSame(rt, cti);
    }
 
-   public void testIsolatedJars() throws Exception
+   protected void assertNonDeploymentModule(ClassLoader cl, Class<?> anysClass) throws Exception
    {
-      Deployment d1 = createIsolatedDeployment("j1.jar");
-      Deployment d2 = createIsolatedDeployment("j2.jar");
-      testIsolatedJars(d1, d2);
+      TypeInfoFactory factory = createTypeInfoFactory();
+      TypeInfo asTIL = factory.getTypeInfo(anysClass);
+      TypeInfo pjbTI = factory.getTypeInfo(PlainJavaBean.class.getName(), cl);
+      TypeInfo rtL = assertReturnType(asTIL, "getBean");
+      assertEquals(pjbTI, rtL);
    }
 
-   public void testHierarchyJarsChildFirst() throws Exception
+   protected void assertNonDeploymentModule(ClassLoader cl, Class<?> anysClass, Class<?> tifClass) throws Exception
    {
-      Deployment d1 = createIsolatedDeployment("j1.jar");
-      ClassLoadingMetaData clmd = createDefaultClassLoadingMetaData("j2.jar", "j1.jar_Domain");
-      clmd.setJ2seClassLoadingCompliance(false);
-      Deployment d2 = createIsolatedDeployment("j2.jar", "j1.jar_Domain", PlainJavaBean.class, clmd);
-      testIsolatedJars(d1, d2);
+      TypeInfoFactory factory = createTypeInfoFactory();
+      TypeInfo tifTIL = factory.getTypeInfo(tifClass);
+      TypeInfo tifRT = assertReturnType(tifTIL, "getAnys");
+      TypeInfo asTIL = factory.getTypeInfo(anysClass);
+      assertEquals(tifRT, asTIL);
+      TypeInfo pjbTI = factory.getTypeInfo(PlainJavaBean.class.getName(), cl);
+      TypeInfo rtL = assertReturnType(asTIL, "getBean");
+      assertEquals(pjbTI, rtL);
    }
 
-   protected void testDomainHierarchy(String top, String left, String right, Deployment... deployments) throws DeploymentException, ClassNotFoundException
+   protected void assertIsolated(ClassLoader cl1, ClassLoader cl2, Class<?> clazz1, Class<?> clazz2) throws Exception
    {
-      DeployerClient main = getDeployerClient();
-      main.deploy(deployments);
-      try
-      {
-         DeploymentUnit duTop = getMainDeployerStructure().getDeploymentUnit(top, true);
-         DeploymentUnit duLeft = getMainDeployerStructure().getDeploymentUnit(left, true);
-         DeploymentUnit duRight = getMainDeployerStructure().getDeploymentUnit(right, 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");
-         assertEquals(pjbTI, rtL);
-
-         TypeInfo rtR = assertReturnType(asTIR, "getBean");
-         assertEquals(pjbTI, rtR);
-      }
-      finally
-      {
-         main.undeploy(deployments);
-      }
+      TypeInfoFactory factory = createTypeInfoFactory();
+      TypeInfo ti1 = factory.getTypeInfo(PlainJavaBean.class.getName(), cl1);
+      TypeInfo ti2 = factory.getTypeInfo(PlainJavaBean.class.getName(), cl2);
+      assertNotEquals(ti1, ti2);
+      TypeInfo ti3 = factory.getTypeInfo(clazz1);
+      assertEquals(ti1, ti3);
+      TypeInfo ti4 = factory.getTypeInfo(clazz2);
+      assertEquals(ti2, ti4);
+      assertNotEquals(ti3, ti4);
    }
 
-   public void testDomainHierarchy() throws Exception
+   protected void assertDomainHierarchy(ClassLoader topCL, ClassLoader leftCL, ClassLoader rightCL) 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);
-      testDomainHierarchy(top.getName(), left.getName(), right.getName(), top, left, right);
-   }
+      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);
 
-   public void testEar2War() throws Exception
-   {
-      AssembledDirectory ear = createAssembledDirectory("ptd-ear-1.0-SNAPSHOT.ear", "ptd-ear-1.0-SNAPSHOT.ear");
-      addPath(ear, "/reflect/ear2war", "META-INF");
-      AssembledDirectory lib = ear.mkdir("lib");
-      AssembledDirectory common = lib.mkdir("common.jar");
-      addPackage(common, PlainJavaBean.class);
+      TypeInfo rtL = assertReturnType(asTIL, "getBean");
+      assertEquals(pjbTI, rtL);
 
-      AssembledDirectory war1 = ear.mkdir("ptd-jsf-1.0-SNAPSHOT.war");
-      AssembledDirectory webinf1 = war1.mkdir("WEB-INF");
-      addPath(war1, "/reflect/ear2war/war1/", "WEB-INF");
-      AssembledDirectory lib1 = webinf1.mkdir("lib");
-      AssembledDirectory wj1 = lib1.mkdir("wj1.jar");
-      addPackage(wj1, AnyServlet.class);
-      addPath(wj1, "/reflect/ear2war/manifest/", "META-INF");
-
-      AssembledDirectory war2 = ear.mkdir("ptd-ws-1.0-SNAPSHOT.war");
-      AssembledDirectory webinf2 = war2.mkdir("WEB-INF");
-      addPath(war2, "/reflect/ear2war/war2/", "WEB-INF");
-      AssembledDirectory lib2 = webinf2.mkdir("lib");
-      AssembledDirectory wj2 = lib2.mkdir("wj2.jar");
-      addPackage(wj2, AnyServlet.class);
-      addPath(wj2, "/reflect/ear2war/manifest/", "META-INF");
-
-      Deployment deployment = createVFSDeployment(ear);
-      String top = deployment.getName();
-      String left = top + "ptd-jsf-1.0-SNAPSHOT.war/";
-      String right = top + "ptd-ws-1.0-SNAPSHOT.war/";
-      testDomainHierarchy(top, left, right, deployment);
+      TypeInfo rtR = assertReturnType(asTIR, "getBean");
+      assertEquals(pjbTI, rtR);
    }
-
-   public void testNonDeploymentModule() throws Exception
-   {
-      URL location = AnyServlet.class.getProtectionDomain().getCodeSource().getLocation();
-      System.setProperty("jboss.tests.url", location.toExternalForm());
-      try
-      {
-         AssembledDirectory jar = createJar();
-         addPath(jar, "/reflect/module", "META-INF");
-
-         Deployment deployment = createVFSDeployment(jar);
-         DeployerClient main = getDeployerClient();
-         main.deploy(deployment);
-         try
-         {
-            Object anys = assertBean("AnyServlet", Object.class);
-            Class<?> anysClass = anys.getClass();
-            ClassLoader anysCL = anysClass.getClassLoader();
-
-            DeploymentUnit du = getMainDeployerStructure().getDeploymentUnit(deployment.getName(), true);
-            ClassLoader cl = getClassLoader(du);
-
-            assertNotSame(cl, anysCL);
-
-            TypeInfoFactory factory = createTypeInfoFactory();
-            TypeInfo asTIL = factory.getTypeInfo(anysClass);
-            TypeInfo pjbTI = factory.getTypeInfo(PlainJavaBean.class.getName(), cl);
-            TypeInfo rtL = assertReturnType(asTIL, "getBean");
-            assertEquals(pjbTI, rtL);
-         }
-         finally
-         {
-            main.undeploy(deployment);
-         }
-      }
-      finally
-      {
-         System.clearProperty("jboss.tests.url");
-      }
-   }
-
-   public void testHierarchyNonDeploymentModule() throws Exception
-   {
-      testHierarchy("tif");
-   }
-
-   public void testClassLoadingMetaDataModule() throws Exception
-   {
-      testHierarchy("clmd");
-   }
-
-   public void testHierarchy(String name) throws Exception
-   {
-      URL location = AnyServlet.class.getProtectionDomain().getCodeSource().getLocation();
-      System.setProperty("jboss.tests.url", location.toExternalForm());
-      try
-      {
-         AssembledDirectory jar = createJar();
-         addPath(jar, "/reflect/" + name, "META-INF");
-
-         Deployment deployment = createVFSDeployment(jar);
-         DeployerClient main = getDeployerClient();
-         main.deploy(deployment);
-         try
-         {
-            Object anys = assertBean("AnyServlet", Object.class);
-            Class<?> anysClass = anys.getClass();
-            ClassLoader anysCL = anysClass.getClassLoader();
-
-            Object tif = assertBean("TifTester", Object.class);
-            Class<?> tifClass = tif.getClass();
-            ClassLoader tifCL = tifClass.getClassLoader();
-
-            DeploymentUnit du = getMainDeployerStructure().getDeploymentUnit(deployment.getName(), true);
-            ClassLoader cl = getClassLoader(du);
-
-            assertNotSame(cl, anysCL);
-            assertNotSame(cl, tifCL);
-            assertNotSame(anysCL, tifCL);
-
-            TypeInfoFactory factory = createTypeInfoFactory();
-            TypeInfo tifTIL = factory.getTypeInfo(tifClass);
-            TypeInfo tifRT = assertReturnType(tifTIL, "getAnys");
-            TypeInfo asTIL = factory.getTypeInfo(anysClass);
-            assertEquals(tifRT, asTIL);
-            TypeInfo pjbTI = factory.getTypeInfo(PlainJavaBean.class.getName(), cl);
-            TypeInfo rtL = assertReturnType(asTIL, "getBean");
-            assertEquals(pjbTI, rtL);
-         }
-         finally
-         {
-            main.undeploy(deployment);
-         }
-      }
-      finally
-      {
-         System.clearProperty("jboss.tests.url");
-      }
-   }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list