[jboss-cvs] JBossAS SVN: r82197 - in projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl: test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Dec 10 13:22:03 EST 2008
Author: kabir.khan at jboss.com
Date: 2008-12-10 13:22:03 -0500 (Wed, 10 Dec 2008)
New Revision: 82197
Modified:
projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/support/MockDeploymentUnit.java
projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/ClassPoolWithRepositoryTestCase.java
Log:
[JBAOP-666] Test generating classes
Modified: projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/support/MockDeploymentUnit.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/support/MockDeploymentUnit.java 2008-12-10 17:54:25 UTC (rev 82196)
+++ projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/support/MockDeploymentUnit.java 2008-12-10 18:22:03 UTC (rev 82197)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.aop.classpool.jbosscl.support;
+import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
@@ -44,11 +45,14 @@
import org.jboss.deployers.structure.spi.DeploymentResourceLoader;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.structure.spi.DeploymentUnitVisitor;
+import org.jboss.deployers.vfs.plugins.classloader.InMemoryClassesDeployer;
import org.jboss.deployers.vfs.plugins.classloader.VFSClassLoaderClassPathDeployer;
import org.jboss.metadata.spi.MetaData;
import org.jboss.metadata.spi.MutableMetaData;
import org.jboss.metadata.spi.scope.ScopeKey;
import org.jboss.util.JBossObject;
+import org.jboss.util.id.GUID;
+import org.jboss.virtual.MemoryFileFactory;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
@@ -63,8 +67,11 @@
public MockDeploymentUnit(String name, ClassLoadingMetaData clmd, URL... urls) throws Exception
{
this.name = name;
-
+
List<VirtualFile> roots = new ArrayList<VirtualFile>();
+ //Prepend the dynamic URL to the classpath
+ VirtualFile dynamicClasses = getInMemoryClassesURL();
+ roots.add(dynamicClasses);
for (URL url : urls)
{
VirtualFile file = VFS.getRoot(url);
@@ -76,6 +83,15 @@
addAttachment(ClassLoadingMetaData.class, clmd);
}
+ private VirtualFile getInMemoryClassesURL() throws Exception
+ {
+ URL dynamicClassRoot = new URL("vfsmemory", GUID.asString(), "");
+ VirtualFile classes = MemoryFileFactory.createRoot(dynamicClassRoot).getRoot();
+ addAttachment(InMemoryClassesDeployer.DYNAMIC_CLASS_URL_KEY, dynamicClassRoot);
+ addAttachment(InMemoryClassesDeployer.DYNAMIC_CLASS_KEY, classes);
+ return classes;
+ }
+
public DeploymentUnit addComponent(String name)
{
return null;
Modified: projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/ClassPoolWithRepositoryTestCase.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/ClassPoolWithRepositoryTestCase.java 2008-12-10 17:54:25 UTC (rev 82196)
+++ projects/aop/trunk/asintegration-mc/src/tests/org/jboss/test/aop/classpool/jbosscl/test/ClassPoolWithRepositoryTestCase.java 2008-12-10 18:22:03 UTC (rev 82197)
@@ -489,133 +489,190 @@
}
}
-// public void testGeneratingClassInNonDelegatingPool() throws Exception
-// {
-// ClassPool global = null;
-// ClassPool child = null;
-// try
-// {
-// final String PARENT = "parent.Parent";
-// final String CHILD = "child.Child";
-// global = createGlobalClassPoolWithParent(JAR_A_1, parent);
-// child = createChildURLClassPool(global, JAR_C_1);
-//
-// assertCannotLoadCtClass(global, PARENT);
-// assertCannotLoadCtClass(child, PARENT);
-// assertCannotLoadCtClass(child, CHILD);
-//
-//
-// CtClass childClass = child.makeClass(CHILD);
-// childClass.setSuperclass(parentClass);
-//
-// CtClass parentFromParent = parent.get(PARENT);
-// assertSame(parent, parentFromParent.getClassPool());
-// assertSame(parentClass, parentFromParent);
-//
-// CtClass childFromChild = child.get(CHILD);
-// assertSame(child, childFromChild.getClassPool());
-// assertSame(childClass, childFromChild);
-//
-// assertCannotLoadCtClass(global, CHILD);
-//
-// CtClass parentFromChildA = childClass.getSuperclass();
-// assertSame(parentClass, parentFromChildA);
-//
-// CtClass parentFromChildB = child.get(PARENT);
-// assertSame(parentClass, parentFromChildB);
-//
-// Class<?> parentClazz = parentClass.toClass();
-// assertSame(parent.getClassLoader(), parentClazz.getClassLoader());
-//
-// Class<?> childClazz = childClass.toClass();
-// assertSame(child.getClassLoader(), childClazz.getClassLoader());
-//
-// Class<?> parentClazzFromParent = parent.getClassLoader().loadClass(PARENT);
-// assertSame(parentClazz, parentClazzFromParent);
-//
-// Class<?> parentClazzFromChild = parent.getClassLoader().loadClass(PARENT);
-// assertSame(parentClazz, parentClazzFromChild);
-//
-// Class<?> childClazzFromChild = child.getClassLoader().loadClass(CHILD);
-// assertSame(childClazz, childClazzFromChild);
-// }
-// finally
-// {
-// removeClassPool(parent);
-// removeClassPool(global);
-// removeClassPool(child);
-// }
-// }
-//
-//
-// public void testGeneratingClassInDelegatingPool() throws Exception
-// {
-// ClassPool globalA = null;
-// ClassPool globalB = null;
-// ClassPool child = null;
-// try
-// {
-// globalA = createGlobalClassPool(JAR_A_1);
-// globalB = createGlobalClassPool(JAR_B_1);
-// child = createChildURLClassPool(globalA, JAR_C_1);
-//
-// final String A_CLASS = "a.Clazz";
-// final String B_CLASS = "b.Clazz";
-//
-// assertCannotLoadCtClass(globalA, A_CLASS);
-// assertCannotLoadCtClass(globalB, A_CLASS);
-// assertCannotLoadCtClass(child, A_CLASS);
-// assertCannotLoadCtClass(globalA, B_CLASS);
-// assertCannotLoadCtClass(globalB, B_CLASS);
-// assertCannotLoadCtClass(child, B_CLASS);
-//
-// CtClass a = globalA.makeClass(A_CLASS);
-// CtClass b = globalB.makeClass(B_CLASS);
-//
-// CtClass aFromA = globalA.get(A_CLASS);
-// assertSame(a, aFromA);
-// assertSame(globalA, aFromA.getClassPool());
-// CtClass aFromB = globalB.get(A_CLASS);
-// assertSame(a, aFromB);
-// CtClass bFromA = globalA.get(B_CLASS);
-// assertSame(b, bFromA);
-// assertSame(globalB, bFromA.getClassPool());
-// CtClass bFromB = globalB.get(B_CLASS);
-// assertSame(b, bFromB);
-// CtClass aFromChild = child.get(A_CLASS);
-// assertSame(a, aFromChild);
-// CtClass bFromChild = child.get(B_CLASS);
-// assertSame(b, bFromChild);
-//
-// Class<?> clazzA = a.toClass();
-// assertSame(globalA.getClassLoader(), clazzA.getClassLoader());
-//
-// Class<?> clazzB = b.toClass();
-// assertSame(globalB.getClassLoader(), clazzB.getClassLoader());
-//
-// Class<?> clazzAFromA = globalA.getClassLoader().loadClass(A_CLASS);
-// assertSame(clazzA, clazzAFromA);
-// Class<?> clazzAFromB = globalB.getClassLoader().loadClass(A_CLASS);
-// assertSame(clazzA, clazzAFromB);
-// Class<?> clazzAFromChild = child.getClassLoader().loadClass(A_CLASS);
-// assertSame(clazzA, clazzAFromChild);
-//
-// Class<?> clazzBFromA = globalA.getClassLoader().loadClass(B_CLASS);
-// assertSame(clazzB, clazzBFromA);
-// Class<?> clazzBFromB = globalB.getClassLoader().loadClass(B_CLASS);
-// assertSame(clazzB, clazzBFromB);
-// Class<?> clazzBFromChild = child.getClassLoader().loadClass(B_CLASS);
-// assertSame(clazzB, clazzBFromChild);
-// }
-// finally
-// {
-// removeClassPool(globalA);
-// removeClassPool(globalB);
-// removeClassPool(child);
-// }
-// }
+ public void testSimpleGeneratingClass() throws Exception
+ {
+ ClassPool global = null;
+ try
+ {
+ global = createClassPool("A", true, JAR_A_1);
+ final String NEW_CLASS = CLASS_A + "XYZ";
+ CtClass newCtClass = global.makeClass(NEW_CLASS);
+ Class<?> newClass = newCtClass.toClass();
+ Class<?> foundClass = global.getClassLoader().loadClass(NEW_CLASS);
+ assertSame(newClass, foundClass);
+ }
+ finally
+ {
+ unregisterClassPool(global);
+ }
+ }
+ public void testSimpleGeneratingClassAndFindInSameDomain() throws Exception
+ {
+ ClassPool globalA = null;
+ ClassPool globalB = null;
+ try
+ {
+ //Created class must be in one of the packages the loader handles
+ //http://www.jboss.com/index.html?module=bb&op=viewtopic&t=147105
+ final String NEW_CLASS = PACKAGE_A + ".NewClass";
+ globalA = createClassPool("A", true, JAR_A_1);
+ globalB = createClassPool("B", true, JAR_B_1);
+ CtClass newCtClass = globalA.makeClass(NEW_CLASS);
+ Class<?> newClass = newCtClass.toClass();
+ Class<?> foundClassA = globalA.getClassLoader().loadClass(NEW_CLASS);
+ Class<?> foundClassB = globalB.getClassLoader().loadClass(NEW_CLASS);
+ assertSame(newClass, foundClassA);
+ assertSame(newClass, foundClassB);
+ }
+ finally
+ {
+ unregisterClassPool(globalA);
+ unregisterClassPool(globalB);
+ }
+ }
+
+ public void testGeneratingCrossDomainClassHierarchy() throws Exception
+ {
+ ClassPool global = null;
+ ClassPool child1 = null;
+ ClassPool child2 = null;
+ try
+ {
+ //Created class must be in one of the packages the loader handles
+ //http://www.jboss.com/index.html?module=bb&op=viewtopic&t=147105
+ final String PARENT = PACKAGE_A + ".Parent";
+ final String CHILD = PACKAGE_C + ".Child";
+
+ global = createClassPool("A", true, JAR_A_1);
+ child1 = createChildDomainParentLastClassPool("C1", "C1", true, JAR_B_1);
+ child2 = createChildDomainParentLastClassPool("C2", "C2", "C1", true, JAR_C_1);
+
+ assertCannotLoadCtClass(global, PARENT);
+ assertCannotLoadCtClass(child1, PARENT);
+ assertCannotLoadCtClass(child2, PARENT);
+ assertCannotLoadCtClass(child2, CHILD);
+
+ CtClass parentClass = global.makeClass(PARENT);
+
+ CtClass childClass = child2.makeClass(CHILD);
+ childClass.setSuperclass(parentClass);
+
+ CtClass parentFromGlobal = global.get(PARENT);
+ assertSame(global, parentFromGlobal.getClassPool());
+ assertSame(parentClass, parentFromGlobal);
+
+ CtClass childFromChild2 = child2.get(CHILD);
+ assertSame(child2, childFromChild2.getClassPool());
+ assertSame(childClass, childFromChild2);
+
+ assertCannotLoadCtClass(global, CHILD);
+ assertCannotLoadCtClass(child1, CHILD);
+
+ CtClass parentFromChildA = childClass.getSuperclass();
+ assertSame(parentClass, parentFromChildA);
+
+ CtClass parentFromChildB = child2.get(PARENT);
+ assertSame(parentClass, parentFromChildB);
+
+ Class<?> parentClazz = parentClass.toClass();
+ assertSame(global.getClassLoader(), parentClazz.getClassLoader());
+
+ Class<?> childClazz = childClass.toClass();
+ assertSame(child2.getClassLoader(), childClazz.getClassLoader());
+
+ Class<?> parentClazzFromParent = global.getClassLoader().loadClass(PARENT);
+ assertSame(parentClazz, parentClazzFromParent);
+
+ Class<?> parentClazzFromChild = child2.getClassLoader().loadClass(PARENT);
+ assertSame(parentClazz, parentClazzFromChild);
+
+ Class<?> childClazzFromChild = child2.getClassLoader().loadClass(CHILD);
+ assertSame(childClazz, childClazzFromChild);
+ }
+ finally
+ {
+ unregisterClassPool(global);
+ unregisterClassPool(child1);
+ unregisterClassPool(child2);
+ unregisterDomain(child1);
+ unregisterDomain(child2);
+ }
+ }
+
+
+ public void testGeneratingClassInDelegatingPool() throws Exception
+ {
+ ClassPool globalA = null;
+ ClassPool globalB = null;
+ ClassPool child = null;
+ try
+ {
+ //Created class must be in one of the packages the loader handles
+ //http://www.jboss.com/index.html?module=bb&op=viewtopic&t=147105
+ final String A_CLASS = PACKAGE_A + ".AClazz";
+ final String B_CLASS = PACKAGE_B + ".BClazz";
+
+ globalA = createClassPool("A", true, JAR_A_1);
+ globalB = createClassPool("B", true, JAR_B_1);
+ child = createChildURLClassPool(globalA, JAR_C_1);
+
+
+ assertCannotLoadCtClass(globalA, A_CLASS);
+ assertCannotLoadCtClass(globalB, A_CLASS);
+ assertCannotLoadCtClass(child, A_CLASS);
+ assertCannotLoadCtClass(globalA, B_CLASS);
+ assertCannotLoadCtClass(globalB, B_CLASS);
+ assertCannotLoadCtClass(child, B_CLASS);
+
+ CtClass a = globalA.makeClass(A_CLASS);
+ CtClass b = globalB.makeClass(B_CLASS);
+
+ CtClass aFromA = globalA.get(A_CLASS);
+ assertSame(a, aFromA);
+ assertSame(globalA, aFromA.getClassPool());
+ CtClass aFromB = globalB.get(A_CLASS);
+ assertSame(a, aFromB);
+ CtClass bFromA = globalA.get(B_CLASS);
+ assertSame(b, bFromA);
+ assertSame(globalB, bFromA.getClassPool());
+ CtClass bFromB = globalB.get(B_CLASS);
+ assertSame(b, bFromB);
+ CtClass aFromChild = child.get(A_CLASS);
+ assertSame(a, aFromChild);
+ CtClass bFromChild = child.get(B_CLASS);
+ assertSame(b, bFromChild);
+
+ Class<?> clazzA = a.toClass();
+ assertSame(globalA.getClassLoader(), clazzA.getClassLoader());
+
+ Class<?> clazzB = b.toClass();
+ assertSame(globalB.getClassLoader(), clazzB.getClassLoader());
+
+ Class<?> clazzAFromA = globalA.getClassLoader().loadClass(A_CLASS);
+ assertSame(clazzA, clazzAFromA);
+ Class<?> clazzAFromB = globalB.getClassLoader().loadClass(A_CLASS);
+ assertSame(clazzA, clazzAFromB);
+ Class<?> clazzAFromChild = child.getClassLoader().loadClass(A_CLASS);
+ assertSame(clazzA, clazzAFromChild);
+
+ Class<?> clazzBFromA = globalA.getClassLoader().loadClass(B_CLASS);
+ assertSame(clazzB, clazzBFromA);
+ Class<?> clazzBFromB = globalB.getClassLoader().loadClass(B_CLASS);
+ assertSame(clazzB, clazzBFromB);
+ Class<?> clazzBFromChild = child.getClassLoader().loadClass(B_CLASS);
+ assertSame(clazzB, clazzBFromChild);
+ }
+ finally
+ {
+ unregisterClassPool(globalA);
+ unregisterClassPool(globalB);
+ unregisterClassPool(child);
+ }
+ }
+
+
/*
The folllowing two tests are probably not very realistic http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4195022#4195022
public void testClassLoaderlWithParentClassLoader() throws Exception
More information about the jboss-cvs-commits
mailing list