[jboss-cvs] JBossAS SVN: r97711 - in projects/jboss-classpool/trunk/src: test/java/org/jboss/test/classpool/support and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Dec 10 21:03:03 EST 2009
Author: flavia.rainone at jboss.com
Date: 2009-12-10 21:03:03 -0500 (Thu, 10 Dec 2009)
New Revision: 97711
Added:
projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassLoaderFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassLoaderInfo.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassPoolTestScenario.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/SanityTestScenario.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/SupportArchives.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/SupportClasses.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/TestScenario.java
Removed:
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassFactory.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassLoaderFactory.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassLoaderInfo.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassPoolTestScenario.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SanityTestScenario.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportArchives.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportClasses.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestScenario.java
Modified:
projects/jboss-classpool/trunk/src/test/resources/org/jboss/test/classpool/jbosscl/Common.xml
Log:
[JBREFLECT-75] Prepare for splitting of classpool project - Part 2.
Common test classes have been moved to main source dir.
Copied: projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassFactory.java (from rev 97633, projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassFactory.java)
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassFactory.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.classpool.support;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Assert;
+
+import org.jboss.classpool.spi.AbstractClassPool;
+import org.jboss.classpool.spi.ClassPoolRepository;
+
+/**
+ * Creates classes using ClassPools.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class ClassFactory
+{
+ public static final String PACKAGE = "org.test.classpool.proxy";
+ private static final String CLASS = "Proxy";
+ private static int counter = 0;
+
+ public static Object create(Class<?> parent, ClassLoader loader) throws Exception
+ {
+ String packageName = parent.getPackage().getName();
+ if (!packageName.startsWith("java.") && !packageName.startsWith("sun."))
+ {
+ packageName += ".";
+ }
+ else
+ {
+ packageName = PACKAGE + ".";
+ }
+ String className = packageName + CLASS + counter++;
+ ClassPool pool = ClassPoolRepository.getInstance().getRegisteredCLs().get(loader);
+ try
+ {
+ registerGeneratedClass(pool, className);
+ CtClass ctClazz = pool.makeClass(packageName + CLASS + counter++);
+ ctClazz.setSuperclass(pool.get(parent.getName()));
+ Class<?> clazz = pool.toClass(ctClazz);
+ Assert.assertSame(loader, clazz.getClassLoader());
+ return clazz.newInstance();
+ }
+ catch(RuntimeException re)
+ {
+ unregisterGeneratedClass(pool, className);
+ throw re;
+ }
+ }
+
+ /**
+ * Utility method to make a new class in a pool. It makes sure that the class is registered with the pool, so others can find it.
+ */
+ public static CtClass create(ClassPool pool, String name)
+ {
+ registerGeneratedClass(pool, name);
+ return pool.makeClass(name);
+ }
+
+ /**
+ * Utility method to make a new class in a pool. It makes sure that the class is registered with the pool, so others can find it.
+ */
+ public static CtClass createNested(CtClass outer, String name, boolean isStatic) throws CannotCompileException
+ {
+ final String classname = outer.getName() + "$" + name;
+ try
+ {
+ registerGeneratedClass(outer.getClassPool(), classname);
+ CtClass inner = outer.makeNestedClass(name, true);
+ return inner;
+ }
+ catch (RuntimeException e)
+ {
+ unregisterGeneratedClass(outer.getClassPool(), classname);
+ throw e;
+ }
+ }
+
+ private static void registerGeneratedClass(ClassPool pool, String name)
+ {
+ if (pool != null && pool instanceof AbstractClassPool)
+ {
+ ((AbstractClassPool) pool).registerGeneratedClass(name);
+ }
+ }
+
+ private static void unregisterGeneratedClass(ClassPool pool, String name)
+ {
+ if (pool != null && pool instanceof AbstractClassPool)
+ {
+ ((AbstractClassPool) pool).doneGeneratingClass(name);
+ }
+ }
+}
Copied: projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassLoaderFactory.java (from rev 97633, projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassLoaderFactory.java)
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassLoaderFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassLoaderFactory.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.classpool.support;
+
+import java.util.Collection;
+
+
+/**
+ * Creates class loaders for {@link TestScenario}.
+ *
+ * @author <a href="mailto:flavia.rainone at jboss.org">Flavia Rainone</a>
+ * @version $Revision$
+ */
+
+public interface ClassLoaderFactory<I extends ClassLoaderInfo>
+{
+ /**
+ * Creates a class loader.
+ *
+ * @param classLoaderInfo information necessary for the creation of the class loader
+ * @return the created class loader
+ * @throws Exception if an unexpected error occurs
+ */
+ public ClassLoader create(I classLoaderInfo) throws Exception;
+
+ /**
+ * Destroys the created class loader.
+ *
+ * @param classLoaderInfo identifies the class loader to be destroyed
+ * @throws Exception if an unexpected error occurs
+ */
+ public void destroy(I classLoaderInfo) throws Exception;
+
+ /**
+ * Destroys all class loaders that have been created by this factory so far.
+ */
+ public void destroyAll();
+
+ /**
+ * Retrieves a class loader that has been previously created.
+ *
+ * @param classLoaderInfo identifies the class loader to be retrieved
+ * @return the class loader corresponding to {@code classLoaderInfo}
+ * @throws Exception if an unexpected error occurs
+ */
+ public ClassLoader retrieve(I classLoaderInfo) throws Exception;
+
+ /**
+ * Retrieves all class loaders that have been created so far.
+ *
+ * @return a collection with all class loaders that have been created (excluding the ones
+ * that have been destroyed)
+ */
+ public Collection<ClassLoader> retrieveAll();
+
+ /**
+ * Checks whether the class loader corresponding to {@code classLoaderInfo} is available
+ * (i.e. whether is has been created but is not destroyed yet).
+ *
+ * @param classLoaderBuilder identifies the loader whose availability is going to be checked
+ * @return {@code true} only if a class loader has been created for {@code classLoaderInfo}
+ * and has not been destroyed
+ * @throws Exception if an unexpected error occurs
+ */
+ public boolean isAvailable(I classLoaderInfo) throws Exception;
+}
\ No newline at end of file
Copied: projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassLoaderInfo.java (from rev 97633, projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassLoaderInfo.java)
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassLoaderInfo.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassLoaderInfo.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.classpool.support;
+
+/**
+ * Contains information necessary for the ClassLoaderFactory that will be used to
+ * create the ClassLoaders.
+ *
+ * @author <a href="mailto:flavia.rainone at jboss.org">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public interface ClassLoaderInfo {}
\ No newline at end of file
Copied: projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassPoolTestScenario.java (from rev 97633, projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassPoolTestScenario.java)
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassPoolTestScenario.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/ClassPoolTestScenario.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -0,0 +1,204 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.classpool.support;
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+import junit.framework.Assert;
+
+import org.jboss.classpool.spi.ClassPoolRepository;
+
+/**
+ * This scenario is used by class pool test cases. All the operations performed using this
+ * scenario are executed over CtClasses and ClassPools.
+ *
+ * @param <I> the ClassLoaderInfo that will be used to create class loaders for this scenario
+ *
+ * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class ClassPoolTestScenario<I extends ClassLoaderInfo> extends TestScenario<CtClass, ClassPool, I>
+{
+ /** The ClassPool repository */
+ protected ClassPoolRepository repository;
+
+ /**
+ * Constructor.
+ *
+ * @param classLoaderFactory creates class loaders for the loader scenario.
+ * @param <I> the info that {@code classLoaderFactory} uses to create a class loader
+ */
+ public ClassPoolTestScenario(ClassLoaderFactory<I> classLoaderFactory)
+ {
+ super(classLoaderFactory);
+ repository = ClassPoolRepository.getInstance();
+ }
+
+ @Override
+ public ClassPool getLoader(CtClass clazz)
+ {
+ return assertRegisterClassLoader(clazz.getClassPool().getClassLoader());
+ }
+
+ @Override
+ public ClassPool getLoader(ClassLoader classLoader)
+ {
+ return assertRegisterClassLoader(classLoader);
+ }
+
+ @Override
+ public ClassLoader getClassLoader(ClassPool classPool)
+ {
+ return classPool.getClassLoader();
+ }
+
+ @Override
+ public CtClass loadClass(ClassPool classPool, ClassPool expectedClassPool, String className)
+ throws Exception
+ {
+ Class<?> clazz = assertLoadClass(classPool.getClassLoader(), expectedClassPool.getClassLoader(), className);
+ CtClass ctClass = assertLoadCtClass(className, classPool, expectedClassPool);
+ Assert.assertEquals(className, ctClass.getName());
+ Assert.assertEquals("Class has been loaded by the wrong class loader: " + className,
+ clazz.getClassLoader(), ctClass.getClassPool().getClassLoader());
+ return ctClass;
+ }
+
+ @Override
+ public void cannotLoadClass(ClassPool classPool, String className)
+ {
+ try
+ {
+ classPool.getCtClass(className);
+ Assert.fail("Should not have been able to load " + className);
+ }
+ catch(NotFoundException expected){}
+ }
+
+ @Override
+ public CtClass getMethodReturnType(CtClass clazz, String methodName) throws Exception
+ {
+ return clazz.getDeclaredMethod(methodName).getReturnType();
+ }
+
+ /********* HELPER METHODS ***************************************************************/
+
+ private ClassPool assertRegisterClassLoader(ClassLoader loader)
+ {
+ ClassPool classPool = repository.registerClassLoader(loader);
+ Assert.assertNotNull(classPool);
+ assertBootstrap(classPool, String.class, Class.class, ClassLoader.class, Object.class,
+ Collection.class, List.class, Map.class, URL.class);
+ return classPool;
+ }
+
+ private void assertBootstrap(ClassPool classPool, Class<?>... classes)
+ {
+ assertSameClassPool(null, classPool, int.class, boolean.class, byte.class, short.class,
+ long.class, float.class, double.class, char.class, void.class);
+ assertSameClassPool(ClassPool.getDefault(), classPool, classes);
+
+ }
+
+ private void assertSameClassPool(ClassPool expectedClassPool, ClassPool classPool,
+ Class<?>... classes)
+ {
+ for (Class<?> clazz: classes)
+ {
+ CtClass ctClass = null;
+ try
+ {
+ ctClass = classPool.getCtClass(clazz.getName());
+ } catch (NotFoundException e)
+ {
+ e.printStackTrace();
+ Assert.fail(e.getMessage());
+ }
+ Assert.assertSame("Class " + clazz.getName() + " loaded by unexpected class pool ",
+ expectedClassPool, ctClass.getClassPool());
+ }
+ }
+
+ protected CtClass assertLoadCtClass(String name, ClassPool initiating, ClassPool expected) throws Exception
+ {
+ CtClass clazz = initiating.get(name);
+ if (expected != null)
+ {
+ Assert.assertSame(expected, clazz.getClassPool());
+ }
+ //Load twice to test both create and cache
+ clazz = initiating.get(name);
+ if (expected != null)
+ {
+ Assert.assertSame(expected, clazz.getClassPool());
+ }
+
+ assertLoadCtClassArray(name, clazz, initiating, expected);
+
+ return clazz;
+ }
+
+ private void assertLoadCtClassArray(String name, CtClass clazz, ClassPool initiating, ClassPool expected) throws Exception
+ {
+ assertLoadCtClassArray(name, clazz, 1, initiating, expected);
+ assertLoadCtClassArray(name, clazz, 2, initiating, expected);
+ }
+
+ private void assertLoadCtClassArray(String name, CtClass clazz, int dimensions, ClassPool initiating, ClassPool expected) throws Exception
+ {
+ String arrayName = name;
+ for (int i = 0 ; i < dimensions ; i++)
+ {
+ arrayName = arrayName + "[]";
+ }
+ CtClass array = initiating.get(arrayName);
+
+ if (expected != null)
+ {
+ Assert.assertSame(expected, array.getClassPool());
+ }
+
+ Assert.assertSame(clazz.getClassPool(), array.getClassPool());
+
+ CtClass type = array;
+ for (int i = 0 ; i < dimensions ; i++)
+ {
+ type = type.getComponentType();
+ }
+ Assert.assertSame(type, clazz);
+ }
+
+ @Override
+ protected void preDestroy(Collection<ClassLoader> classLoaders)
+ {
+ for (ClassLoader classLoader: classLoaders)
+ {
+ repository.unregisterClassLoader(classLoader);
+ }
+ }
+}
Copied: projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/SanityTestScenario.java (from rev 97633, projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SanityTestScenario.java)
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/SanityTestScenario.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/SanityTestScenario.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.classpool.support;
+
+
+import junit.framework.Assert;
+
+/**
+ * This scenario is used by sanity tests, i.e., tests that check whether the class loaders
+ * represented by class pools actually behave as expected.
+ *
+ * @param <I> the ClassLoaderInfo that will be used to create class loaders for this scenario
+ *
+ * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class SanityTestScenario<I extends ClassLoaderInfo> extends TestScenario<Class<?>, ClassLoader, I>
+{
+ /**
+ * Constructor.
+ *
+ * @param classLoaderFactory creates class loaders for the loader scenario.
+ * @param <I> the info that {@code classLoaderFactory} uses to create a class loader
+ */
+ public SanityTestScenario(ClassLoaderFactory<I> classLoaderFactory)
+ {
+ super(classLoaderFactory);
+ }
+
+ @Override
+ public ClassLoader getLoader(Class<?> clazz)
+ {
+ return clazz.getClassLoader();
+ }
+
+ @Override
+ public ClassLoader getLoader(ClassLoader classLoader)
+ {
+ return classLoader;
+ }
+
+ @Override
+ public ClassLoader getClassLoader(ClassLoader loader)
+ {
+ return loader;
+ }
+
+ @Override
+ public Class<?> loadClass(ClassLoader loader, ClassLoader expected, String className) throws Exception
+ {
+ return assertLoadClass(loader, expected, className);
+ }
+
+ @Override
+ public void cannotLoadClass(ClassLoader classLoader, String className)
+ {
+ try
+ {
+ classLoader.loadClass(className);
+ Assert.fail("Should not have been able to load " + className);
+ }
+ catch(ClassNotFoundException expected){}
+ }
+
+ @Override
+ public Class<?> getMethodReturnType(Class<?> clazz, String methodName) throws Exception
+ {
+ return clazz.getDeclaredMethod(methodName).getReturnType();
+ }
+}
\ No newline at end of file
Copied: projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/SupportArchives.java (from rev 97633, projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportArchives.java)
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/SupportArchives.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/SupportArchives.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.classpool.support;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+
+/**
+ * Contains the name of the support archives.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class SupportArchives
+{
+ private static final String UTIL_JAR = "lib/util.jar";
+ private static final String EXT_JAR = "lib/ext.jar";
+ private static final String UI_JAR = "lib/ui.jar";
+ private static final String UI_UTIL_JAR = "lib/ui_util.jar";
+ private static String WAR_CP = "/WEB-INF/classes";
+
+ /************ ARCHIVE NAMES *************************************************************/
+
+ public final static String JAR_A_1 = "a1.jar";
+ public final static String JAR_A_2 = "a2.jar";
+ public final static String JAR_B_1 = "b1.jar";
+ public final static String JAR_B_2 = "b2.jar";
+ public final static String JAR_C_1 = "c1.jar";
+ public final static String JAR_C_2 = "c2.jar";
+ public final static String JAR_D = "d.jar";
+ public final static String SIMPLE_JAR = "simple.jar";
+ public final static String SIMPLE_SAR = "simple.sar";
+ public final static String EJB_JAR = "ejbs.jar";
+ public final static String SIMPLE_WAR = "simple.war";
+ public final static String SIMPLE_EAR = "simple.ear";
+ public final static String SIMPLE_EAR_JAR = SIMPLE_EAR + '/' + SIMPLE_JAR;
+ public final static String SIMPLE_EAR_SAR = SIMPLE_EAR + '/' + SIMPLE_SAR;
+ public final static String SIMPLE_EAR_EJB = SIMPLE_EAR + '/' + EJB_JAR;
+ public final static String SIMPLE_EAR_LIB1 = SIMPLE_EAR + '/' + UTIL_JAR;
+ public final static String SIMPLE_EAR_LIB2 = SIMPLE_EAR + '/' + EXT_JAR;
+ public final static String SIMPLE_EAR_WAR1 = SIMPLE_EAR + "/simple_ui.war";
+ public final static String SIMPLE_EAR_WAR1_LIB = SIMPLE_EAR_WAR1 + "/WEB-INF/" + UI_JAR;
+ public final static String SIMPLE_EAR_WAR2 = SIMPLE_EAR + "/jsfapp.war";
+ public final static String SIMPLE_EAR_WAR2_LIB = SIMPLE_EAR_WAR2 + "/WEB-INF/" + UI_UTIL_JAR;
+ public final static String TOP_EAR = "top-level.ear";
+ public final static String TOP_EAR_UTIL = TOP_EAR + '/' + UTIL_JAR;
+ public final static String TOP_EAR_EXT = TOP_EAR + '/' + EXT_JAR;
+ public final static String WAR_IN_EAR = "war-in-ear.ear";
+ public final static String WAR_IN_EAR_WAR = WAR_IN_EAR + '/' + SIMPLE_WAR;
+ public final static String JAR_IN_EAR = "jar-in-ear.ear";
+ public final static String JAR_IN_EAR_JAR = JAR_IN_EAR + '/' + SIMPLE_JAR;
+ public final static String SERVLET_JAR = "servlet.jar";
+ public final static String PTD_EAR = "ptd-ear-1.0-SNAPSHOT.ear";
+ public final static String PTD_EAR_LIB = PTD_EAR + "/lib/common.jar";
+ public final static String PTD_JSF_WAR = PTD_EAR + "/ptd-jsf-1.0-SNAPSHOT.war";
+ public final static String PTD_JSF_WAR_LIB = PTD_JSF_WAR + "/WEB-INF/lib/wj1.jar";
+ public final static String PTD_WS_WAR = PTD_EAR + "/ptd-ws-1.0-SNAPSHOT.war";
+ public final static String PTD_WS_WAR_LIB = PTD_WS_WAR + "/WEB-INF/lib/wj2.jar";
+ public final static String PARENT_JAR = "replacereferences-parent.jar";
+ public final static String CHILD_JAR = "replacereferences-child.jar";
+ // TODO JBREFLECT-80
+ //public final static String EXCLUDED_CLASSPATH = "../test-classes";
+ public final static String EXCLUDED_CLASSPATH = "../test-excluded-classes";
+
+ /************ CLASSPATH URLS ************************************************************/
+
+ public final static URL JAR_A_1_URL = getURL(JAR_A_1);
+ public final static URL JAR_A_2_URL = getURL(JAR_A_2);
+ public final static URL JAR_B_1_URL = getURL(JAR_B_1);
+ public final static URL JAR_B_2_URL = getURL(JAR_B_2);
+ public final static URL JAR_C_1_URL = getURL(JAR_C_1);
+ public final static URL JAR_C_2_URL = getURL(JAR_C_2);
+ public final static URL JAR_D_URL = getURL(JAR_D);
+ public final static URL SIMPLE_JAR_URL = getURL(SIMPLE_JAR);
+ public final static URL SIMPLE_SAR_URL = getURL(SIMPLE_SAR);
+ public final static URL EJB_JAR_URL = getURL(EJB_JAR);
+ public final static URL SIMPLE_WAR_CP_URL = getURL(SIMPLE_WAR + WAR_CP);
+ public final static URL SIMPLE_EAR_JAR_URL = getURL(SIMPLE_EAR_JAR);
+ public final static URL SIMPLE_EAR_SAR_URL = getURL(SIMPLE_EAR_SAR);
+ public final static URL SIMPLE_EAR_EJB_URL = getURL(SIMPLE_EAR_EJB);
+ public final static URL SIMPLE_EAR_LIB1_URL = getURL(SIMPLE_EAR_LIB1);
+ public final static URL SIMPLE_EAR_LIB2_URL = getURL(SIMPLE_EAR_LIB2);
+ public final static URL SIMPLE_EAR_WAR1_URL = getURL(SIMPLE_EAR_WAR1);
+ public final static URL SIMPLE_EAR_WAR1_CP_URL = getURL(SIMPLE_EAR_WAR1 + WAR_CP);
+ public final static URL SIMPLE_EAR_WAR1_LIB_URL = getURL(SIMPLE_EAR_WAR1_LIB);
+ public final static URL SIMPLE_EAR_WAR2_URL = getURL(SIMPLE_EAR_WAR2);
+ public final static URL SIMPLE_EAR_WAR2_CP_URL = getURL(SIMPLE_EAR_WAR2 + WAR_CP);
+ public final static URL SIMPLE_EAR_WAR2_LIB_URL = getURL(SIMPLE_EAR_WAR2_LIB);
+ public final static URL TOP_EAR_UTIL_URL = getURL(TOP_EAR_UTIL);
+ public final static URL TOP_EAR_EXT_URL = getURL(TOP_EAR_EXT);
+ public final static URL WAR_IN_EAR_WAR_URL = getURL(WAR_IN_EAR_WAR);
+ public final static URL WAR_IN_EAR_WAR_CP = getURL(WAR_IN_EAR_WAR + WAR_CP);
+ public final static URL JAR_IN_EAR_JAR_URL = getURL(JAR_IN_EAR_JAR);
+ public final static URL SERVLET_JAR_URL = getURL(SERVLET_JAR);
+ public final static URL PTD_EAR_LIB_URL = getURL(PTD_EAR_LIB);
+ public final static URL PTD_JSF_WAR_URL = getURL(PTD_JSF_WAR);
+ public final static URL PTD_JSF_WAR_LIB_URL = getURL(PTD_JSF_WAR_LIB);
+ public final static URL PTD_WS_WAR_URL = getURL(PTD_WS_WAR);
+ public final static URL PTD_WS_WAR_LIB_URL = getURL(PTD_WS_WAR_LIB);
+ public final static URL EXCLUDED_CLASSPATH_URL = getURL(EXCLUDED_CLASSPATH);
+ public final static URL PARENT_JAR_URL = getURL(PARENT_JAR);
+ public final static URL CHILD_JAR_URL = getURL(CHILD_JAR);
+
+ /** Returns the relative URL to the project root */
+ private static URL getURL(String relativePath)
+ {
+ try
+ {
+ URL url = SupportArchives.class.getProtectionDomain().getCodeSource().getLocation();
+ String location = url.toString();
+ int index = location.lastIndexOf("/target/") + "/target/".length();
+ location = location.substring(0, index) + "archives/";
+
+ location = location + relativePath;
+ return new URL(location);
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
\ No newline at end of file
Copied: projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/SupportClasses.java (from rev 97633, projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportClasses.java)
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/SupportClasses.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/SupportClasses.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.classpool.support;
+
+
+
+/**
+ * Contains the name of all support classes.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class SupportClasses
+{
+ public static final String PACKAGE_ROOT = SupportClasses.class.getPackage().getName() + ".excluded";
+ public final static String PACKAGE_A = PACKAGE_ROOT + ".a";
+ public final static String PACKAGE_B = PACKAGE_ROOT + ".b";
+ public final static String PACKAGE_C = PACKAGE_ROOT + ".c";
+ public final static String PACKAGE_D = PACKAGE_ROOT + ".d";
+ public final static String PACKAGE_JAR = PACKAGE_ROOT + ".jar";
+ public final static String PACKAGE_SAR = PACKAGE_ROOT + ".service";
+ public final static String PACKAGE_EJB = PACKAGE_ROOT + ".ejb";
+ public final static String PACKAGE_WEB = PACKAGE_ROOT + ".web";
+ public final static String PACKAGE_JSF = PACKAGE_ROOT + ".jsf";
+ public final static String PACKAGE_UTIL = PACKAGE_ROOT + ".util";
+ public final static String PACKAGE_EXT = PACKAGE_ROOT + ".ext";
+ public final static String PACKAGE_UI = PACKAGE_ROOT + ".ui";
+ public final static String PACKAGE_CRM = PACKAGE_ROOT + ".crm";
+ public final static String PACKAGE_TIF = PACKAGE_ROOT + ".tif";
+
+ public final static String CLASS_A = PACKAGE_A + ".A";
+ public final static String CLASS_B = PACKAGE_B + ".B";
+ public final static String CLASS_C = PACKAGE_C + ".C";
+ public final static String CLASS_D = PACKAGE_D + ".D";
+ public final static String CLASS_PLAIN = PACKAGE_JAR + ".PlainJavaBean";
+ public final static String CLASS_MBEAN = PACKAGE_SAR + ".SomeMBean";
+ public final static String CLASS_SLS_BEAN = PACKAGE_EJB + ".MySLSBean";
+ public final static String CLASS_SLS_INTERFACE = PACKAGE_EJB + ".BusinessInterface";
+ public final static String CLASS_SERVLET = PACKAGE_WEB + ".AnyServlet";
+ public final static String CLASS_JSF = PACKAGE_JSF + ".JsfBean";
+ public final static String CLASS_UTIL = PACKAGE_UTIL + ".SomeUtil";
+ public final static String CLASS_EXT = PACKAGE_EXT + ".External";
+ public final static String CLASS_UI = PACKAGE_UI + ".UIBean";
+ public final static String CLASS_CRM = PACKAGE_CRM + ".CrmFacade";
+ public final static String CLASS_TIF = PACKAGE_TIF + ".TIFTester";
+
+ private static final String[] SUPPORT_CLASSES = new String[]{CLASS_A, CLASS_B, CLASS_C,
+ CLASS_D, CLASS_PLAIN, CLASS_MBEAN, CLASS_SLS_BEAN, CLASS_SLS_INTERFACE, CLASS_SERVLET,
+ CLASS_JSF, CLASS_UTIL, CLASS_EXT, CLASS_UI, CLASS_CRM, CLASS_TIF};
+
+ public static final String[] getAllSupportClasses()
+ {
+ return SUPPORT_CLASSES;
+ }
+
+ public final static String PACKAGE_REPLACEMENT = PACKAGE_ROOT + ".replacereferences";
+ public final static String PACKAGE_REPLACEMENT_CHILD = PACKAGE_REPLACEMENT + ".child";
+ public final static String PACKAGE_REPLACEMENT_PARENT = PACKAGE_REPLACEMENT + ".parent";
+ public final static String CLASS_INVOKED = PACKAGE_REPLACEMENT + ".Invoked";
+ public final static String CLASS_PARENT_CALLER = PACKAGE_REPLACEMENT_PARENT + ".ParentCaller";
+ public final static String CLASS_CHILD_CALLER = PACKAGE_REPLACEMENT_CHILD + ".ChildCaller";
+}
\ No newline at end of file
Copied: projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/TestScenario.java (from rev 97633, projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestScenario.java)
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/TestScenario.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/test/classpool/support/TestScenario.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -0,0 +1,219 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.classpool.support;
+
+import java.util.Collection;
+
+import junit.framework.Assert;
+
+
+/**
+ * Abstracts the concept of loader (L) and classes (C).
+ * This class allows the implementation of tests that don't rely on the actual type of
+ * L and C.
+ * @param <C> represents a class
+ * @param <L> responsbile for loading a class
+ * @param <I> the ClassLoaderInfo that will be used to create class loaders for this scenario
+ *
+ * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ * @see SanityTestScenario
+ * @see ClassPoolTestScenario
+ */
+public abstract class TestScenario<C,L,I extends ClassLoaderInfo>
+{
+ /** The classloader factory */
+ private ClassLoaderFactory<I> classLoaderFactory;
+
+ /**
+ * Constructor.
+ *
+ * @param classLoaderFactory creates class loaders for the loader scenario.
+ * @param <I> the info that {@code classLoaderFactory} uses to create a class loader
+ */
+ public TestScenario(ClassLoaderFactory<I> classLoaderFactory)
+ {
+ this.classLoaderFactory = classLoaderFactory;
+ }
+
+ /**
+ * Creates a loader.
+ *
+ * @param classLoaderBuilder contains all the info necessary for the creation of a loader
+ * @return the created loader
+ * @throws Exception if an unexpected error occurs
+ */
+ public L createLoader(I classLoaderInfo) throws Exception
+ {
+ ClassLoader classLoader = classLoaderFactory.create(classLoaderInfo);
+ return getLoader(classLoader);
+ }
+
+ /**
+ * Destroys the loader corresponding to classLoaderBuilder.
+ * This method can be invoked only after the loader has been
+ * {@link #createLoader(I) created}.
+ *
+ * @param classLoaderInfo contains information regarding the loader to be destroyed.
+ * @throws Exception if an unexpected error occurs
+ * @see #createLoader(I)
+ */
+ public void destroyLoader(I classLoaderInfo) throws Exception
+ {
+ classLoaderFactory.destroy(classLoaderInfo);
+ }
+
+ /**
+ * Destroy all loaders that have been created so far (except for loaders that have already
+ * been {@link #destroyLoader(I) destroyed}).
+ */
+ public void destroyLoaders()
+ {
+ preDestroy(classLoaderFactory.retrieveAll());
+ classLoaderFactory.destroyAll();
+ }
+
+ /**
+ * Returns the loader corresponding to {@code classLoaderBuilder}. This method can be
+ * invoked only after {@code #createLoader(I)}.
+ *
+ * @param classLoaderInfo contains all the info related to the loader to be retrieved
+ * @return the loader equivalent to {@code classLoaderBuilder}
+ * @throws Exception if an unexpected error occurs
+ * @see {@link #createLoader(I)}
+ */
+ public L getLoader(I classLoaderInfo) throws Exception
+ {
+ ClassLoader classLoader = classLoaderFactory.retrieve(classLoaderInfo);
+ return getLoader(classLoader);
+ }
+
+ /**
+ * Checks that the loader corresponding to {@code classLoaderBuilder} is no longer
+ * available on the test scenario.
+ *
+ * @param classLoaderInfo identifies the loader that is going to be verified
+ * @throws Exception if an unexpected error occurs
+ */
+ public void cannotGetLoader(I classLoaderInfo) throws Exception
+ {
+ Assert.assertFalse("Class loader should not be available",
+ classLoaderFactory.isAvailable(classLoaderInfo));
+ }
+
+ /**
+ * Returns the loader that loaded {@code clazz}.
+ *
+ * @param clazz a class that has been previously loaded
+ * @return the loader that loaded {@code clazz}
+ */
+ public abstract L getLoader(C clazz);
+
+ /**
+ * Returns the loader corresponding to {@code classLoader}.
+ *
+ * @param classLoader a class loader
+ * @return the loader that represents {code classLoader}
+ */
+ public abstract L getLoader(ClassLoader classLoader);
+
+ /**
+ * Returns the class loader corresponding to {@code loader}.
+ *
+ * @param loader a loader
+ * @return the class loader that is represented by loader
+ */
+ public abstract ClassLoader getClassLoader(L loader);
+
+ /**
+ * Checks that {@code loader} can load {@code className} and returns the loaded class.
+ * Also verifies that the loader associated with the loaded class is {@code loader}.
+ *
+ * @param loader a loader
+ * @param className the name of the class to be loaded
+ * @return the class loaded by {@code loader}
+ * @throws Exception if an unexpected error occurs
+ */
+ public C loadClass(L loader, String className) throws Exception
+ {
+ return loadClass(loader, loader, className);
+ }
+
+ /**
+ * Checks that {@code loader} can load {@code className} and returns the loaded class.
+ * Also verifies that the loader associated with the loaded class is {@code expected}.
+ *
+ * @param initiating the loader that will be used for loading {@code className}
+ * @param expected the actual loader that is associated with the loaded class
+ * @param className the name of the class to be loaded
+ * @return the loaded class
+ * @throws Exception if an unexpected error occurs
+ */
+ public abstract C loadClass(L initiating, L expected, String className) throws Exception;
+
+ /**
+ * Checks that {@code loader} cannot load class {@code className}.
+ *
+ * @param loader a loader
+ * @param className the name of the class that can't be loaded by {@code loader}
+ */
+ public abstract void cannotLoadClass(L loader, String className);
+
+ /**
+ * Returns the return type of a method declared in {@code clazz}.
+ *
+ * @param clazz the class that contains the method
+ * @param methodName the name of the method
+ * @return the return type of the method
+ * @throws Exception if an unexpected error occurs
+ */
+ public abstract C getMethodReturnType(C clazz, String methodName) throws Exception;
+
+ /**
+ * Asserts that {@code initiating} class loader can load {@code classname}.
+ * Also verifies that the class loader associated with the loaded class is {@code expected}
+ *
+ * @param initiating the class loader that will be used for loading {@code className}
+ * @param expected the actual class loader that is associated with the loaded class
+ * @param className the name of the class to be loaded
+ * @return the loaded class
+ * @throws Exception if an unexpected error occurs
+ */
+ protected Class<?> assertLoadClass(ClassLoader initiating, ClassLoader expected, String className) throws Exception
+ {
+ Class<?> clazz = initiating.loadClass(className);
+ if (expected != null)
+ {
+ Assert.assertSame(expected, clazz.getClassLoader());
+ }
+ return clazz;
+ }
+
+ /**
+ * Is called prior to destroy the class loaders in {@code classLoaders} collection.
+ *
+ * @param classLoaders the class loaders that will be destroyed
+ */
+ protected void preDestroy(Collection<ClassLoader> classLoaders)
+ {
+ }
+}
\ No newline at end of file
Deleted: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassFactory.java 2009-12-11 01:48:42 UTC (rev 97710)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassFactory.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -1,116 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.classpool.support;
-
-import javassist.CannotCompileException;
-import javassist.ClassPool;
-import javassist.CtClass;
-import junit.framework.Assert;
-
-import org.jboss.classpool.spi.AbstractClassPool;
-import org.jboss.classpool.spi.ClassPoolRepository;
-
-/**
- * Creates classes using ClassPools.
- *
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- * @version $Revision$
- */
-public class ClassFactory
-{
- public static final String PACKAGE = "org.test.classpool.proxy";
- private static final String CLASS = "Proxy";
- private static int counter = 0;
-
- public static Object create(Class<?> parent, ClassLoader loader) throws Exception
- {
- String packageName = parent.getPackage().getName();
- if (!packageName.startsWith("java.") && !packageName.startsWith("sun."))
- {
- packageName += ".";
- }
- else
- {
- packageName = PACKAGE + ".";
- }
- String className = packageName + CLASS + counter++;
- ClassPool pool = ClassPoolRepository.getInstance().getRegisteredCLs().get(loader);
- try
- {
- registerGeneratedClass(pool, className);
- CtClass ctClazz = pool.makeClass(packageName + CLASS + counter++);
- ctClazz.setSuperclass(pool.get(parent.getName()));
- Class<?> clazz = pool.toClass(ctClazz);
- Assert.assertSame(loader, clazz.getClassLoader());
- return clazz.newInstance();
- }
- catch(RuntimeException re)
- {
- unregisterGeneratedClass(pool, className);
- throw re;
- }
- }
-
- /**
- * Utility method to make a new class in a pool. It makes sure that the class is registered with the pool, so others can find it.
- */
- public static CtClass create(ClassPool pool, String name)
- {
- registerGeneratedClass(pool, name);
- return pool.makeClass(name);
- }
-
- /**
- * Utility method to make a new class in a pool. It makes sure that the class is registered with the pool, so others can find it.
- */
- public static CtClass createNested(CtClass outer, String name, boolean isStatic) throws CannotCompileException
- {
- final String classname = outer.getName() + "$" + name;
- try
- {
- registerGeneratedClass(outer.getClassPool(), classname);
- CtClass inner = outer.makeNestedClass(name, true);
- return inner;
- }
- catch (RuntimeException e)
- {
- unregisterGeneratedClass(outer.getClassPool(), classname);
- throw e;
- }
- }
-
- private static void registerGeneratedClass(ClassPool pool, String name)
- {
- if (pool != null && pool instanceof AbstractClassPool)
- {
- ((AbstractClassPool) pool).registerGeneratedClass(name);
- }
- }
-
- private static void unregisterGeneratedClass(ClassPool pool, String name)
- {
- if (pool != null && pool instanceof AbstractClassPool)
- {
- ((AbstractClassPool) pool).doneGeneratingClass(name);
- }
- }
-}
Deleted: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassLoaderFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassLoaderFactory.java 2009-12-11 01:48:42 UTC (rev 97710)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassLoaderFactory.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -1,85 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.classpool.support;
-
-import java.util.Collection;
-
-
-/**
- * Creates class loaders for {@link TestScenario}.
- *
- * @author <a href="mailto:flavia.rainone at jboss.org">Flavia Rainone</a>
- * @version $Revision$
- */
-
-public interface ClassLoaderFactory<I extends ClassLoaderInfo>
-{
- /**
- * Creates a class loader.
- *
- * @param classLoaderInfo information necessary for the creation of the class loader
- * @return the created class loader
- * @throws Exception if an unexpected error occurs
- */
- public ClassLoader create(I classLoaderInfo) throws Exception;
-
- /**
- * Destroys the created class loader.
- *
- * @param classLoaderInfo identifies the class loader to be destroyed
- * @throws Exception if an unexpected error occurs
- */
- public void destroy(I classLoaderInfo) throws Exception;
-
- /**
- * Destroys all class loaders that have been created by this factory so far.
- */
- public void destroyAll();
-
- /**
- * Retrieves a class loader that has been previously created.
- *
- * @param classLoaderInfo identifies the class loader to be retrieved
- * @return the class loader corresponding to {@code classLoaderInfo}
- * @throws Exception if an unexpected error occurs
- */
- public ClassLoader retrieve(I classLoaderInfo) throws Exception;
-
- /**
- * Retrieves all class loaders that have been created so far.
- *
- * @return a collection with all class loaders that have been created (excluding the ones
- * that have been destroyed)
- */
- public Collection<ClassLoader> retrieveAll();
-
- /**
- * Checks whether the class loader corresponding to {@code classLoaderInfo} is available
- * (i.e. whether is has been created but is not destroyed yet).
- *
- * @param classLoaderBuilder identifies the loader whose availability is going to be checked
- * @return {@code true} only if a class loader has been created for {@code classLoaderInfo}
- * and has not been destroyed
- * @throws Exception if an unexpected error occurs
- */
- public boolean isAvailable(I classLoaderInfo) throws Exception;
-}
\ No newline at end of file
Deleted: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassLoaderInfo.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassLoaderInfo.java 2009-12-11 01:48:42 UTC (rev 97710)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassLoaderInfo.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -1,31 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.classpool.support;
-
-/**
- * Contains information necessary for the ClassLoaderFactory that will be used to
- * create the ClassLoaders.
- *
- * @author <a href="mailto:flavia.rainone at jboss.org">Flavia Rainone</a>
- * @version $Revision$
- */
-public interface ClassLoaderInfo {}
\ No newline at end of file
Deleted: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassPoolTestScenario.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassPoolTestScenario.java 2009-12-11 01:48:42 UTC (rev 97710)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ClassPoolTestScenario.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -1,204 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.classpool.support;
-
-import java.net.URL;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.NotFoundException;
-import junit.framework.Assert;
-
-import org.jboss.classpool.spi.ClassPoolRepository;
-
-/**
- * This scenario is used by class pool test cases. All the operations performed using this
- * scenario are executed over CtClasses and ClassPools.
- *
- * @param <I> the ClassLoaderInfo that will be used to create class loaders for this scenario
- *
- * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
- * @version $Revision$
- */
-public class ClassPoolTestScenario<I extends ClassLoaderInfo> extends TestScenario<CtClass, ClassPool, I>
-{
- /** The ClassPool repository */
- protected ClassPoolRepository repository;
-
- /**
- * Constructor.
- *
- * @param classLoaderFactory creates class loaders for the loader scenario.
- * @param <I> the info that {@code classLoaderFactory} uses to create a class loader
- */
- public ClassPoolTestScenario(ClassLoaderFactory<I> classLoaderFactory)
- {
- super(classLoaderFactory);
- repository = ClassPoolRepository.getInstance();
- }
-
- @Override
- public ClassPool getLoader(CtClass clazz)
- {
- return assertRegisterClassLoader(clazz.getClassPool().getClassLoader());
- }
-
- @Override
- public ClassPool getLoader(ClassLoader classLoader)
- {
- return assertRegisterClassLoader(classLoader);
- }
-
- @Override
- public ClassLoader getClassLoader(ClassPool classPool)
- {
- return classPool.getClassLoader();
- }
-
- @Override
- public CtClass loadClass(ClassPool classPool, ClassPool expectedClassPool, String className)
- throws Exception
- {
- Class<?> clazz = assertLoadClass(classPool.getClassLoader(), expectedClassPool.getClassLoader(), className);
- CtClass ctClass = assertLoadCtClass(className, classPool, expectedClassPool);
- Assert.assertEquals(className, ctClass.getName());
- Assert.assertEquals("Class has been loaded by the wrong class loader: " + className,
- clazz.getClassLoader(), ctClass.getClassPool().getClassLoader());
- return ctClass;
- }
-
- @Override
- public void cannotLoadClass(ClassPool classPool, String className)
- {
- try
- {
- classPool.getCtClass(className);
- Assert.fail("Should not have been able to load " + className);
- }
- catch(NotFoundException expected){}
- }
-
- @Override
- public CtClass getMethodReturnType(CtClass clazz, String methodName) throws Exception
- {
- return clazz.getDeclaredMethod(methodName).getReturnType();
- }
-
- /********* HELPER METHODS ***************************************************************/
-
- private ClassPool assertRegisterClassLoader(ClassLoader loader)
- {
- ClassPool classPool = repository.registerClassLoader(loader);
- Assert.assertNotNull(classPool);
- assertBootstrap(classPool, String.class, Class.class, ClassLoader.class, Object.class,
- Collection.class, List.class, Map.class, URL.class);
- return classPool;
- }
-
- private void assertBootstrap(ClassPool classPool, Class<?>... classes)
- {
- assertSameClassPool(null, classPool, int.class, boolean.class, byte.class, short.class,
- long.class, float.class, double.class, char.class, void.class);
- assertSameClassPool(ClassPool.getDefault(), classPool, classes);
-
- }
-
- private void assertSameClassPool(ClassPool expectedClassPool, ClassPool classPool,
- Class<?>... classes)
- {
- for (Class<?> clazz: classes)
- {
- CtClass ctClass = null;
- try
- {
- ctClass = classPool.getCtClass(clazz.getName());
- } catch (NotFoundException e)
- {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
- Assert.assertSame("Class " + clazz.getName() + " loaded by unexpected class pool ",
- expectedClassPool, ctClass.getClassPool());
- }
- }
-
- protected CtClass assertLoadCtClass(String name, ClassPool initiating, ClassPool expected) throws Exception
- {
- CtClass clazz = initiating.get(name);
- if (expected != null)
- {
- Assert.assertSame(expected, clazz.getClassPool());
- }
- //Load twice to test both create and cache
- clazz = initiating.get(name);
- if (expected != null)
- {
- Assert.assertSame(expected, clazz.getClassPool());
- }
-
- assertLoadCtClassArray(name, clazz, initiating, expected);
-
- return clazz;
- }
-
- private void assertLoadCtClassArray(String name, CtClass clazz, ClassPool initiating, ClassPool expected) throws Exception
- {
- assertLoadCtClassArray(name, clazz, 1, initiating, expected);
- assertLoadCtClassArray(name, clazz, 2, initiating, expected);
- }
-
- private void assertLoadCtClassArray(String name, CtClass clazz, int dimensions, ClassPool initiating, ClassPool expected) throws Exception
- {
- String arrayName = name;
- for (int i = 0 ; i < dimensions ; i++)
- {
- arrayName = arrayName + "[]";
- }
- CtClass array = initiating.get(arrayName);
-
- if (expected != null)
- {
- Assert.assertSame(expected, array.getClassPool());
- }
-
- Assert.assertSame(clazz.getClassPool(), array.getClassPool());
-
- CtClass type = array;
- for (int i = 0 ; i < dimensions ; i++)
- {
- type = type.getComponentType();
- }
- Assert.assertSame(type, clazz);
- }
-
- @Override
- protected void preDestroy(Collection<ClassLoader> classLoaders)
- {
- for (ClassLoader classLoader: classLoaders)
- {
- repository.unregisterClassLoader(classLoader);
- }
- }
-}
Deleted: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SanityTestScenario.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SanityTestScenario.java 2009-12-11 01:48:42 UTC (rev 97710)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SanityTestScenario.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -1,89 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.classpool.support;
-
-
-import junit.framework.Assert;
-
-/**
- * This scenario is used by sanity tests, i.e., tests that check whether the class loaders
- * represented by class pools actually behave as expected.
- *
- * @param <I> the ClassLoaderInfo that will be used to create class loaders for this scenario
- *
- * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
- * @version $Revision$
- */
-public class SanityTestScenario<I extends ClassLoaderInfo> extends TestScenario<Class<?>, ClassLoader, I>
-{
- /**
- * Constructor.
- *
- * @param classLoaderFactory creates class loaders for the loader scenario.
- * @param <I> the info that {@code classLoaderFactory} uses to create a class loader
- */
- public SanityTestScenario(ClassLoaderFactory<I> classLoaderFactory)
- {
- super(classLoaderFactory);
- }
-
- @Override
- public ClassLoader getLoader(Class<?> clazz)
- {
- return clazz.getClassLoader();
- }
-
- @Override
- public ClassLoader getLoader(ClassLoader classLoader)
- {
- return classLoader;
- }
-
- @Override
- public ClassLoader getClassLoader(ClassLoader loader)
- {
- return loader;
- }
-
- @Override
- public Class<?> loadClass(ClassLoader loader, ClassLoader expected, String className) throws Exception
- {
- return assertLoadClass(loader, expected, className);
- }
-
- @Override
- public void cannotLoadClass(ClassLoader classLoader, String className)
- {
- try
- {
- classLoader.loadClass(className);
- Assert.fail("Should not have been able to load " + className);
- }
- catch(ClassNotFoundException expected){}
- }
-
- @Override
- public Class<?> getMethodReturnType(Class<?> clazz, String methodName) throws Exception
- {
- return clazz.getDeclaredMethod(methodName).getReturnType();
- }
-}
\ No newline at end of file
Deleted: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportArchives.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportArchives.java 2009-12-11 01:48:42 UTC (rev 97710)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportArchives.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -1,142 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.classpool.support;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-
-/**
- * Contains the name of the support archives.
- *
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- * @version $Revision$
- */
-public class SupportArchives
-{
- private static final String UTIL_JAR = "lib/util.jar";
- private static final String EXT_JAR = "lib/ext.jar";
- private static final String UI_JAR = "lib/ui.jar";
- private static final String UI_UTIL_JAR = "lib/ui_util.jar";
- private static String WAR_CP = "/WEB-INF/classes";
-
- /************ ARCHIVE NAMES *************************************************************/
-
- public final static String JAR_A_1 = "a1.jar";
- public final static String JAR_A_2 = "a2.jar";
- public final static String JAR_B_1 = "b1.jar";
- public final static String JAR_B_2 = "b2.jar";
- public final static String JAR_C_1 = "c1.jar";
- public final static String JAR_C_2 = "c2.jar";
- public final static String JAR_D = "d.jar";
- public final static String SIMPLE_JAR = "simple.jar";
- public final static String SIMPLE_SAR = "simple.sar";
- public final static String EJB_JAR = "ejbs.jar";
- public final static String SIMPLE_WAR = "simple.war";
- public final static String SIMPLE_EAR = "simple.ear";
- public final static String SIMPLE_EAR_JAR = SIMPLE_EAR + '/' + SIMPLE_JAR;
- public final static String SIMPLE_EAR_SAR = SIMPLE_EAR + '/' + SIMPLE_SAR;
- public final static String SIMPLE_EAR_EJB = SIMPLE_EAR + '/' + EJB_JAR;
- public final static String SIMPLE_EAR_LIB1 = SIMPLE_EAR + '/' + UTIL_JAR;
- public final static String SIMPLE_EAR_LIB2 = SIMPLE_EAR + '/' + EXT_JAR;
- public final static String SIMPLE_EAR_WAR1 = SIMPLE_EAR + "/simple_ui.war";
- public final static String SIMPLE_EAR_WAR1_LIB = SIMPLE_EAR_WAR1 + "/WEB-INF/" + UI_JAR;
- public final static String SIMPLE_EAR_WAR2 = SIMPLE_EAR + "/jsfapp.war";
- public final static String SIMPLE_EAR_WAR2_LIB = SIMPLE_EAR_WAR2 + "/WEB-INF/" + UI_UTIL_JAR;
- public final static String TOP_EAR = "top-level.ear";
- public final static String TOP_EAR_UTIL = TOP_EAR + '/' + UTIL_JAR;
- public final static String TOP_EAR_EXT = TOP_EAR + '/' + EXT_JAR;
- public final static String WAR_IN_EAR = "war-in-ear.ear";
- public final static String WAR_IN_EAR_WAR = WAR_IN_EAR + '/' + SIMPLE_WAR;
- public final static String JAR_IN_EAR = "jar-in-ear.ear";
- public final static String JAR_IN_EAR_JAR = JAR_IN_EAR + '/' + SIMPLE_JAR;
- public final static String SERVLET_JAR = "servlet.jar";
- public final static String PTD_EAR = "ptd-ear-1.0-SNAPSHOT.ear";
- public final static String PTD_EAR_LIB = PTD_EAR + "/lib/common.jar";
- public final static String PTD_JSF_WAR = PTD_EAR + "/ptd-jsf-1.0-SNAPSHOT.war";
- public final static String PTD_JSF_WAR_LIB = PTD_JSF_WAR + "/WEB-INF/lib/wj1.jar";
- public final static String PTD_WS_WAR = PTD_EAR + "/ptd-ws-1.0-SNAPSHOT.war";
- public final static String PTD_WS_WAR_LIB = PTD_WS_WAR + "/WEB-INF/lib/wj2.jar";
- public final static String PARENT_JAR = "replacereferences-parent.jar";
- public final static String CHILD_JAR = "replacereferences-child.jar";
- // TODO JBREFLECT-80
- //public final static String EXCLUDED_CLASSPATH = "../test-classes";
- public final static String EXCLUDED_CLASSPATH = "../test-excluded-classes";
-
- /************ CLASSPATH URLS ************************************************************/
-
- public final static URL JAR_A_1_URL = getURL(JAR_A_1);
- public final static URL JAR_A_2_URL = getURL(JAR_A_2);
- public final static URL JAR_B_1_URL = getURL(JAR_B_1);
- public final static URL JAR_B_2_URL = getURL(JAR_B_2);
- public final static URL JAR_C_1_URL = getURL(JAR_C_1);
- public final static URL JAR_C_2_URL = getURL(JAR_C_2);
- public final static URL JAR_D_URL = getURL(JAR_D);
- public final static URL SIMPLE_JAR_URL = getURL(SIMPLE_JAR);
- public final static URL SIMPLE_SAR_URL = getURL(SIMPLE_SAR);
- public final static URL EJB_JAR_URL = getURL(EJB_JAR);
- public final static URL SIMPLE_WAR_CP_URL = getURL(SIMPLE_WAR + WAR_CP);
- public final static URL SIMPLE_EAR_JAR_URL = getURL(SIMPLE_EAR_JAR);
- public final static URL SIMPLE_EAR_SAR_URL = getURL(SIMPLE_EAR_SAR);
- public final static URL SIMPLE_EAR_EJB_URL = getURL(SIMPLE_EAR_EJB);
- public final static URL SIMPLE_EAR_LIB1_URL = getURL(SIMPLE_EAR_LIB1);
- public final static URL SIMPLE_EAR_LIB2_URL = getURL(SIMPLE_EAR_LIB2);
- public final static URL SIMPLE_EAR_WAR1_URL = getURL(SIMPLE_EAR_WAR1);
- public final static URL SIMPLE_EAR_WAR1_CP_URL = getURL(SIMPLE_EAR_WAR1 + WAR_CP);
- public final static URL SIMPLE_EAR_WAR1_LIB_URL = getURL(SIMPLE_EAR_WAR1_LIB);
- public final static URL SIMPLE_EAR_WAR2_URL = getURL(SIMPLE_EAR_WAR2);
- public final static URL SIMPLE_EAR_WAR2_CP_URL = getURL(SIMPLE_EAR_WAR2 + WAR_CP);
- public final static URL SIMPLE_EAR_WAR2_LIB_URL = getURL(SIMPLE_EAR_WAR2_LIB);
- public final static URL TOP_EAR_UTIL_URL = getURL(TOP_EAR_UTIL);
- public final static URL TOP_EAR_EXT_URL = getURL(TOP_EAR_EXT);
- public final static URL WAR_IN_EAR_WAR_URL = getURL(WAR_IN_EAR_WAR);
- public final static URL WAR_IN_EAR_WAR_CP = getURL(WAR_IN_EAR_WAR + WAR_CP);
- public final static URL JAR_IN_EAR_JAR_URL = getURL(JAR_IN_EAR_JAR);
- public final static URL SERVLET_JAR_URL = getURL(SERVLET_JAR);
- public final static URL PTD_EAR_LIB_URL = getURL(PTD_EAR_LIB);
- public final static URL PTD_JSF_WAR_URL = getURL(PTD_JSF_WAR);
- public final static URL PTD_JSF_WAR_LIB_URL = getURL(PTD_JSF_WAR_LIB);
- public final static URL PTD_WS_WAR_URL = getURL(PTD_WS_WAR);
- public final static URL PTD_WS_WAR_LIB_URL = getURL(PTD_WS_WAR_LIB);
- public final static URL EXCLUDED_CLASSPATH_URL = getURL(EXCLUDED_CLASSPATH);
- public final static URL PARENT_JAR_URL = getURL(PARENT_JAR);
- public final static URL CHILD_JAR_URL = getURL(CHILD_JAR);
-
- /** Returns the relative URL to the project root */
- private static URL getURL(String relativePath)
- {
- try
- {
- URL url = SupportArchives.class.getProtectionDomain().getCodeSource().getLocation();
- String location = url.toString();
- int index = location.lastIndexOf("/target/") + "/target/".length();
- location = location.substring(0, index) + "archives/";
-
- location = location + relativePath;
- return new URL(location);
- }
- catch (MalformedURLException e)
- {
- throw new RuntimeException(e);
- }
- }
-}
\ No newline at end of file
Deleted: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportClasses.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportClasses.java 2009-12-11 01:48:42 UTC (rev 97710)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportClasses.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -1,81 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.classpool.support;
-
-
-
-/**
- * Contains the name of all support classes.
- *
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- * @version $Revision$
- */
-public class SupportClasses
-{
- public static final String PACKAGE_ROOT = SupportClasses.class.getPackage().getName() + ".excluded";
- public final static String PACKAGE_A = PACKAGE_ROOT + ".a";
- public final static String PACKAGE_B = PACKAGE_ROOT + ".b";
- public final static String PACKAGE_C = PACKAGE_ROOT + ".c";
- public final static String PACKAGE_D = PACKAGE_ROOT + ".d";
- public final static String PACKAGE_JAR = PACKAGE_ROOT + ".jar";
- public final static String PACKAGE_SAR = PACKAGE_ROOT + ".service";
- public final static String PACKAGE_EJB = PACKAGE_ROOT + ".ejb";
- public final static String PACKAGE_WEB = PACKAGE_ROOT + ".web";
- public final static String PACKAGE_JSF = PACKAGE_ROOT + ".jsf";
- public final static String PACKAGE_UTIL = PACKAGE_ROOT + ".util";
- public final static String PACKAGE_EXT = PACKAGE_ROOT + ".ext";
- public final static String PACKAGE_UI = PACKAGE_ROOT + ".ui";
- public final static String PACKAGE_CRM = PACKAGE_ROOT + ".crm";
- public final static String PACKAGE_TIF = PACKAGE_ROOT + ".tif";
-
- public final static String CLASS_A = PACKAGE_A + ".A";
- public final static String CLASS_B = PACKAGE_B + ".B";
- public final static String CLASS_C = PACKAGE_C + ".C";
- public final static String CLASS_D = PACKAGE_D + ".D";
- public final static String CLASS_PLAIN = PACKAGE_JAR + ".PlainJavaBean";
- public final static String CLASS_MBEAN = PACKAGE_SAR + ".SomeMBean";
- public final static String CLASS_SLS_BEAN = PACKAGE_EJB + ".MySLSBean";
- public final static String CLASS_SLS_INTERFACE = PACKAGE_EJB + ".BusinessInterface";
- public final static String CLASS_SERVLET = PACKAGE_WEB + ".AnyServlet";
- public final static String CLASS_JSF = PACKAGE_JSF + ".JsfBean";
- public final static String CLASS_UTIL = PACKAGE_UTIL + ".SomeUtil";
- public final static String CLASS_EXT = PACKAGE_EXT + ".External";
- public final static String CLASS_UI = PACKAGE_UI + ".UIBean";
- public final static String CLASS_CRM = PACKAGE_CRM + ".CrmFacade";
- public final static String CLASS_TIF = PACKAGE_TIF + ".TIFTester";
-
- private static final String[] SUPPORT_CLASSES = new String[]{CLASS_A, CLASS_B, CLASS_C,
- CLASS_D, CLASS_PLAIN, CLASS_MBEAN, CLASS_SLS_BEAN, CLASS_SLS_INTERFACE, CLASS_SERVLET,
- CLASS_JSF, CLASS_UTIL, CLASS_EXT, CLASS_UI, CLASS_CRM, CLASS_TIF};
-
- public static final String[] getAllSupportClasses()
- {
- return SUPPORT_CLASSES;
- }
-
- public final static String PACKAGE_REPLACEMENT = PACKAGE_ROOT + ".replacereferences";
- public final static String PACKAGE_REPLACEMENT_CHILD = PACKAGE_REPLACEMENT + ".child";
- public final static String PACKAGE_REPLACEMENT_PARENT = PACKAGE_REPLACEMENT + ".parent";
- public final static String CLASS_INVOKED = PACKAGE_REPLACEMENT + ".Invoked";
- public final static String CLASS_PARENT_CALLER = PACKAGE_REPLACEMENT_PARENT + ".ParentCaller";
- public final static String CLASS_CHILD_CALLER = PACKAGE_REPLACEMENT_CHILD + ".ChildCaller";
-}
\ No newline at end of file
Deleted: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestScenario.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestScenario.java 2009-12-11 01:48:42 UTC (rev 97710)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestScenario.java 2009-12-11 02:03:03 UTC (rev 97711)
@@ -1,223 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.classpool.support;
-
-import java.util.Collection;
-
-import org.jboss.test.classpool.jbosscl.support.NoSuchClassLoaderException;
-
-import junit.framework.Assert;
-
-
-/**
- * Abstracts the concept of loader (L) and classes (C).
- * This class allows the implementation of tests that don't rely on the actual type of
- * L and C.
- * @param <C> represents a class
- * @param <L> responsbile for loading a class
- * @param <I> the ClassLoaderInfo that will be used to create class loaders for this scenario
- *
- * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
- * @version $Revision$
- * @see SanityTestScenario
- * @see ClassPoolTestScenario
- */
-public abstract class TestScenario<C,L,I extends ClassLoaderInfo>
-{
- /** The classloader factory */
- private ClassLoaderFactory<I> classLoaderFactory;
-
- /**
- * Constructor.
- *
- * @param classLoaderFactory creates class loaders for the loader scenario.
- * @param <I> the info that {@code classLoaderFactory} uses to create a class loader
- */
- public TestScenario(ClassLoaderFactory<I> classLoaderFactory)
- {
- this.classLoaderFactory = classLoaderFactory;
- }
-
- /**
- * Creates a loader.
- *
- * @param classLoaderBuilder contains all the info necessary for the creation of a loader
- * @return the created loader
- * @throws NoSuchClassLoaderException indicates that the deployment is not successful. The
- * class loader is not created at this moment
- * @throws Exception if an unexpected error occurs
- */
- public L createLoader(I classLoaderInfo) throws NoSuchClassLoaderException, Exception
- {
- ClassLoader classLoader = classLoaderFactory.create(classLoaderInfo);
- return getLoader(classLoader);
- }
-
- /**
- * Destroys the loader corresponding to classLoaderBuilder.
- * This method can be invoked only after the loader has been
- * {@link #createLoader(I) created}.
- *
- * @param classLoaderInfo contains information regarding the loader to be destroyed.
- * @throws Exception if an unexpected error occurs
- * @see #createLoader(I)
- */
- public void destroyLoader(I classLoaderInfo) throws Exception
- {
- classLoaderFactory.destroy(classLoaderInfo);
- }
-
- /**
- * Destroy all loaders that have been created so far (except for loaders that have already
- * been {@link #destroyLoader(I) destroyed}).
- */
- public void destroyLoaders()
- {
- preDestroy(classLoaderFactory.retrieveAll());
- classLoaderFactory.destroyAll();
- }
-
- /**
- * Returns the loader corresponding to {@code classLoaderBuilder}. This method can be
- * invoked only after {@code #createLoader(I)}.
- *
- * @param classLoaderInfo contains all the info related to the loader to be retrieved
- * @return the loader equivalent to {@code classLoaderBuilder}
- * @throws Exception if an unexpected error occurs
- * @see {@link #createLoader(I)}
- */
- public L getLoader(I classLoaderInfo) throws Exception
- {
- ClassLoader classLoader = classLoaderFactory.retrieve(classLoaderInfo);
- return getLoader(classLoader);
- }
-
- /**
- * Checks that the loader corresponding to {@code classLoaderBuilder} is no longer
- * available on the test scenario.
- *
- * @param classLoaderInfo identifies the loader that is going to be verified
- * @throws Exception if an unexpected error occurs
- */
- public void cannotGetLoader(I classLoaderInfo) throws Exception
- {
- Assert.assertFalse("Class loader should not be available",
- classLoaderFactory.isAvailable(classLoaderInfo));
- }
-
- /**
- * Returns the loader that loaded {@code clazz}.
- *
- * @param clazz a class that has been previously loaded
- * @return the loader that loaded {@code clazz}
- */
- public abstract L getLoader(C clazz);
-
- /**
- * Returns the loader corresponding to {@code classLoader}.
- *
- * @param classLoader a class loader
- * @return the loader that represents {code classLoader}
- */
- public abstract L getLoader(ClassLoader classLoader);
-
- /**
- * Returns the class loader corresponding to {@code loader}.
- *
- * @param loader a loader
- * @return the class loader that is represented by loader
- */
- public abstract ClassLoader getClassLoader(L loader);
-
- /**
- * Checks that {@code loader} can load {@code className} and returns the loaded class.
- * Also verifies that the loader associated with the loaded class is {@code loader}.
- *
- * @param loader a loader
- * @param className the name of the class to be loaded
- * @return the class loaded by {@code loader}
- * @throws Exception if an unexpected error occurs
- */
- public C loadClass(L loader, String className) throws Exception
- {
- return loadClass(loader, loader, className);
- }
-
- /**
- * Checks that {@code loader} can load {@code className} and returns the loaded class.
- * Also verifies that the loader associated with the loaded class is {@code expected}.
- *
- * @param initiating the loader that will be used for loading {@code className}
- * @param expected the actual loader that is associated with the loaded class
- * @param className the name of the class to be loaded
- * @return the loaded class
- * @throws Exception if an unexpected error occurs
- */
- public abstract C loadClass(L initiating, L expected, String className) throws Exception;
-
- /**
- * Checks that {@code loader} cannot load class {@code className}.
- *
- * @param loader a loader
- * @param className the name of the class that can't be loaded by {@code loader}
- */
- public abstract void cannotLoadClass(L loader, String className);
-
- /**
- * Returns the return type of a method declared in {@code clazz}.
- *
- * @param clazz the class that contains the method
- * @param methodName the name of the method
- * @return the return type of the method
- * @throws Exception if an unexpected error occurs
- */
- public abstract C getMethodReturnType(C clazz, String methodName) throws Exception;
-
- /**
- * Asserts that {@code initiating} class loader can load {@code classname}.
- * Also verifies that the class loader associated with the loaded class is {@code expected}
- *
- * @param initiating the class loader that will be used for loading {@code className}
- * @param expected the actual class loader that is associated with the loaded class
- * @param className the name of the class to be loaded
- * @return the loaded class
- * @throws Exception if an unexpected error occurs
- */
- protected Class<?> assertLoadClass(ClassLoader initiating, ClassLoader expected, String className) throws Exception
- {
- Class<?> clazz = initiating.loadClass(className);
- if (expected != null)
- {
- Assert.assertSame(expected, clazz.getClassLoader());
- }
- return clazz;
- }
-
- /**
- * Is called prior to destroy the class loaders in {@code classLoaders} collection.
- *
- * @param classLoaders the class loaders that will be destroyed
- */
- protected void preDestroy(Collection<ClassLoader> classLoaders)
- {
- }
-}
\ No newline at end of file
Modified: projects/jboss-classpool/trunk/src/test/resources/org/jboss/test/classpool/jbosscl/Common.xml
===================================================================
--- projects/jboss-classpool/trunk/src/test/resources/org/jboss/test/classpool/jbosscl/Common.xml 2009-12-11 01:48:42 UTC (rev 97710)
+++ projects/jboss-classpool/trunk/src/test/resources/org/jboss/test/classpool/jbosscl/Common.xml 2009-12-11 02:03:03 UTC (rev 97711)
@@ -11,11 +11,11 @@
<uncallback method="removeModule" state="Configured"/>
</bean>
- <bean name="ClassLoaderScopingPolicy" class="org.jboss.classpool.plugins.as5.VFSClassLoaderDomainRegistry">
+ <bean name="ClassLoaderScopingPolicy" class="org.jboss.classpool.plugins.jbosscl.VFSClassLoaderDomainRegistry">
<constructor factoryMethod="getInstance"/>
</bean>
- <bean name="RegisterModuleCallback" class="org.jboss.classpool.plugins.as5.RegisterModuleCallback">
+ <bean name="RegisterModuleCallback" class="org.jboss.classpool.plugins.jbosscl.RegisterModuleCallback">
<constructor>
<parameter><inject bean="ClassLoaderScopingPolicy"/></parameter>
</constructor>
@@ -27,14 +27,14 @@
</uninstall>
</bean>
- <bean name="ClassPoolFactory" class="org.jboss.classpool.plugins.as5.jbosscl.JBossClDelegatingClassPoolFactory">
+ <bean name="ClassPoolFactory" class="org.jboss.classpool.plugins.jbosscl.JBossClDelegatingClassPoolFactory">
<constructor>
<parameter><inject bean="ClassLoaderScopingPolicy"/></parameter>
<parameter><inject bean="RegisterModuleCallback"/></parameter>
</constructor>
</bean>
- <bean name="ClassPoolRepository" class="org.jboss.classpool.plugins.as5.jbosscl.JBossClDelegatingClassPoolRepository">
+ <bean name="ClassPoolRepository" class="org.jboss.classpool.plugins.jbosscl.JBossClDelegatingClassPoolRepository">
<constructor factoryMethod="getInstance"/>
<property name="classPoolFactory"><inject bean="ClassPoolFactory"/></property>
</bean>
More information about the jboss-cvs-commits
mailing list