Spelling
This commit is contained in:
@@ -23,7 +23,7 @@ import junit.framework.TestCase;
|
||||
/**
|
||||
* Test the ability to force the LogFactory class to use some
|
||||
* arbitrary Hashtable implementation to store its mapping from
|
||||
* context-classloader -> LogFactory object.
|
||||
* context class loader -> LogFactory object.
|
||||
*/
|
||||
public class AltHashtableTestCase extends TestCase {
|
||||
|
||||
@@ -61,7 +61,7 @@ public class AltHashtableTestCase extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that when LogFactory sees a context-classloader for the
|
||||
* Verify that when LogFactory sees a context class loader for the
|
||||
* first time that it creates a new entry in the LogFactory.factories
|
||||
* hashmap. In particular, this checks that this process works ok when
|
||||
* a system property has been used to specify an alternative Hashtable
|
||||
@@ -86,7 +86,7 @@ public class AltHashtableTestCase extends TestCase {
|
||||
// Here, the reference to the LogFactory class should cause the
|
||||
// class to be loaded and initialized. It will see the property
|
||||
// set and use the AltHashtable class. If other tests in this
|
||||
// class have already been run within the same classloader then
|
||||
// class have already been run within the same class loader then
|
||||
// LogFactory will already have been initialized, but that
|
||||
// doesn't change the effectiveness of this test.
|
||||
assertTrue(LogFactory.factories instanceof AltHashtable);
|
||||
|
||||
@@ -26,13 +26,13 @@ import junit.framework.TestCase;
|
||||
public class LoadTestCase extends TestCase {
|
||||
|
||||
/**
|
||||
* A custom classloader which "duplicates" logging classes available
|
||||
* in the parent classloader into itself.
|
||||
* A custom class loader which "duplicates" logging classes available
|
||||
* in the parent class loader into itself.
|
||||
* <p>
|
||||
* When asked to load a class that is in one of the LOG_PCKG packages,
|
||||
* it loads the class itself (child-first). This class doesn't need
|
||||
* to be set up with a classpath, as it simply uses the same classpath
|
||||
* as the classloader that loaded it.
|
||||
* as the class loader that loaded it.
|
||||
*/
|
||||
static class AppClassLoader extends ClassLoader {
|
||||
|
||||
@@ -79,7 +79,7 @@ public class LoadTestCase extends TestCase {
|
||||
@Override
|
||||
public Class loadClass(final String name) throws ClassNotFoundException {
|
||||
|
||||
// isolates all logging classes, application in the same classloader too.
|
||||
// isolates all logging classes, application in the same class loader too.
|
||||
// filters exceptions to simplify handling in test
|
||||
for (final String element : LOG_PCKG) {
|
||||
if (name.startsWith(element) && name.indexOf("Exception") == -1) {
|
||||
@@ -103,8 +103,8 @@ public class LoadTestCase extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load class UserClass via a temporary classloader which is a child of
|
||||
* the classloader used to load this test class.
|
||||
* Load class UserClass via a temporary class loader which is a child of
|
||||
* the class loader used to load this test class.
|
||||
*/
|
||||
private Class reload() throws Exception {
|
||||
Class testObjCls = null;
|
||||
@@ -129,7 +129,7 @@ public class LoadTestCase extends TestCase {
|
||||
|
||||
/**
|
||||
* Call the static setAllowFlawedContext method on the specified class
|
||||
* (expected to be a UserClass loaded via a custom classloader), passing
|
||||
* (expected to be a UserClass loaded via a custom class loader), passing
|
||||
* it the specified state parameter.
|
||||
*/
|
||||
private void setAllowFlawedContext(final Class c, final String state) throws Exception {
|
||||
@@ -151,7 +151,7 @@ public class LoadTestCase extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test what happens when we play various classloader tricks like those
|
||||
* Test what happens when we play various class loader tricks like those
|
||||
* that happen in web and j2ee containers.
|
||||
* <p>
|
||||
* Note that this test assumes that commons-logging.jar and log4j.jar
|
||||
@@ -166,19 +166,19 @@ public class LoadTestCase extends TestCase {
|
||||
// 1. Thread.currentThread().setContextClassLoader(appLoader);
|
||||
// 2. Thread.currentThread().setContextClassLoader(null);
|
||||
|
||||
// Context classloader is same as class calling into log
|
||||
// Context class loader is same as class calling into log
|
||||
Class cls = reload();
|
||||
Thread.currentThread().setContextClassLoader(cls.getClassLoader());
|
||||
execute(cls);
|
||||
|
||||
// Context classloader is the "bootclassloader". This is technically
|
||||
// Context class loader is the "bootclass loader". This is technically
|
||||
// bad, but LogFactoryImpl.ALLOW_FLAWED_CONTEXT defaults to true so
|
||||
// this test should pass.
|
||||
cls = reload();
|
||||
Thread.currentThread().setContextClassLoader(null);
|
||||
execute(cls);
|
||||
|
||||
// Context classloader is the "bootclassloader". This is same as above
|
||||
// Context class loader is the "bootclass loader". This is same as above
|
||||
// except that ALLOW_FLAWED_CONTEXT is set to false; an error should
|
||||
// now be reported.
|
||||
cls = reload();
|
||||
@@ -186,27 +186,27 @@ public class LoadTestCase extends TestCase {
|
||||
try {
|
||||
setAllowFlawedContext(cls, "false");
|
||||
execute(cls);
|
||||
fail("Logging config succeeded when context classloader was null!");
|
||||
fail("Logging config succeeded when context class loader was null!");
|
||||
} catch (final InvocationTargetException ex) {
|
||||
final Throwable targetException = ex.getTargetException();
|
||||
// LogConfigurationException is expected; the boot classloader doesn't *have* JCL available
|
||||
// LogConfigurationException is expected; the boot class loader doesn't *have* JCL available
|
||||
if (!(targetException instanceof LogConfigurationException)) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
// Context classloader is the system classloader.
|
||||
// Context class loader is the system class loader.
|
||||
//
|
||||
// This is expected to cause problems, as LogFactoryImpl will attempt
|
||||
// to use the system classloader to load the Log4JLogger class, which
|
||||
// to use the system class loader to load the Log4JLogger class, which
|
||||
// will then be unable to cast that object to the Log interface loaded
|
||||
// via the child classloader. However as ALLOW_FLAWED_CONTEXT defaults
|
||||
// via the child class loader. However as ALLOW_FLAWED_CONTEXT defaults
|
||||
// to true this test should pass.
|
||||
cls = reload();
|
||||
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
|
||||
execute(cls);
|
||||
|
||||
// Context classloader is the system classloader. This is the same
|
||||
// Context class loader is the system class loader. This is the same
|
||||
// as above except that ALLOW_FLAWED_CONTEXT is set to false; an error
|
||||
// should now be reported.
|
||||
cls = reload();
|
||||
@@ -214,8 +214,8 @@ public class LoadTestCase extends TestCase {
|
||||
try {
|
||||
setAllowFlawedContext(cls, "false");
|
||||
execute(cls);
|
||||
fail("Error: somehow downcast a Logger loaded via system classloader"
|
||||
+ " to the Log interface loaded via a custom classloader");
|
||||
fail("Error: somehow downcast a Logger loaded via system class loader"
|
||||
+ " to the Log interface loaded via a custom class loader");
|
||||
} catch (final InvocationTargetException ex) {
|
||||
final Throwable targetException = ex.getTargetException();
|
||||
// LogConfigurationException is expected
|
||||
|
||||
@@ -21,7 +21,7 @@ import junit.framework.TestCase;
|
||||
/**
|
||||
* Test cases for situations where getClassLoader or getContextClassLoader
|
||||
* return null. This can happen when using JDK 1.1. It can also happen when
|
||||
* JCL is deployed via the bootclassloader - something that could be done when
|
||||
* JCL is deployed via the bootclass loader - something that could be done when
|
||||
* using java in embedded systems.
|
||||
*/
|
||||
public class NullClassLoaderTestCase extends TestCase {
|
||||
@@ -35,7 +35,7 @@ public class NullClassLoaderTestCase extends TestCase {
|
||||
*/
|
||||
public void testSameLogObject() throws Exception {
|
||||
// unfortunately, there just isn't any way to emulate JCL being
|
||||
// accessible via the null classloader in "standard" systems, so
|
||||
// accessible via the null class loader in "standard" systems, so
|
||||
// we can't include this test in our standard unit tests.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import junit.framework.Assert;
|
||||
* A ClassLoader which sees only specified classes, and which can be
|
||||
* set to do parent-first or child-first path lookup.
|
||||
* <p>
|
||||
* Note that this classloader is not "industrial strength"; users
|
||||
* Note that this class loader is not "industrial strength"; users
|
||||
* looking for such a class may wish to look at the Tomcat sourcecode
|
||||
* instead. In particular, this class may not be threadsafe.
|
||||
* <p>
|
||||
@@ -54,16 +54,16 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
|
||||
/**
|
||||
* A map of package-prefix to ClassLoader. Any class which is in
|
||||
* this map is looked up via the specified classloader instead of
|
||||
* the classpath associated with this classloader or its parents.
|
||||
* this map is looked up via the specified class loader instead of
|
||||
* the classpath associated with this class loader or its parents.
|
||||
* <p>
|
||||
* This is necessary in order for the rest of the world to communicate
|
||||
* with classes loaded via a custom classloader. As an example, junit
|
||||
* tests which are loaded via a custom classloader needs to see
|
||||
* with classes loaded via a custom class loader. As an example, junit
|
||||
* tests which are loaded via a custom class loader needs to see
|
||||
* the same junit classes as the code invoking the test, otherwise
|
||||
* they can't pass result objects back.
|
||||
* <p>
|
||||
* Normally, only a classloader created with a null parent needs to
|
||||
* Normally, only a class loader created with a null parent needs to
|
||||
* have any lookasides defined.
|
||||
*/
|
||||
private HashMap lookasides;
|
||||
@@ -81,7 +81,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* totally clean; nothing but the standard java library will be
|
||||
* present.
|
||||
* <p>
|
||||
* When using a null parent classloader with a junit test, it *is*
|
||||
* When using a null parent class loader with a junit test, it *is*
|
||||
* necessary for the junit library to also be visible. In this case, it
|
||||
* is recommended that the following code be used:
|
||||
* <pre>
|
||||
@@ -91,7 +91,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* </pre>
|
||||
* Note that this works regardless of whether junit is on the system
|
||||
* classpath, or whether it has been loaded by some test framework that
|
||||
* creates its own classloader to run unit tests in (eg maven2's
|
||||
* creates its own class loader to run unit tests in (eg maven2's
|
||||
* Surefire plugin).
|
||||
*/
|
||||
public PathableClassLoader(final ClassLoader parent) {
|
||||
@@ -108,9 +108,9 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* be found. Typically this is the name of a jar file, or a directory
|
||||
* containing class files.
|
||||
* <p>
|
||||
* If there is no system property, but the classloader that loaded
|
||||
* If there is no system property, but the class loader that loaded
|
||||
* this class is a URLClassLoader then the set of URLs that the
|
||||
* classloader uses for its classpath is scanned; any jar in the
|
||||
* class loader uses for its classpath is scanned; any jar in the
|
||||
* URL set whose name starts with the specified string is added to
|
||||
* the classpath managed by this instance.
|
||||
* <p>
|
||||
@@ -225,14 +225,14 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
final ClassLoader parent = getParent();
|
||||
if (parent == null) {
|
||||
// Alas, there is no method to get matching resources
|
||||
// from a null (BOOT) parent classloader. Calling
|
||||
// from a null (BOOT) parent class loader. Calling
|
||||
// ClassLoader.getSystemClassLoader isn't right. Maybe
|
||||
// calling Class.class.getResources(name) would do?
|
||||
//
|
||||
// However for the purposes of unit tests, we can
|
||||
// simply assume that no relevant resources are
|
||||
// loadable from the parent; unit tests will never be
|
||||
// putting any of their resources in a "boot" classloader
|
||||
// putting any of their resources in a "boot" class loader
|
||||
// path!
|
||||
return localUrls;
|
||||
}
|
||||
@@ -245,15 +245,15 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
}
|
||||
|
||||
/**
|
||||
* If the classloader that loaded this class has this logical lib in its
|
||||
* If the class loader that loaded this class has this logical lib in its
|
||||
* path, then return the matching URL otherwise return null.
|
||||
* <p>
|
||||
* This only works when the classloader loading this class is an instance
|
||||
* This only works when the class loader loading this class is an instance
|
||||
* of URLClassLoader and thus has a getURLs method that returns the classpath
|
||||
* it uses when loading classes. However in practice, the vast majority of the
|
||||
* time this type is the classloader used.
|
||||
* time this type is the class loader used.
|
||||
* <p>
|
||||
* The classpath of the classloader for this instance is scanned, and any
|
||||
* The classpath of the class loader for this instance is scanned, and any
|
||||
* jarfile in the path whose name starts with the logicalLib string is
|
||||
* considered a match. For example, passing "foo" will match a url
|
||||
* of {@code file:///some/where/foo-2.7.jar}.
|
||||
@@ -301,7 +301,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* <p>
|
||||
* For each explicitly mapped package prefix, if the name matches the
|
||||
* prefix associated with that entry then attempt to load the class via
|
||||
* that entries' classloader.
|
||||
* that entries' class loader.
|
||||
*/
|
||||
@Override
|
||||
protected Class loadClass(final String name, final boolean resolve)
|
||||
@@ -341,7 +341,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether this classloader should ask the parent classloader
|
||||
* Specify whether this class loader should ask the parent class loader
|
||||
* to resolve a class first, before trying to resolve it via its own
|
||||
* classpath.
|
||||
* <p>
|
||||
@@ -380,13 +380,13 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a classloader to use for specific java packages.
|
||||
* Specify a class loader to use for specific java packages.
|
||||
* <p>
|
||||
* The specified classloader is normally a loader that is NOT
|
||||
* an ancestor of this classloader. In particular, this loader
|
||||
* The specified class loader is normally a loader that is NOT
|
||||
* an ancestor of this class loader. In particular, this loader
|
||||
* may have the bootloader as its parent, but be configured to
|
||||
* see specific other classes (eg the junit library loaded
|
||||
* via the system classloader).
|
||||
* via the system class loader).
|
||||
* <p>
|
||||
* The differences between using this method, and using
|
||||
* addLogicalLib are:
|
||||
@@ -394,11 +394,11 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* <li>If code calls getClassLoader on a class loaded via
|
||||
* "lookaside", then traces up its inheritance chain, it
|
||||
* will see the "real" class loaders. When the class is remapped
|
||||
* into this classloader via addLogicalLib, the classloader
|
||||
* into this class loader via addLogicalLib, the class loader
|
||||
* chain seen is this object plus ancestors.
|
||||
* <li>If two different jars contain classes in the same
|
||||
* package, then it is not possible to load both jars into
|
||||
* the same "lookaside" classloader (eg the system classloader)
|
||||
* the same "lookaside" class loader (eg the system class loader)
|
||||
* then map one of those subsets from here. Of course they could
|
||||
* be loaded into two different "lookaside" class loaders and
|
||||
* then a prefix used to map from here to one of those class loaders.
|
||||
@@ -421,7 +421,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* </pre>
|
||||
* <p>
|
||||
* Of course, this assumes that the classes of interest are already
|
||||
* in the classpath of the system classloader.
|
||||
* in the classpath of the system class loader.
|
||||
*/
|
||||
public void useSystemLoader(final String prefix) {
|
||||
useExplicitLoader(prefix, ClassLoader.getSystemClassLoader());
|
||||
|
||||
@@ -23,10 +23,10 @@ import junit.framework.TestResult;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Custom TestSuite class that can be used to control the context classloader
|
||||
* Custom TestSuite class that can be used to control the context class loader
|
||||
* in operation when a test runs.
|
||||
* <p>
|
||||
* For tests that need to control exactly what the classloader hierarchy is
|
||||
* For tests that need to control exactly what the class loader hierarchy is
|
||||
* like when the test is run, something like the following is recommended:
|
||||
* <pre>
|
||||
* class SomeTestCase extends TestCase {
|
||||
@@ -57,18 +57,18 @@ import junit.framework.TestSuite;
|
||||
* is expected that using the two classes together is common practice.
|
||||
* <p>
|
||||
* This class will run each test methods within the specified TestCase using
|
||||
* the specified context classloader and system classloader. If different
|
||||
* the specified context class loader and system class loader. If different
|
||||
* tests within the same class require different context class loaders,
|
||||
* then the context classloader passed to the constructor should be the
|
||||
* then the context class loader passed to the constructor should be the
|
||||
* "lowest" one available, and tests that need the context set to some parent
|
||||
* of this "lowest" classloader can call
|
||||
* of this "lowest" class loader can call
|
||||
* <pre>
|
||||
* // NB: pseudo-code only
|
||||
* setContextClassLoader(getContextClassLoader().getParent());
|
||||
* </pre>
|
||||
* This class ensures that any context classloader changes applied by a test
|
||||
* This class ensures that any context class loader changes applied by a test
|
||||
* is undone after the test is run, so tests don't need to worry about
|
||||
* restoring the context classloader on exit. This class also ensures that
|
||||
* restoring the context class loader on exit. This class also ensures that
|
||||
* the system properties are restored to their original settings after each
|
||||
* test, so tests that manipulate those don't need to worry about resetting them.
|
||||
* <p>
|
||||
@@ -87,14 +87,14 @@ import junit.framework.TestSuite;
|
||||
* <p>
|
||||
* <h2>Limitations</h2>
|
||||
* <p>
|
||||
* This class cannot control the system classloader (ie what method
|
||||
* This class cannot control the system class loader (ie what method
|
||||
* ClassLoader.getSystemClassLoader returns) because Java provides no
|
||||
* mechanism for setting the system classloader. In this case, the only
|
||||
* mechanism for setting the system class loader. In this case, the only
|
||||
* option is to invoke the unit test in a separate JVM with the appropriate
|
||||
* settings.
|
||||
* <p>
|
||||
* The effect of using this approach in a system that uses junit's
|
||||
* "reloading classloader" behavior is unknown. This junit feature is
|
||||
* "reloading class loader" behavior is unknown. This junit feature is
|
||||
* intended for junit GUI apps where a test may be run multiple times
|
||||
* within the same JVM - and in particular, when the .class file may
|
||||
* be modified between runs of the test. How junit achieves this is
|
||||
@@ -105,7 +105,7 @@ import junit.framework.TestSuite;
|
||||
public class PathableTestSuite extends TestSuite {
|
||||
|
||||
/**
|
||||
* The classloader that should be set as the context classloader
|
||||
* The class loader that should be set as the context class loader
|
||||
* before each test in the suite is run.
|
||||
*/
|
||||
private final ClassLoader contextLoader;
|
||||
@@ -130,7 +130,7 @@ public class PathableTestSuite extends TestSuite {
|
||||
* Note that a Test may itself be a TestSuite object (ie a collection
|
||||
* of tests).
|
||||
* <p>
|
||||
* The context classloader and system properties are saved before each
|
||||
* The context class loader and system properties are saved before each
|
||||
* test, and restored after the test completes to better isolate tests.
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -22,9 +22,9 @@ public class UserClass {
|
||||
|
||||
/**
|
||||
* Sets the ALLOW_FLAWED_CONTEXT feature on the LogFactoryImpl object
|
||||
* associated with this class' classloader.
|
||||
* associated with this class' class loader.
|
||||
* <p>
|
||||
* Don't forget to set the context classloader to whatever it will be
|
||||
* Don't forget to set the context class loader to whatever it will be
|
||||
* when an instance of this class is actually created <i>before</i> calling
|
||||
* this method!
|
||||
*/
|
||||
|
||||
@@ -61,7 +61,7 @@ public class FirstPriorityConfigTestCase extends TestCase {
|
||||
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||
|
||||
// Now set up the desired classloader hierarchy. We'll put JCL
|
||||
// Now set up the desired class loader hierarchy. We'll put JCL
|
||||
// in the container path, the test in a webapp path, and
|
||||
// both config files into the webapp path too.
|
||||
final PathableClassLoader containerLoader = new PathableClassLoader(null);
|
||||
@@ -111,10 +111,10 @@ public class FirstPriorityConfigTestCase extends TestCase {
|
||||
final ClassLoader lfClassLoader = instance.getClass().getClassLoader();
|
||||
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
// context classloader should be thisClassLoader
|
||||
// context class loader should be thisClassLoader
|
||||
assertEquals(thisClassLoader, contextClassLoader);
|
||||
|
||||
// lfClassLoader should be parent of this classloader
|
||||
// lfClassLoader should be parent of this class loader
|
||||
assertEquals(lfClassLoader, thisClassLoader.getParent());
|
||||
assertEquals(PathableClassLoader.class.getName(),
|
||||
lfClassLoader.getClass().getName());
|
||||
|
||||
@@ -68,7 +68,7 @@ public class PriorityConfigTestCase extends TestCase {
|
||||
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||
|
||||
// Now set up the desired classloader hierarchy. We'll put a config
|
||||
// Now set up the desired class loader hierarchy. We'll put a config
|
||||
// file of priority=10 in the container path, and ones of both
|
||||
// "no priority" and priority=20 in the webapp path.
|
||||
//
|
||||
|
||||
@@ -37,7 +37,7 @@ public class CustomConfigAPITestCase extends CustomConfigTestCase {
|
||||
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
|
||||
// the TestHandler class must be accessible from the System classloader
|
||||
// the TestHandler class must be accessible from the System class loader
|
||||
// in order for java.util.logging.LogManager.readConfiguration to
|
||||
// be able to instantiate it. And this test case must see the same
|
||||
// class in order to be able to access its data. Yes this is ugly
|
||||
|
||||
@@ -39,7 +39,7 @@ public class CustomConfigFullTestCase extends CustomConfigTestCase {
|
||||
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
|
||||
// the TestHandler class must be accessible from the System classloader
|
||||
// the TestHandler class must be accessible from the System class loader
|
||||
// in order for java.util.logging.LogManager.readConfiguration to
|
||||
// be able to instantiate it. And this test case must see the same
|
||||
// class in order to be able to access its data. Yes this is ugly
|
||||
|
||||
@@ -48,15 +48,15 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
|
||||
|
||||
/**
|
||||
* Make a class available in the system classloader even when its classfile is
|
||||
* not present in the classpath configured for that classloader. This only
|
||||
* Make a class available in the system class loader even when its classfile is
|
||||
* not present in the classpath configured for that class loader. This only
|
||||
* works for classes for which all dependencies are already loaded in
|
||||
* that classloader.
|
||||
* that class loader.
|
||||
*/
|
||||
protected static void loadTestHandler(final String className, final ClassLoader targetCL) {
|
||||
try {
|
||||
targetCL.loadClass(className);
|
||||
// fail("Class already in target classloader");
|
||||
// fail("Class already in target class loader");
|
||||
return;
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
// ok, go ahead and load it
|
||||
@@ -87,7 +87,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
|
||||
/**
|
||||
* Given the name of a class that is somewhere in the classpath of the provided
|
||||
* classloader, return the contents of the corresponding .class file.
|
||||
* class loader, return the contents of the corresponding .class file.
|
||||
*/
|
||||
protected static byte[] readClass(final String name, final ClassLoader srcCL) throws Exception {
|
||||
final String resName = name.replace('.', '/') + ".class";
|
||||
@@ -115,7 +115,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
final PathableClassLoader cl = new PathableClassLoader(null);
|
||||
cl.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
|
||||
// the TestHandler class must be accessible from the System classloader
|
||||
// the TestHandler class must be accessible from the System class loader
|
||||
// in order for java.util.logging.LogManager.readConfiguration to
|
||||
// be able to instantiate it. And this test case must see the same
|
||||
// class in order to be able to access its data. Yes this is ugly
|
||||
|
||||
@@ -26,7 +26,7 @@ import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests for Log4J logging when there is only one classloader and everything
|
||||
* Tests for Log4J logging when there is only one class loader and everything
|
||||
* is in it, as would be the situation for a standalone application.
|
||||
*/
|
||||
|
||||
|
||||
@@ -45,12 +45,12 @@ public class ChildFirstTestCase extends TestCase {
|
||||
|
||||
|
||||
/**
|
||||
* Sets up a custom classloader hierarchy for this test case.
|
||||
* Sets up a custom class loader hierarchy for this test case.
|
||||
* The hierarchy is:
|
||||
* <ul>
|
||||
* <li> contextloader: child-first.
|
||||
* <li> childloader: child-first, used to load test case.
|
||||
* <li> parentloader: child-first, parent is the bootclassloader.
|
||||
* <li> parentloader: child-first, parent is the bootclass loader.
|
||||
* </ul>
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
@@ -64,7 +64,7 @@ public class ChildFirstTestCase extends TestCase {
|
||||
|
||||
// Make the junit classes visible as a special case, as junit
|
||||
// won't be able to call this class at all without this. The
|
||||
// junit classes must be visible from the classloader that loaded
|
||||
// junit classes must be visible from the class loader that loaded
|
||||
// this class, so use that as the source for future access to classes
|
||||
// from the junit package.
|
||||
parent.useExplicitLoader("junit.", thisClassLoader);
|
||||
@@ -73,20 +73,20 @@ public class ChildFirstTestCase extends TestCase {
|
||||
// Make the commons-logging.jar classes visible via the parent
|
||||
parent.addLogicalLib("commons-logging");
|
||||
|
||||
// Create a child classloader to load the test case through
|
||||
// Create a child class loader to load the test case through
|
||||
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||
child.setParentFirst(false);
|
||||
|
||||
// Obviously, the child classloader needs to have the test classes
|
||||
// Obviously, the child class loader needs to have the test classes
|
||||
// in its path!
|
||||
child.addLogicalLib("testclasses");
|
||||
child.addLogicalLib("commons-logging-adapters");
|
||||
|
||||
// Create a third classloader to be the context classloader.
|
||||
// Create a third class loader to be the context class loader.
|
||||
final PathableClassLoader context = new PathableClassLoader(child);
|
||||
context.setParentFirst(false);
|
||||
|
||||
// reload this class via the child classloader
|
||||
// reload this class via the child class loader
|
||||
final Class testClass = child.loadClass(thisClass.getName());
|
||||
|
||||
// and return our custom TestSuite class
|
||||
@@ -122,56 +122,56 @@ public class ChildFirstTestCase extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the classloader hierarchy is as expected, and that
|
||||
* Test that the class loader hierarchy is as expected, and that
|
||||
* calling loadClass() on various class loaders works as expected.
|
||||
* Note that for this test case, parent-first classloading is
|
||||
* in effect.
|
||||
*/
|
||||
public void testPaths() throws Exception {
|
||||
// the context classloader is not expected to be null
|
||||
// the context class loader is not expected to be null
|
||||
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
assertNotNull("Context classloader is null", contextLoader);
|
||||
assertEquals("Context classloader has unexpected type",
|
||||
assertNotNull("Context class loader is null", contextLoader);
|
||||
assertEquals("Context class loader has unexpected type",
|
||||
PathableClassLoader.class.getName(),
|
||||
contextLoader.getClass().getName());
|
||||
|
||||
// the classloader that loaded this class is obviously not null
|
||||
// the class loader that loaded this class is obviously not null
|
||||
final ClassLoader thisLoader = this.getClass().getClassLoader();
|
||||
assertNotNull("thisLoader is null", thisLoader);
|
||||
assertEquals("thisLoader has unexpected type",
|
||||
PathableClassLoader.class.getName(),
|
||||
thisLoader.getClass().getName());
|
||||
|
||||
// the suite method specified that the context classloader's parent
|
||||
// the suite method specified that the context class loader's parent
|
||||
// is the loader that loaded this test case.
|
||||
assertSame("Context classloader is not child of thisLoader",
|
||||
assertSame("Context class loader is not child of thisLoader",
|
||||
thisLoader, contextLoader.getParent());
|
||||
|
||||
// thisLoader's parent should be available
|
||||
final ClassLoader parentLoader = thisLoader.getParent();
|
||||
assertNotNull("Parent classloader is null", parentLoader);
|
||||
assertEquals("Parent classloader has unexpected type",
|
||||
assertNotNull("Parent class loader is null", parentLoader);
|
||||
assertEquals("Parent class loader has unexpected type",
|
||||
PathableClassLoader.class.getName(),
|
||||
parentLoader.getClass().getName());
|
||||
|
||||
// parent should have a parent of null
|
||||
assertNull("Parent classloader has non-null parent", parentLoader.getParent());
|
||||
assertNull("Parent class loader has non-null parent", parentLoader.getParent());
|
||||
|
||||
// getSystemClassloader is not a PathableClassLoader; it's of a
|
||||
// built-in type. This also verifies that system classloader is none of
|
||||
// built-in type. This also verifies that system class loader is none of
|
||||
// (context, child, parent).
|
||||
final ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
|
||||
assertNotNull("System classloader is null", systemLoader);
|
||||
assertFalse("System classloader has unexpected type",
|
||||
assertNotNull("System class loader is null", systemLoader);
|
||||
assertFalse("System class loader has unexpected type",
|
||||
PathableClassLoader.class.getName().equals(
|
||||
systemLoader.getClass().getName()));
|
||||
|
||||
// junit classes should be visible; their classloader is not
|
||||
// junit classes should be visible; their class loader is not
|
||||
// in the hierarchy of parent class loaders for this class,
|
||||
// though it is accessible due to trickery in the PathableClassLoader.
|
||||
final Class junitTest = contextLoader.loadClass("junit.framework.Test");
|
||||
final Set ancestorCLs = getAncestorCLs();
|
||||
assertFalse("Junit not loaded by ancestor classloader",
|
||||
assertFalse("Junit not loaded by ancestor class loader",
|
||||
ancestorCLs.contains(junitTest.getClassLoader()));
|
||||
|
||||
// jcl api classes should be visible only via the parent
|
||||
@@ -199,9 +199,9 @@ public class ChildFirstTestCase extends TestCase {
|
||||
// ok
|
||||
}
|
||||
|
||||
// String class classloader is null
|
||||
// String class class loader is null
|
||||
final Class stringClass = contextLoader.loadClass("java.lang.String");
|
||||
assertNull("String class classloader is not null!",
|
||||
assertNull("String class class loader is not null!",
|
||||
stringClass.getClassLoader());
|
||||
}
|
||||
|
||||
@@ -218,11 +218,11 @@ public class ChildFirstTestCase extends TestCase {
|
||||
resource = childLoader.getResource("nosuchfile");
|
||||
assertNull("Non-null URL returned for invalid resource name", resource);
|
||||
|
||||
// getResource where it is accessible only to parent classloader
|
||||
// getResource where it is accessible only to parent class loader
|
||||
resource = childLoader.getResource("org/apache/commons/logging/Log.class");
|
||||
assertNotNull("Unable to locate Log.class resource", resource);
|
||||
|
||||
// getResource where it is accessible only to child classloader
|
||||
// getResource where it is accessible only to child class loader
|
||||
resource = childLoader.getResource("org/apache/commons/logging/PathableTestSuite.class");
|
||||
assertNotNull("Unable to locate PathableTestSuite.class resource", resource);
|
||||
|
||||
@@ -242,12 +242,12 @@ public class ChildFirstTestCase extends TestCase {
|
||||
public void testResourceAsStream() throws Exception {
|
||||
java.io.InputStream is;
|
||||
|
||||
// verify the classloader hierarchy
|
||||
// verify the class loader hierarchy
|
||||
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader childLoader = contextLoader.getParent();
|
||||
final ClassLoader parentLoader = childLoader.getParent();
|
||||
final ClassLoader bootLoader = parentLoader.getParent();
|
||||
assertNull("Unexpected classloader hierarchy", bootLoader);
|
||||
assertNull("Unexpected class loader hierarchy", bootLoader);
|
||||
|
||||
// getResourceAsStream where no instances exist
|
||||
is = childLoader.getResourceAsStream("nosuchfile");
|
||||
@@ -271,12 +271,12 @@ public class ChildFirstTestCase extends TestCase {
|
||||
Enumeration resources;
|
||||
URL[] urls;
|
||||
|
||||
// verify the classloader hierarchy
|
||||
// verify the class loader hierarchy
|
||||
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader childLoader = contextLoader.getParent();
|
||||
final ClassLoader parentLoader = childLoader.getParent();
|
||||
final ClassLoader bootLoader = parentLoader.getParent();
|
||||
assertNull("Unexpected classloader hierarchy", bootLoader);
|
||||
assertNull("Unexpected class loader hierarchy", bootLoader);
|
||||
|
||||
// getResources where no instances exist
|
||||
resources = childLoader.getResources("nosuchfile");
|
||||
|
||||
@@ -32,7 +32,7 @@ import junit.framework.TestCase;
|
||||
public class GeneralTestCase extends TestCase {
|
||||
|
||||
/**
|
||||
* Verify that the context classloader is a custom one, then reset it to
|
||||
* Verify that the context class loader is a custom one, then reset it to
|
||||
* a non-custom one.
|
||||
*/
|
||||
private static void checkAndSetContext() {
|
||||
@@ -57,7 +57,7 @@ public class GeneralTestCase extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a custom classloader hierarchy for this test case.
|
||||
* Sets up a custom class loader hierarchy for this test case.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
final Class thisClass = GeneralTestCase.class;
|
||||
@@ -67,7 +67,7 @@ public class GeneralTestCase extends TestCase {
|
||||
loader.useExplicitLoader("junit.", thisClassLoader);
|
||||
loader.addLogicalLib("testclasses");
|
||||
|
||||
// reload this class via the child classloader
|
||||
// reload this class via the child class loader
|
||||
final Class testClass = loader.loadClass(thisClass.getName());
|
||||
|
||||
// and return our custom TestSuite class
|
||||
@@ -75,7 +75,7 @@ public class GeneralTestCase extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that when a test method modifies the context classloader it is
|
||||
* Verify that when a test method modifies the context class loader it is
|
||||
* reset before the next test is run.
|
||||
* <p>
|
||||
* This method works in conjunction with testResetContext2. There is no
|
||||
|
||||
@@ -46,12 +46,12 @@ import junit.framework.TestCase;
|
||||
public class ParentFirstTestCase extends TestCase {
|
||||
|
||||
/**
|
||||
* Sets up a custom classloader hierarchy for this test case.
|
||||
* Sets up a custom class loader hierarchy for this test case.
|
||||
* The hierarchy is:
|
||||
* <ul>
|
||||
* <li> contextloader: parent-first.
|
||||
* <li> childloader: parent-first, used to load test case.
|
||||
* <li> parentloader: parent-first, parent is the bootclassloader.
|
||||
* <li> parentloader: parent-first, parent is the boot class loader.
|
||||
* </ul>
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
@@ -64,7 +64,7 @@ public class ParentFirstTestCase extends TestCase {
|
||||
|
||||
// Make the junit classes visible as a special case, as junit
|
||||
// won't be able to call this class at all without this. The
|
||||
// junit classes must be visible from the classloader that loaded
|
||||
// junit classes must be visible from the class loader that loaded
|
||||
// this class, so use that as the source for future access to classes
|
||||
// from the junit package.
|
||||
parent.useExplicitLoader("junit.", thisClassLoader);
|
||||
@@ -73,18 +73,18 @@ public class ParentFirstTestCase extends TestCase {
|
||||
// make the commons-logging.jar classes visible via the parent
|
||||
parent.addLogicalLib("commons-logging");
|
||||
|
||||
// create a child classloader to load the test case through
|
||||
// create a child class loader to load the test case through
|
||||
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||
|
||||
// obviously, the child classloader needs to have the test classes
|
||||
// obviously, the child class loader needs to have the test classes
|
||||
// in its path!
|
||||
child.addLogicalLib("testclasses");
|
||||
child.addLogicalLib("commons-logging-adapters");
|
||||
|
||||
// create a third classloader to be the context classloader.
|
||||
// create a third class loader to be the context class loader.
|
||||
final PathableClassLoader context = new PathableClassLoader(child);
|
||||
|
||||
// reload this class via the child classloader
|
||||
// reload this class via the child class loader
|
||||
final Class testClass = child.loadClass(thisClass.getName());
|
||||
|
||||
// and return our custom TestSuite class
|
||||
@@ -120,55 +120,55 @@ public class ParentFirstTestCase extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the classloader hierarchy is as expected, and that
|
||||
* Test that the class loader hierarchy is as expected, and that
|
||||
* calling loadClass() on various class loaders works as expected.
|
||||
* Note that for this test case, parent-first classloading is
|
||||
* in effect.
|
||||
*/
|
||||
public void testPaths() throws Exception {
|
||||
// the context classloader is not expected to be null
|
||||
// the context class loader is not expected to be null
|
||||
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
assertNotNull("Context classloader is null", contextLoader);
|
||||
assertEquals("Context classloader has unexpected type",
|
||||
assertNotNull("Context class loader is null", contextLoader);
|
||||
assertEquals("Context class loader has unexpected type",
|
||||
PathableClassLoader.class.getName(),
|
||||
contextLoader.getClass().getName());
|
||||
|
||||
// the classloader that loaded this class is obviously not null
|
||||
// the class loader that loaded this class is obviously not null
|
||||
final ClassLoader thisLoader = this.getClass().getClassLoader();
|
||||
assertNotNull("thisLoader is null", thisLoader);
|
||||
assertEquals("thisLoader has unexpected type",
|
||||
PathableClassLoader.class.getName(),
|
||||
thisLoader.getClass().getName());
|
||||
|
||||
// the suite method specified that the context classloader's parent
|
||||
// the suite method specified that the context class loader's parent
|
||||
// is the loader that loaded this test case.
|
||||
assertSame("Context classloader is not child of thisLoader",
|
||||
assertSame("Context class loader is not child of thisLoader",
|
||||
thisLoader, contextLoader.getParent());
|
||||
|
||||
// thisLoader's parent should be available
|
||||
final ClassLoader parentLoader = thisLoader.getParent();
|
||||
assertNotNull("Parent classloader is null", parentLoader);
|
||||
assertEquals("Parent classloader has unexpected type",
|
||||
assertNotNull("Parent class loader is null", parentLoader);
|
||||
assertEquals("Parent class loader has unexpected type",
|
||||
PathableClassLoader.class.getName(),
|
||||
parentLoader.getClass().getName());
|
||||
|
||||
// parent should have a parent of null
|
||||
assertNull("Parent classloader has non-null parent", parentLoader.getParent());
|
||||
assertNull("Parent class loader has non-null parent", parentLoader.getParent());
|
||||
|
||||
// getSystemClassloader is not a PathableClassLoader; it's of a
|
||||
// built-in type. This also verifies that system classloader is none of
|
||||
// built-in type. This also verifies that system class loader is none of
|
||||
// (context, child, parent).
|
||||
final ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
|
||||
assertNotNull("System classloader is null", systemLoader);
|
||||
assertNotEquals("System classloader has unexpected type", PathableClassLoader.class.getName(),
|
||||
assertNotNull("System class loader is null", systemLoader);
|
||||
assertNotEquals("System class loader has unexpected type", PathableClassLoader.class.getName(),
|
||||
systemLoader.getClass().getName());
|
||||
|
||||
// junit classes should be visible; their classloader is not
|
||||
// junit classes should be visible; their class loader is not
|
||||
// in the hierarchy of parent class loaders for this class,
|
||||
// though it is accessible due to trickery in the PathableClassLoader.
|
||||
final Class junitTest = contextLoader.loadClass("junit.framework.Test");
|
||||
final Set ancestorCLs = getAncestorCLs();
|
||||
assertFalse("Junit not loaded by ancestor classloader",
|
||||
assertFalse("Junit not loaded by ancestor class loader",
|
||||
ancestorCLs.contains(junitTest.getClassLoader()));
|
||||
|
||||
// jcl api classes should be visible only via the parent
|
||||
@@ -196,9 +196,9 @@ public class ParentFirstTestCase extends TestCase {
|
||||
// ok
|
||||
}
|
||||
|
||||
// String class classloader is null
|
||||
// String class class loader is null
|
||||
final Class stringClass = contextLoader.loadClass("java.lang.String");
|
||||
assertNull("String class classloader is not null!",
|
||||
assertNull("String class class loader is not null!",
|
||||
stringClass.getClassLoader());
|
||||
}
|
||||
|
||||
@@ -215,11 +215,11 @@ public class ParentFirstTestCase extends TestCase {
|
||||
resource = childLoader.getResource("nosuchfile");
|
||||
assertNull("Non-null URL returned for invalid resource name", resource);
|
||||
|
||||
// getResource where it is accessible only to parent classloader
|
||||
// getResource where it is accessible only to parent class loader
|
||||
resource = childLoader.getResource("org/apache/commons/logging/Log.class");
|
||||
assertNotNull("Unable to locate Log.class resource", resource);
|
||||
|
||||
// getResource where it is accessible only to child classloader
|
||||
// getResource where it is accessible only to child class loader
|
||||
resource = childLoader.getResource("org/apache/commons/logging/PathableTestSuite.class");
|
||||
assertNotNull("Unable to locate PathableTestSuite.class resource", resource);
|
||||
|
||||
@@ -239,12 +239,12 @@ public class ParentFirstTestCase extends TestCase {
|
||||
public void testResourceAsStream() throws Exception {
|
||||
java.io.InputStream is;
|
||||
|
||||
// verify the classloader hierarchy
|
||||
// verify the class loader hierarchy
|
||||
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader childLoader = contextLoader.getParent();
|
||||
final ClassLoader parentLoader = childLoader.getParent();
|
||||
final ClassLoader bootLoader = parentLoader.getParent();
|
||||
assertNull("Unexpected classloader hierarchy", bootLoader);
|
||||
assertNull("Unexpected class loader hierarchy", bootLoader);
|
||||
|
||||
// getResourceAsStream where no instances exist
|
||||
is = childLoader.getResourceAsStream("nosuchfile");
|
||||
@@ -268,12 +268,12 @@ public class ParentFirstTestCase extends TestCase {
|
||||
Enumeration resources;
|
||||
URL[] urls;
|
||||
|
||||
// verify the classloader hierarchy
|
||||
// verify the class loader hierarchy
|
||||
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader childLoader = contextLoader.getParent();
|
||||
final ClassLoader parentLoader = childLoader.getParent();
|
||||
final ClassLoader bootLoader = parentLoader.getParent();
|
||||
assertNull("Unexpected classloader hierarchy", bootLoader);
|
||||
assertNull("Unexpected class loader hierarchy", bootLoader);
|
||||
|
||||
// getResources where no instances exist
|
||||
resources = childLoader.getResources("nosuchfile");
|
||||
|
||||
@@ -37,9 +37,9 @@ import junit.framework.TestCase;
|
||||
* <p>
|
||||
* This class has only one unit test, as we are (in part) checking behavior in
|
||||
* the static block of the LogFactory class. As that class cannot be unloaded after
|
||||
* being loaded into a classloader, the only workaround is to use the
|
||||
* being loaded into a class loader, the only workaround is to use the
|
||||
* PathableClassLoader approach to ensure each test is run in its own
|
||||
* classloader, and use a separate test class for each test.
|
||||
* class loader, and use a separate test class for each test.
|
||||
*/
|
||||
public class SecurityAllowedTestCase extends TestCase {
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@ import junit.framework.TestCase;
|
||||
* <p>
|
||||
* This class has only one unit test, as we are (in part) checking behavior in
|
||||
* the static block of the LogFactory class. As that class cannot be unloaded after
|
||||
* being loaded into a classloader, the only workaround is to use the
|
||||
* being loaded into a class loader, the only workaround is to use the
|
||||
* PathableClassLoader approach to ensure each test is run in its own
|
||||
* classloader, and use a separate test class for each test.
|
||||
* class loader, and use a separate test class for each test.
|
||||
*/
|
||||
public class SecurityForbiddenTestCase extends TestCase {
|
||||
|
||||
@@ -77,7 +77,7 @@ public class SecurityForbiddenTestCase extends TestCase {
|
||||
private ClassLoader otherClassLoader;
|
||||
|
||||
/**
|
||||
* Loads a class with the given classloader.
|
||||
* Loads a class with the given class loader.
|
||||
*/
|
||||
private Object loadClass(final String name, final ClassLoader classLoader) {
|
||||
try {
|
||||
@@ -167,8 +167,8 @@ public class SecurityForbiddenTestCase extends TestCase {
|
||||
|
||||
/**
|
||||
* Test what happens when JCL is run with absolutely no security
|
||||
* privileges at all and a class loaded with a different classloader
|
||||
* than the context classloader of the current thread tries to log something.
|
||||
* privileges at all and a class loaded with a different class loader
|
||||
* than the context class loader of the current thread tries to log something.
|
||||
*/
|
||||
public void testContextClassLoader() {
|
||||
// Ignore on Java 21
|
||||
@@ -183,7 +183,7 @@ public class SecurityForbiddenTestCase extends TestCase {
|
||||
System.setSecurityManager(mySecurityManager);
|
||||
|
||||
try {
|
||||
// load a dummy class with another classloader
|
||||
// load a dummy class with another class loader
|
||||
// to force a SecurityException when the LogFactory calls
|
||||
// Thread.getCurrentThread().getContextClassLoader()
|
||||
loadClass("org.apache.commons.logging.security.DummyClass", otherClassLoader);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.apache.commons.logging.serviceloader.internal;
|
||||
|
||||
/**
|
||||
* A common ServiceLoader error is finding a class that implements LogFactory from a different classloader.
|
||||
* A common ServiceLoader error is finding a class that implements LogFactory from a different class loader.
|
||||
* This class should emulate that behavior.
|
||||
*/
|
||||
public class ThrowingLogFactory {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class BasicServletTestCase extends TestCase {
|
||||
//
|
||||
// Having the test loaded via a loader above the tccl emulates the situation
|
||||
// where a web.xml file specifies ServletContextCleaner as a listener, and
|
||||
// that class is deployed via a shared classloader.
|
||||
// that class is deployed via a shared class loader.
|
||||
|
||||
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
|
||||
@@ -31,7 +31,7 @@ import junit.framework.TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* Verify that by default LogFactoryImpl is loaded from the tccl classloader.
|
||||
* Verify that by default LogFactoryImpl is loaded from the tccl class loader.
|
||||
*/
|
||||
|
||||
public class TcclDisabledTestCase extends TestCase {
|
||||
@@ -61,10 +61,10 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||
|
||||
// Now set up the desired classloader hierarchy. Everything goes into
|
||||
// Now set up the desired class loader hierarchy. Everything goes into
|
||||
// the parent classpath, but we exclude the custom Log class.
|
||||
//
|
||||
// We then create a tccl classloader that can see the custom
|
||||
// We then create a tccl class loader that can see the custom
|
||||
// Log class. Therefore if that class can be found, then the
|
||||
// TCCL must have been used to load it.
|
||||
final PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||
@@ -73,7 +73,7 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
parentLoader.addLogicalLib("commons-logging");
|
||||
parentLoader.addLogicalLib("testclasses");
|
||||
// hack to ensure that the test classloader can't see
|
||||
// hack to ensure that the test class loader can't see
|
||||
// the custom MyLog
|
||||
parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
|
||||
|
||||
@@ -113,12 +113,12 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
final ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
// the tccl loader should NOT be the same as the loader that loaded this test class.
|
||||
assertNotSame("tccl not same as test classloader", thisClassLoader, tcclLoader);
|
||||
assertNotSame("tccl not same as test class loader", thisClassLoader, tcclLoader);
|
||||
|
||||
// MyLog should not be loadable via parent loader
|
||||
try {
|
||||
final Class clazz = thisClassLoader.loadClass(MY_LOG_IMPL);
|
||||
fail("Unexpectedly able to load MyLog via test class classloader");
|
||||
fail("Unexpectedly able to load MyLog via test class class loader");
|
||||
assertNotNull(clazz); // silence warnings about unused var
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
// ok, expected
|
||||
@@ -129,7 +129,7 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
final Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
||||
assertNotNull(clazz);
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
fail("Unexpectedly unable to load MyLog via tccl classloader");
|
||||
fail("Unexpectedly unable to load MyLog via tccl class loader");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,10 +61,10 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||
|
||||
// Now set up the desired classloader hierarchy. Everything goes into
|
||||
// Now set up the desired class loader hierarchy. Everything goes into
|
||||
// the parent classpath, but we exclude the custom Log class.
|
||||
//
|
||||
// We then create a tccl classloader that can see the custom
|
||||
// We then create a tccl class loader that can see the custom
|
||||
// Log class. Therefore if that class can be found, then the
|
||||
// TCCL must have been used to load it.
|
||||
final PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||
@@ -73,7 +73,7 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
parentLoader.addLogicalLib("commons-logging");
|
||||
parentLoader.addLogicalLib("testclasses");
|
||||
// hack to ensure that the test classloader can't see
|
||||
// hack to ensure that the test class loader can't see
|
||||
// the custom MyLogFactoryImpl
|
||||
parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
|
||||
|
||||
@@ -113,12 +113,12 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
final ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
// the tccl loader should NOT be the same as the loader that loaded this test class.
|
||||
assertNotSame("tccl not same as test classloader", thisClassLoader, tcclLoader);
|
||||
assertNotSame("tccl not same as test class loader", thisClassLoader, tcclLoader);
|
||||
|
||||
// MyLog should not be loadable via parent loader
|
||||
try {
|
||||
final Class clazz = thisClassLoader.loadClass(MY_LOG_IMPL);
|
||||
fail("Unexpectedly able to load MyLog via test class classloader");
|
||||
fail("Unexpectedly able to load MyLog via test class class loader");
|
||||
assertNotNull(clazz); // silence warnings about unused var
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
// ok, expected
|
||||
@@ -129,7 +129,7 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
final Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
||||
assertNotNull(clazz);
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
fail("Unexpectedly unable to load MyLog via tccl classloader");
|
||||
fail("Unexpectedly unable to load MyLog via tccl class loader");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Verify that a commons-logging.properties file can prevent a custom
|
||||
* LogFactoryImpl being loaded from the tccl classloader.
|
||||
* LogFactoryImpl being loaded from the tccl class loader.
|
||||
*/
|
||||
|
||||
public class TcclDisabledTestCase extends TestCase {
|
||||
@@ -61,11 +61,11 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||
|
||||
// Now set up the desired classloader hierarchy. Everything goes into
|
||||
// Now set up the desired class loader hierarchy. Everything goes into
|
||||
// the parent classpath, but we exclude the custom LogFactoryImpl
|
||||
// class.
|
||||
//
|
||||
// We then create a tccl classloader that can see the custom
|
||||
// We then create a tccl class loader that can see the custom
|
||||
// LogFactory class. Therefore if that class can be found, then the
|
||||
// TCCL must have been used to load it.
|
||||
final PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||
@@ -74,7 +74,7 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
parentLoader.addLogicalLib("commons-logging");
|
||||
parentLoader.addLogicalLib("testclasses");
|
||||
// hack to ensure that the test classloader can't see
|
||||
// hack to ensure that the test class loader can't see
|
||||
// the custom MyLogFactoryImpl
|
||||
parentLoader.useExplicitLoader(
|
||||
MY_LOG_FACTORY_PKG + ".", emptyLoader);
|
||||
@@ -115,12 +115,12 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
final ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
// the tccl loader should NOT be the same as the loader that loaded this test class.
|
||||
assertNotSame("tccl not same as test classloader", thisClassLoader, tcclLoader);
|
||||
assertNotSame("tccl not same as test class loader", thisClassLoader, tcclLoader);
|
||||
|
||||
// MyLogFactoryImpl should not be loadable via parent loader
|
||||
try {
|
||||
final Class clazz = thisClassLoader.loadClass(MY_LOG_FACTORY_IMPL);
|
||||
fail("Unexpectedly able to load MyLogFactoryImpl via test class classloader");
|
||||
fail("Unexpectedly able to load MyLogFactoryImpl via test class class loader");
|
||||
assertNotNull(clazz); // silence warning about unused var
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
// ok, expected
|
||||
@@ -131,7 +131,7 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
final Class clazz = tcclLoader.loadClass(MY_LOG_FACTORY_IMPL);
|
||||
assertNotNull(clazz);
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
fail("Unexpectedly unable to load MyLogFactoryImpl via tccl classloader");
|
||||
fail("Unexpectedly unable to load MyLogFactoryImpl via tccl class loader");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Verify that by default a custom LogFactoryImpl is loaded from the
|
||||
* tccl classloader.
|
||||
* tccl class loader.
|
||||
*/
|
||||
|
||||
public class TcclEnabledTestCase extends TestCase {
|
||||
@@ -55,11 +55,11 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||
|
||||
// Now set up the desired classloader hierarchy. Everything goes into
|
||||
// Now set up the desired class loader hierarchy. Everything goes into
|
||||
// the parent classpath, but we exclude the custom LogFactoryImpl
|
||||
// class.
|
||||
//
|
||||
// We then create a tccl classloader that can see the custom
|
||||
// We then create a tccl class loader that can see the custom
|
||||
// LogFactory class. Therefore if that class can be found, then the
|
||||
// TCCL must have been used to load it.
|
||||
final PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||
@@ -68,7 +68,7 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
parentLoader.addLogicalLib("commons-logging");
|
||||
parentLoader.addLogicalLib("testclasses");
|
||||
// hack to ensure that the test classloader can't see
|
||||
// hack to ensure that the test class loader can't see
|
||||
// the cust MyLogFactoryImpl
|
||||
parentLoader.useExplicitLoader(
|
||||
"org.apache.commons.logging.tccl.custom.", emptyLoader);
|
||||
@@ -109,13 +109,13 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
final ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
// the tccl loader should NOT be the same as the loader that loaded this test class.
|
||||
assertNotSame("tccl not same as test classloader", thisClassLoader, tcclLoader);
|
||||
assertNotSame("tccl not same as test class loader", thisClassLoader, tcclLoader);
|
||||
|
||||
// MyLogFactoryImpl should not be loadable via parent loader
|
||||
try {
|
||||
final Class clazz = thisClassLoader.loadClass(
|
||||
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl");
|
||||
fail("Unexpectedly able to load MyLogFactoryImpl via test class classloader");
|
||||
fail("Unexpectedly able to load MyLogFactoryImpl via test class class loader");
|
||||
assertNotNull(clazz); // silence warning about unused var
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
// ok, expected
|
||||
@@ -127,7 +127,7 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl");
|
||||
assertNotNull(clazz);
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
fail("Unexpectedly unable to load MyLogFactoryImpl via tccl classloader");
|
||||
fail("Unexpectedly unable to load MyLogFactoryImpl via tccl class loader");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user