Remove trailing whitespace.
This commit is contained in:
@@ -25,7 +25,7 @@ public class AltHashtable extends Hashtable {
|
|||||||
* Generated serial version ID.
|
* Generated serial version ID.
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 8927996458633688095L;
|
private static final long serialVersionUID = 8927996458633688095L;
|
||||||
|
|
||||||
public static Object lastKey;
|
public static Object lastKey;
|
||||||
public static Object lastValue;
|
public static Object lastValue;
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class LoadTestCase extends TestCase{
|
|||||||
//TODO: need some way to add service provider packages
|
//TODO: need some way to add service provider packages
|
||||||
static private String LOG_PCKG[] = {"org.apache.commons.logging",
|
static private String LOG_PCKG[] = {"org.apache.commons.logging",
|
||||||
"org.apache.commons.logging.impl"};
|
"org.apache.commons.logging.impl"};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A custom classloader which "duplicates" logging classes available
|
* A custom classloader which "duplicates" logging classes available
|
||||||
* in the parent classloader into itself.
|
* in the parent classloader into itself.
|
||||||
@@ -38,51 +38,51 @@ public class LoadTestCase extends TestCase{
|
|||||||
* as the classloader that loaded it.
|
* as the classloader that loaded it.
|
||||||
*/
|
*/
|
||||||
static class AppClassLoader extends ClassLoader{
|
static class AppClassLoader extends ClassLoader{
|
||||||
|
|
||||||
java.util.Map classes = new java.util.HashMap();
|
java.util.Map classes = new java.util.HashMap();
|
||||||
|
|
||||||
AppClassLoader(ClassLoader parent){
|
AppClassLoader(ClassLoader parent){
|
||||||
super(parent);
|
super(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Class def(String name)throws ClassNotFoundException{
|
private Class def(String name)throws ClassNotFoundException{
|
||||||
|
|
||||||
Class result = (Class)classes.get(name);
|
Class result = (Class)classes.get(name);
|
||||||
if(result != null){
|
if(result != null){
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
ClassLoader cl = this.getClass().getClassLoader();
|
ClassLoader cl = this.getClass().getClassLoader();
|
||||||
String classFileName = name.replace('.','/') + ".class";
|
String classFileName = name.replace('.','/') + ".class";
|
||||||
java.io.InputStream is = cl.getResourceAsStream(classFileName);
|
java.io.InputStream is = cl.getResourceAsStream(classFileName);
|
||||||
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
|
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
|
||||||
|
|
||||||
while(is.available() > 0){
|
while(is.available() > 0){
|
||||||
out.write(is.read());
|
out.write(is.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
byte data [] = out.toByteArray();
|
byte data [] = out.toByteArray();
|
||||||
|
|
||||||
result = super.defineClass(name, data, 0, data.length );
|
result = super.defineClass(name, data, 0, data.length );
|
||||||
classes.put(name,result);
|
classes.put(name,result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}catch(java.io.IOException ioe){
|
}catch(java.io.IOException ioe){
|
||||||
|
|
||||||
throw new ClassNotFoundException( name + " caused by "
|
throw new ClassNotFoundException( name + " caused by "
|
||||||
+ ioe.getMessage() );
|
+ ioe.getMessage() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// not very trivial to emulate we must implement "findClass",
|
// not very trivial to emulate we must implement "findClass",
|
||||||
// but it will delegete to junit class loder first
|
// but it will delegete to junit class loder first
|
||||||
public Class loadClass(String name)throws ClassNotFoundException{
|
public Class loadClass(String name)throws ClassNotFoundException{
|
||||||
|
|
||||||
//isolates all logging classes, application in the same classloader too.
|
//isolates all logging classes, application in the same classloader too.
|
||||||
//filters exeptions to simlify handling in test
|
//filters exeptions to simlify handling in test
|
||||||
for(int i = 0; i < LOG_PCKG.length; i++ ){
|
for(int i = 0; i < LOG_PCKG.length; i++ ){
|
||||||
@@ -93,9 +93,9 @@ public class LoadTestCase extends TestCase{
|
|||||||
}
|
}
|
||||||
return super.loadClass(name);
|
return super.loadClass(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call the static setAllowFlawedContext method on the specified class
|
* Call the static setAllowFlawedContext method on the specified class
|
||||||
@@ -116,26 +116,26 @@ public class LoadTestCase extends TestCase{
|
|||||||
* are available via the system classpath.
|
* are available via the system classpath.
|
||||||
*/
|
*/
|
||||||
public void testInContainer()throws Exception{
|
public void testInContainer()throws Exception{
|
||||||
|
|
||||||
//problem can be in this step (broken app container or missconfiguration)
|
//problem can be in this step (broken app container or missconfiguration)
|
||||||
//1. Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
|
//1. Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
|
||||||
//2. Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
|
//2. Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
|
||||||
// we expect this :
|
// we expect this :
|
||||||
// 1. Thread.currentThread().setContextClassLoader(appLoader);
|
// 1. Thread.currentThread().setContextClassLoader(appLoader);
|
||||||
// 2. Thread.currentThread().setContextClassLoader(null);
|
// 2. Thread.currentThread().setContextClassLoader(null);
|
||||||
|
|
||||||
// Context classloader is same as class calling into log
|
// Context classloader is same as class calling into log
|
||||||
Class cls = reload();
|
Class cls = reload();
|
||||||
Thread.currentThread().setContextClassLoader(cls.getClassLoader());
|
Thread.currentThread().setContextClassLoader(cls.getClassLoader());
|
||||||
execute(cls);
|
execute(cls);
|
||||||
|
|
||||||
// Context classloader is the "bootclassloader". This is technically
|
// Context classloader is the "bootclassloader". This is technically
|
||||||
// bad, but LogFactoryImpl.ALLOW_FLAWED_CONTEXT defaults to true so
|
// bad, but LogFactoryImpl.ALLOW_FLAWED_CONTEXT defaults to true so
|
||||||
// this test should pass.
|
// this test should pass.
|
||||||
cls = reload();
|
cls = reload();
|
||||||
Thread.currentThread().setContextClassLoader(null);
|
Thread.currentThread().setContextClassLoader(null);
|
||||||
execute(cls);
|
execute(cls);
|
||||||
|
|
||||||
// Context classloader is the "bootclassloader". This is same as above
|
// Context classloader is the "bootclassloader". This is same as above
|
||||||
// except that ALLOW_FLAWED_CONTEXT is set to false; an error should
|
// except that ALLOW_FLAWED_CONTEXT is set to false; an error should
|
||||||
// now be reported.
|
// now be reported.
|
||||||
@@ -148,7 +148,7 @@ public class LoadTestCase extends TestCase{
|
|||||||
} catch(LogConfigurationException ex) {
|
} catch(LogConfigurationException ex) {
|
||||||
// expected; the boot classloader doesn't *have* JCL available
|
// expected; the boot classloader doesn't *have* JCL available
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context classloader is the system classloader.
|
// Context classloader is the system classloader.
|
||||||
//
|
//
|
||||||
// This is expected to cause problems, as LogFactoryImpl will attempt
|
// This is expected to cause problems, as LogFactoryImpl will attempt
|
||||||
@@ -159,9 +159,9 @@ public class LoadTestCase extends TestCase{
|
|||||||
cls = reload();
|
cls = reload();
|
||||||
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
|
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
|
||||||
execute(cls);
|
execute(cls);
|
||||||
|
|
||||||
// Context classloader is the system classloader. This is the same
|
// Context classloader is the system classloader. This is the same
|
||||||
// as above except that ALLOW_FLAWED_CONTEXT is set to false; an error
|
// as above except that ALLOW_FLAWED_CONTEXT is set to false; an error
|
||||||
// should now be reported.
|
// should now be reported.
|
||||||
cls = reload();
|
cls = reload();
|
||||||
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
|
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
|
||||||
@@ -171,7 +171,7 @@ public class LoadTestCase extends TestCase{
|
|||||||
fail("Error: somehow downcast a Logger loaded via system classloader"
|
fail("Error: somehow downcast a Logger loaded via system classloader"
|
||||||
+ " to the Log interface loaded via a custom classloader");
|
+ " to the Log interface loaded via a custom classloader");
|
||||||
} catch(LogConfigurationException ex) {
|
} catch(LogConfigurationException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,46 +180,46 @@ public class LoadTestCase extends TestCase{
|
|||||||
* the classloader used to load this test class.
|
* the classloader used to load this test class.
|
||||||
*/
|
*/
|
||||||
private Class reload()throws Exception{
|
private Class reload()throws Exception{
|
||||||
|
|
||||||
Class testObjCls = null;
|
Class testObjCls = null;
|
||||||
|
|
||||||
AppClassLoader appLoader = new AppClassLoader(
|
AppClassLoader appLoader = new AppClassLoader(
|
||||||
this.getClass().getClassLoader());
|
this.getClass().getClassLoader());
|
||||||
try{
|
try{
|
||||||
|
|
||||||
testObjCls = appLoader.loadClass(UserClass.class.getName());
|
testObjCls = appLoader.loadClass(UserClass.class.getName());
|
||||||
|
|
||||||
}catch(ClassNotFoundException cnfe){
|
}catch(ClassNotFoundException cnfe){
|
||||||
throw cnfe;
|
throw cnfe;
|
||||||
}catch(Throwable t){
|
}catch(Throwable t){
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
fail("AppClassLoader failed ");
|
fail("AppClassLoader failed ");
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue( "app isolated" ,testObjCls.getClassLoader() == appLoader );
|
assertTrue( "app isolated" ,testObjCls.getClassLoader() == appLoader );
|
||||||
|
|
||||||
|
|
||||||
return testObjCls;
|
return testObjCls;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void execute(Class cls)throws Exception{
|
private void execute(Class cls)throws Exception{
|
||||||
|
|
||||||
cls.newInstance();
|
cls.newInstance();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
// save state before test starts so we can restore it when test ends
|
// save state before test starts so we can restore it when test ends
|
||||||
origContextClassLoader = Thread.currentThread().getContextClassLoader();
|
origContextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
// restore original state so a test can't stuff up later tests.
|
// restore original state so a test can't stuff up later tests.
|
||||||
Thread.currentThread().setContextClassLoader(origContextClassLoader);
|
Thread.currentThread().setContextClassLoader(origContextClassLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClassLoader origContextClassLoader;
|
private ClassLoader origContextClassLoader;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ import junit.framework.TestCase;
|
|||||||
*/
|
*/
|
||||||
public class NullClassLoaderTestCase extends TestCase {
|
public class NullClassLoaderTestCase extends TestCase {
|
||||||
|
|
||||||
//---------------------- unit tests ---------------------------------
|
//---------------------- unit tests ---------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This tests that when getContextClassLoader returns null, the
|
* This tests that when getContextClassLoader returns null, the
|
||||||
* LogFactory.getLog(name) method still correctly returns the same
|
* LogFactory.getLog(name) method still correctly returns the same
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class PathableClassLoader extends URLClassLoader {
|
public class PathableClassLoader extends URLClassLoader {
|
||||||
|
|
||||||
private static final URL[] NO_URLS = new URL[0];
|
private static final URL[] NO_URLS = new URL[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A map of package-prefix to ClassLoader. Any class which is in
|
* A map of package-prefix to ClassLoader. Any class which is in
|
||||||
* this map is looked up via the specified classloader instead of
|
* this map is looked up via the specified classloader instead of
|
||||||
@@ -60,7 +60,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* with classes loaded via a custom classloader. As an example, junit
|
* with classes loaded via a custom classloader. As an example, junit
|
||||||
* testcases which are loaded via a custom classloader needs to see
|
* testcases which are loaded via a custom classloader needs to see
|
||||||
* the same junit classes as the code invoking the testcase, otherwise
|
* the same junit classes as the code invoking the testcase, otherwise
|
||||||
* they can't pass result objects back.
|
* they can't pass result objects back.
|
||||||
* <p>
|
* <p>
|
||||||
* Normally, only a classloader created with a null parent needs to
|
* Normally, only a classloader created with a null parent needs to
|
||||||
* have any lookasides defined.
|
* have any lookasides defined.
|
||||||
@@ -96,7 +96,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
public PathableClassLoader(ClassLoader parent) {
|
public PathableClassLoader(ClassLoader parent) {
|
||||||
super(NO_URLS, parent);
|
super(NO_URLS, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow caller to explicitly add paths. Generally this not a good idea;
|
* Allow caller to explicitly add paths. Generally this not a good idea;
|
||||||
* use addLogicalLib instead, then define the location for that logical
|
* use addLogicalLib instead, then define the location for that logical
|
||||||
@@ -110,9 +110,9 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* Specify whether this classloader should ask the parent classloader
|
* Specify whether this classloader should ask the parent classloader
|
||||||
* to resolve a class first, before trying to resolve it via its own
|
* to resolve a class first, before trying to resolve it via its own
|
||||||
* classpath.
|
* classpath.
|
||||||
* <p>
|
* <p>
|
||||||
* Checking with the parent first is the normal approach for java, but
|
* Checking with the parent first is the normal approach for java, but
|
||||||
* components within containers such as servlet engines can use
|
* components within containers such as servlet engines can use
|
||||||
* child-first lookup instead, to allow the components to override libs
|
* child-first lookup instead, to allow the components to override libs
|
||||||
* which are visible in shared classloaders provided by the container.
|
* which are visible in shared classloaders provided by the container.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -140,7 +140,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
*/
|
*/
|
||||||
public void useSystemLoader(String prefix) {
|
public void useSystemLoader(String prefix) {
|
||||||
useExplicitLoader(prefix, ClassLoader.getSystemClassLoader());
|
useExplicitLoader(prefix, ClassLoader.getSystemClassLoader());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -148,7 +148,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* <p>
|
* <p>
|
||||||
* The specified classloader is normally a loader that is NOT
|
* The specified classloader is normally a loader that is NOT
|
||||||
* an ancestor of this classloader. In particular, this loader
|
* an ancestor of this classloader. In particular, this loader
|
||||||
* may have the bootloader as its parent, but be configured to
|
* may have the bootloader as its parent, but be configured to
|
||||||
* see specific other classes (eg the junit library loaded
|
* see specific other classes (eg the junit library loaded
|
||||||
* via the system classloader).
|
* via the system classloader).
|
||||||
* <p>
|
* <p>
|
||||||
@@ -186,7 +186,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify a logical library to be included in the classpath used to
|
* Specify a logical library to be included in the classpath used to
|
||||||
* locate classes.
|
* locate classes.
|
||||||
* <p>
|
* <p>
|
||||||
* The specified lib name is used as a key into the system properties;
|
* The specified lib name is used as a key into the system properties;
|
||||||
* there is expected to be a system property defined with that name
|
* there is expected to be a system property defined with that name
|
||||||
@@ -198,11 +198,11 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* this class is a URLClassLoader then the set of URLs that the
|
* this class is a URLClassLoader then the set of URLs that the
|
||||||
* classloader uses for its classpath is scanned; any jar in the
|
* classloader uses for its classpath is scanned; any jar in the
|
||||||
* URL set whose name starts with the specified string is added to
|
* URL set whose name starts with the specified string is added to
|
||||||
* the classpath managed by this instance.
|
* the classpath managed by this instance.
|
||||||
* <p>
|
* <p>
|
||||||
* Using logical library names allows the calling code to specify its
|
* Using logical library names allows the calling code to specify its
|
||||||
* desired classpath without knowing the exact location of the necessary
|
* desired classpath without knowing the exact location of the necessary
|
||||||
* classes.
|
* classes.
|
||||||
*/
|
*/
|
||||||
public void addLogicalLib(String logicalLib) {
|
public void addLogicalLib(String logicalLib) {
|
||||||
// first, check the system properties
|
// first, check the system properties
|
||||||
@@ -255,14 +255,14 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
if (cl instanceof URLClassLoader == false) {
|
if (cl instanceof URLClassLoader == false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
URLClassLoader ucl = (URLClassLoader) cl;
|
URLClassLoader ucl = (URLClassLoader) cl;
|
||||||
URL[] path = ucl.getURLs();
|
URL[] path = ucl.getURLs();
|
||||||
URL shortestMatch = null;
|
URL shortestMatch = null;
|
||||||
int shortestMatchLen = Integer.MAX_VALUE;
|
int shortestMatchLen = Integer.MAX_VALUE;
|
||||||
for(int i=0; i<path.length; ++i) {
|
for(int i=0; i<path.length; ++i) {
|
||||||
URL u = path[i];
|
URL u = path[i];
|
||||||
|
|
||||||
// extract the filename bit on the end of the url
|
// extract the filename bit on the end of the url
|
||||||
String filename = u.toString();
|
String filename = u.toString();
|
||||||
if (!filename.endsWith(".jar")) {
|
if (!filename.endsWith(".jar")) {
|
||||||
@@ -274,7 +274,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
if (lastSlash >= 0) {
|
if (lastSlash >= 0) {
|
||||||
filename = filename.substring(lastSlash+1);
|
filename = filename.substring(lastSlash+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename.startsWith(logicalLib)) {
|
if (filename.startsWith(logicalLib)) {
|
||||||
// ok, this is a candidate
|
// ok, this is a candidate
|
||||||
if (filename.length() < shortestMatchLen) {
|
if (filename.length() < shortestMatchLen) {
|
||||||
@@ -283,18 +283,18 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return shortestMatch;
|
return shortestMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override ClassLoader method.
|
* Override ClassLoader method.
|
||||||
* <p>
|
* <p>
|
||||||
* For each explicitly mapped package prefix, if the name matches the
|
* For each explicitly mapped package prefix, if the name matches the
|
||||||
* prefix associated with that entry then attempt to load the class via
|
* prefix associated with that entry then attempt to load the class via
|
||||||
* that entries' classloader.
|
* that entries' classloader.
|
||||||
*/
|
*/
|
||||||
protected Class loadClass(String name, boolean resolve)
|
protected Class loadClass(String name, boolean resolve)
|
||||||
throws ClassNotFoundException {
|
throws ClassNotFoundException {
|
||||||
// just for performance, check java and javax
|
// just for performance, check java and javax
|
||||||
if (name.startsWith("java.") || name.startsWith("javax.")) {
|
if (name.startsWith("java.") || name.startsWith("javax.")) {
|
||||||
@@ -312,17 +312,17 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentFirst) {
|
if (parentFirst) {
|
||||||
return super.loadClass(name, resolve);
|
return super.loadClass(name, resolve);
|
||||||
} else {
|
} else {
|
||||||
// Implement child-first.
|
// Implement child-first.
|
||||||
//
|
//
|
||||||
// It appears that the findClass method doesn't check whether the
|
// It appears that the findClass method doesn't check whether the
|
||||||
// class has already been loaded. This seems odd to me, but without
|
// class has already been loaded. This seems odd to me, but without
|
||||||
// first checking via findLoadedClass we can get java.lang.LinkageError
|
// first checking via findLoadedClass we can get java.lang.LinkageError
|
||||||
// with message "duplicate class definition" which isn't good.
|
// with message "duplicate class definition" which isn't good.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class clazz = findLoadedClass(name);
|
Class clazz = findLoadedClass(name);
|
||||||
if (clazz == null) {
|
if (clazz == null) {
|
||||||
@@ -337,7 +337,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as parent class method except that when parentFirst is false
|
* Same as parent class method except that when parentFirst is false
|
||||||
* the resource is looked for in the local classpath before the parent
|
* the resource is looked for in the local classpath before the parent
|
||||||
@@ -354,7 +354,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
return super.getResource(name);
|
return super.getResource(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emulate a proper implementation of getResources which respects the
|
* Emulate a proper implementation of getResources which respects the
|
||||||
* setting for parentFirst.
|
* setting for parentFirst.
|
||||||
@@ -368,7 +368,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
return super.getResources(name);
|
return super.getResources(name);
|
||||||
} else {
|
} else {
|
||||||
Enumeration localUrls = super.findResources(name);
|
Enumeration localUrls = super.findResources(name);
|
||||||
|
|
||||||
ClassLoader parent = getParent();
|
ClassLoader parent = getParent();
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
// Alas, there is no method to get matching resources
|
// Alas, there is no method to get matching resources
|
||||||
@@ -391,11 +391,11 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
return Collections.enumeration(localItems);
|
return Collections.enumeration(localItems);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Clean implementation of list function of
|
* Clean implementation of list function of
|
||||||
* {@link java.utils.Collection} added in JDK 1.4
|
* {@link java.utils.Collection} added in JDK 1.4
|
||||||
* @param en <code>Enumeration</code>, possibly null
|
* @param en <code>Enumeration</code>, possibly null
|
||||||
* @return <code>ArrayList</code> containing the enumerated
|
* @return <code>ArrayList</code> containing the enumerated
|
||||||
* elements in the enumerated order, not null
|
* elements in the enumerated order, not null
|
||||||
@@ -410,7 +410,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as parent class method except that when parentFirst is false
|
* Same as parent class method except that when parentFirst is false
|
||||||
* the resource is looked for in the local classpath before the parent
|
* the resource is looked for in the local classpath before the parent
|
||||||
|
|||||||
@@ -33,24 +33,24 @@ import junit.framework.TestSuite;
|
|||||||
* public static Test suite() throws Exception {
|
* public static Test suite() throws Exception {
|
||||||
* PathableClassLoader parent = new PathableClassLoader(null);
|
* PathableClassLoader parent = new PathableClassLoader(null);
|
||||||
* parent.useSystemLoader("junit.");
|
* parent.useSystemLoader("junit.");
|
||||||
*
|
*
|
||||||
* PathableClassLoader child = new PathableClassLoader(parent);
|
* PathableClassLoader child = new PathableClassLoader(parent);
|
||||||
* child.addLogicalLib("testclasses");
|
* child.addLogicalLib("testclasses");
|
||||||
* child.addLogicalLib("log4j12");
|
* child.addLogicalLib("log4j12");
|
||||||
* child.addLogicalLib("commons-logging");
|
* child.addLogicalLib("commons-logging");
|
||||||
*
|
*
|
||||||
* Class testClass = child.loadClass(SomeTestCase.class.getName());
|
* Class testClass = child.loadClass(SomeTestCase.class.getName());
|
||||||
* ClassLoader contextClassLoader = child;
|
* ClassLoader contextClassLoader = child;
|
||||||
*
|
*
|
||||||
* PathableTestSuite suite = new PathableTestSuite(testClass, child);
|
* PathableTestSuite suite = new PathableTestSuite(testClass, child);
|
||||||
* return suite;
|
* return suite;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* // test methods go here
|
* // test methods go here
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
* Note that if the suite method throws an exception then this will be handled
|
* Note that if the suite method throws an exception then this will be handled
|
||||||
* reasonable gracefully by junit; it will report that the suite method for
|
* reasonable gracefully by junit; it will report that the suite method for
|
||||||
* a test case failed with exception yyy.
|
* a test case failed with exception yyy.
|
||||||
* <p>
|
* <p>
|
||||||
* The use of PathableClassLoader is not required to use this class, but it
|
* The use of PathableClassLoader is not required to use this class, but it
|
||||||
@@ -59,7 +59,7 @@ import junit.framework.TestSuite;
|
|||||||
* This class will run each test methods within the specified TestCase using
|
* This class will run each test methods within the specified TestCase using
|
||||||
* the specified context classloader and system classloader. If different
|
* the specified context classloader and system classloader. If different
|
||||||
* tests within the same class require different context classloaders,
|
* tests within the same class require different context classloaders,
|
||||||
* then the context classloader passed to the constructor should be the
|
* then the context classloader passed to the constructor should be the
|
||||||
* "lowest" one available, and tests that need the context set to some parent
|
* "lowest" one available, and tests that need the context set to some parent
|
||||||
* of this "lowest" classloader can call
|
* of this "lowest" classloader can call
|
||||||
* <pre>
|
* <pre>
|
||||||
@@ -70,14 +70,14 @@ import junit.framework.TestSuite;
|
|||||||
* is undone after the test is run, so tests don't need to worry about
|
* 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 classloader on exit. This class also ensures that
|
||||||
* the system properties are restored to their original settings after each
|
* 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.
|
* test, so tests that manipulate those don't need to worry about resetting them.
|
||||||
* <p>
|
* <p>
|
||||||
* This class does not provide facilities for manipulating system properties;
|
* This class does not provide facilities for manipulating system properties;
|
||||||
* tests that need specific system properties can simply set them in the
|
* tests that need specific system properties can simply set them in the
|
||||||
* fixture or at the start of a test method.
|
* fixture or at the start of a test method.
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Important!</b> When the test case is run, "this.getClass()" refers of
|
* <b>Important!</b> When the test case is run, "this.getClass()" refers of
|
||||||
* course to the Class object passed to the constructor of this class - which
|
* course to the Class object passed to the constructor of this class - which
|
||||||
* is different from the class whose suite() method was executed to determine
|
* is different from the class whose suite() method was executed to determine
|
||||||
* the classpath. This means that the suite method cannot communicate with
|
* the classpath. This means that the suite method cannot communicate with
|
||||||
* the test cases simply by setting static variables (for example to make the
|
* the test cases simply by setting static variables (for example to make the
|
||||||
@@ -87,7 +87,7 @@ import junit.framework.TestSuite;
|
|||||||
* <p>
|
* <p>
|
||||||
* <h2>Limitations</h2>
|
* <h2>Limitations</h2>
|
||||||
* <p>
|
* <p>
|
||||||
* This class cannot control the system classloader (ie what method
|
* This class cannot control the system classloader (ie what method
|
||||||
* ClassLoader.getSystemClassLoader returns) because Java provides no
|
* ClassLoader.getSystemClassLoader returns) because Java provides no
|
||||||
* mechanism for setting the system classloader. In this case, the only
|
* mechanism for setting the system classloader. In this case, the only
|
||||||
* option is to invoke the unit test in a separate JVM with the appropriate
|
* option is to invoke the unit test in a separate JVM with the appropriate
|
||||||
@@ -112,10 +112,10 @@ public class PathableTestSuite extends TestSuite {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param testClass is the TestCase that is to be run, as loaded by
|
* @param testClass is the TestCase that is to be run, as loaded by
|
||||||
* the appropriate ClassLoader.
|
* the appropriate ClassLoader.
|
||||||
*
|
*
|
||||||
* @param contextClassLoader is the loader that should be returned by
|
* @param contextClassLoader is the loader that should be returned by
|
||||||
* calls to Thread.currentThread.getContextClassLoader from test methods
|
* calls to Thread.currentThread.getContextClassLoader from test methods
|
||||||
* (or any method called by test methods).
|
* (or any method called by test methods).
|
||||||
|
|||||||
@@ -65,28 +65,28 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
// this class, so use that as the source for future access to classes
|
// this class, so use that as the source for future access to classes
|
||||||
// from the junit package.
|
// from the junit package.
|
||||||
parent.useExplicitLoader("junit.", thisClassLoader);
|
parent.useExplicitLoader("junit.", thisClassLoader);
|
||||||
|
|
||||||
// make the commons-logging.jar classes visible via the parent
|
// make the commons-logging.jar classes visible via the parent
|
||||||
parent.addLogicalLib("commons-logging");
|
parent.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
// create a child classloader to load the test case through
|
// create a child classloader to load the test case through
|
||||||
PathableClassLoader child = new PathableClassLoader(parent);
|
PathableClassLoader child = new PathableClassLoader(parent);
|
||||||
|
|
||||||
// obviously, the child classloader needs to have the test classes
|
// obviously, the child classloader needs to have the test classes
|
||||||
// in its path!
|
// in its path!
|
||||||
child.addLogicalLib("testclasses");
|
child.addLogicalLib("testclasses");
|
||||||
child.addLogicalLib("commons-logging-adapters");
|
child.addLogicalLib("commons-logging-adapters");
|
||||||
|
|
||||||
// create a third classloader to be the context classloader.
|
// create a third classloader to be the context classloader.
|
||||||
PathableClassLoader context = new PathableClassLoader(child);
|
PathableClassLoader context = new PathableClassLoader(child);
|
||||||
|
|
||||||
// reload this class via the child classloader
|
// reload this class via the child classloader
|
||||||
Class testClass = child.loadClass(thisClass.getName());
|
Class testClass = child.loadClass(thisClass.getName());
|
||||||
|
|
||||||
// and return our custom TestSuite class
|
// and return our custom TestSuite class
|
||||||
return new PathableTestSuite(testClass, context);
|
return new PathableTestSuite(testClass, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method to return the set of all classloaders in the
|
* Utility method to return the set of all classloaders in the
|
||||||
* parent chain starting from the one that loaded the class for
|
* parent chain starting from the one that loaded the class for
|
||||||
@@ -115,14 +115,14 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
assertEquals("Context classloader has unexpected type",
|
assertEquals("Context classloader has unexpected type",
|
||||||
PathableClassLoader.class.getName(),
|
PathableClassLoader.class.getName(),
|
||||||
contextLoader.getClass().getName());
|
contextLoader.getClass().getName());
|
||||||
|
|
||||||
// the classloader that loaded this class is obviously not null
|
// the classloader that loaded this class is obviously not null
|
||||||
ClassLoader thisLoader = this.getClass().getClassLoader();
|
ClassLoader thisLoader = this.getClass().getClassLoader();
|
||||||
assertNotNull("thisLoader is null", thisLoader);
|
assertNotNull("thisLoader is null", thisLoader);
|
||||||
assertEquals("thisLoader has unexpected type",
|
assertEquals("thisLoader has unexpected type",
|
||||||
PathableClassLoader.class.getName(),
|
PathableClassLoader.class.getName(),
|
||||||
thisLoader.getClass().getName());
|
thisLoader.getClass().getName());
|
||||||
|
|
||||||
// the suite method specified that the context classloader's parent
|
// the suite method specified that the context classloader's parent
|
||||||
// is the loader that loaded this test case.
|
// is the loader that loaded this test case.
|
||||||
assertSame("Context classloader is not child of thisLoader",
|
assertSame("Context classloader is not child of thisLoader",
|
||||||
@@ -134,7 +134,7 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
assertEquals("Parent classloader has unexpected type",
|
assertEquals("Parent classloader has unexpected type",
|
||||||
PathableClassLoader.class.getName(),
|
PathableClassLoader.class.getName(),
|
||||||
parentLoader.getClass().getName());
|
parentLoader.getClass().getName());
|
||||||
|
|
||||||
// parent should have a parent of null
|
// parent should have a parent of null
|
||||||
assertNull("Parent classloader has non-null parent", parentLoader.getParent());
|
assertNull("Parent classloader has non-null parent", parentLoader.getParent());
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
// though it is accessable due to trickery in the PathableClassLoader.
|
// though it is accessable due to trickery in the PathableClassLoader.
|
||||||
Class junitTest = contextLoader.loadClass("junit.framework.Test");
|
Class junitTest = contextLoader.loadClass("junit.framework.Test");
|
||||||
Set ancestorCLs = getAncestorCLs();
|
Set ancestorCLs = getAncestorCLs();
|
||||||
assertFalse("Junit not loaded by ancestor classloader",
|
assertFalse("Junit not loaded by ancestor classloader",
|
||||||
ancestorCLs.contains(junitTest.getClassLoader()));
|
ancestorCLs.contains(junitTest.getClassLoader()));
|
||||||
|
|
||||||
// jcl api classes should be visible only via the parent
|
// jcl api classes should be visible only via the parent
|
||||||
@@ -163,14 +163,14 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
// jcl adapter classes should be visible via both parent and child. However
|
// jcl adapter classes should be visible via both parent and child. However
|
||||||
// as the classloaders are parent-first we should see the parent one.
|
// as the classloaders are parent-first we should see the parent one.
|
||||||
Class log4jClass = contextLoader.loadClass("org.apache.commons.logging.impl.Log4JLogger");
|
Class log4jClass = contextLoader.loadClass("org.apache.commons.logging.impl.Log4JLogger");
|
||||||
assertSame("Log4JLogger not loaded via parent",
|
assertSame("Log4JLogger not loaded via parent",
|
||||||
log4jClass.getClassLoader(), parentLoader);
|
log4jClass.getClassLoader(), parentLoader);
|
||||||
|
|
||||||
// test classes should be visible via the child only
|
// test classes should be visible via the child only
|
||||||
Class testClass = contextLoader.loadClass("org.apache.commons.logging.PathableTestSuite");
|
Class testClass = contextLoader.loadClass("org.apache.commons.logging.PathableTestSuite");
|
||||||
assertSame("PathableTestSuite not loaded via child",
|
assertSame("PathableTestSuite not loaded via child",
|
||||||
testClass.getClassLoader(), thisLoader);
|
testClass.getClassLoader(), thisLoader);
|
||||||
|
|
||||||
// test loading of class that is not available
|
// test loading of class that is not available
|
||||||
try {
|
try {
|
||||||
Class noSuchClass = contextLoader.loadClass("no.such.class");
|
Class noSuchClass = contextLoader.loadClass("no.such.class");
|
||||||
@@ -185,16 +185,16 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
assertNull("String class classloader is not null!",
|
assertNull("String class classloader is not null!",
|
||||||
stringClass.getClassLoader());
|
stringClass.getClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the various flavours of ClassLoader.getResource work as expected.
|
* Test that the various flavours of ClassLoader.getResource work as expected.
|
||||||
*/
|
*/
|
||||||
public void testResource() {
|
public void testResource() {
|
||||||
URL resource;
|
URL resource;
|
||||||
|
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
ClassLoader childLoader = contextLoader.getParent();
|
ClassLoader childLoader = contextLoader.getParent();
|
||||||
|
|
||||||
// getResource where it doesn't exist
|
// getResource where it doesn't exist
|
||||||
resource = childLoader.getResource("nosuchfile");
|
resource = childLoader.getResource("nosuchfile");
|
||||||
assertNull("Non-null URL returned for invalid resource name", resource);
|
assertNull("Non-null URL returned for invalid resource name", resource);
|
||||||
@@ -202,7 +202,7 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
// getResource where it is accessable only to parent classloader
|
// getResource where it is accessable only to parent classloader
|
||||||
resource = childLoader.getResource("org/apache/commons/logging/Log.class");
|
resource = childLoader.getResource("org/apache/commons/logging/Log.class");
|
||||||
assertNotNull("Unable to locate Log.class resource", resource);
|
assertNotNull("Unable to locate Log.class resource", resource);
|
||||||
|
|
||||||
// getResource where it is accessable only to child classloader
|
// getResource where it is accessable only to child classloader
|
||||||
resource = childLoader.getResource("org/apache/commons/logging/PathableTestSuite.class");
|
resource = childLoader.getResource("org/apache/commons/logging/PathableTestSuite.class");
|
||||||
assertNotNull("Unable to locate PathableTestSuite.class resource", resource);
|
assertNotNull("Unable to locate PathableTestSuite.class resource", resource);
|
||||||
@@ -216,42 +216,42 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
assertTrue("Incorrect source for Log4JLogger class",
|
assertTrue("Incorrect source for Log4JLogger class",
|
||||||
resource.toString().indexOf("/commons-logging-1.") > 0);
|
resource.toString().indexOf("/commons-logging-1.") > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the various flavours of ClassLoader.getResources work as expected.
|
* Test that the various flavours of ClassLoader.getResources work as expected.
|
||||||
*/
|
*/
|
||||||
public void testResources() throws Exception {
|
public void testResources() throws Exception {
|
||||||
Enumeration resources;
|
Enumeration resources;
|
||||||
URL[] urls;
|
URL[] urls;
|
||||||
|
|
||||||
// verify the classloader hierarchy
|
// verify the classloader hierarchy
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
ClassLoader childLoader = contextLoader.getParent();
|
ClassLoader childLoader = contextLoader.getParent();
|
||||||
ClassLoader parentLoader = childLoader.getParent();
|
ClassLoader parentLoader = childLoader.getParent();
|
||||||
ClassLoader bootLoader = parentLoader.getParent();
|
ClassLoader bootLoader = parentLoader.getParent();
|
||||||
assertNull("Unexpected classloader hierarchy", bootLoader);
|
assertNull("Unexpected classloader hierarchy", bootLoader);
|
||||||
|
|
||||||
// getResources where no instances exist
|
// getResources where no instances exist
|
||||||
resources = childLoader.getResources("nosuchfile");
|
resources = childLoader.getResources("nosuchfile");
|
||||||
urls = toURLArray(resources);
|
urls = toURLArray(resources);
|
||||||
assertEquals("Non-null URL returned for invalid resource name", 0, urls.length);
|
assertEquals("Non-null URL returned for invalid resource name", 0, urls.length);
|
||||||
|
|
||||||
// getResources where the resource only exists in the parent
|
// getResources where the resource only exists in the parent
|
||||||
resources = childLoader.getResources("org/apache/commons/logging/Log.class");
|
resources = childLoader.getResources("org/apache/commons/logging/Log.class");
|
||||||
urls = toURLArray(resources);
|
urls = toURLArray(resources);
|
||||||
assertEquals("Unexpected number of Log.class resources found", 1, urls.length);
|
assertEquals("Unexpected number of Log.class resources found", 1, urls.length);
|
||||||
|
|
||||||
// getResources where the resource only exists in the child
|
// getResources where the resource only exists in the child
|
||||||
resources = childLoader.getResources("org/apache/commons/logging/PathableTestSuite.class");
|
resources = childLoader.getResources("org/apache/commons/logging/PathableTestSuite.class");
|
||||||
urls = toURLArray(resources);
|
urls = toURLArray(resources);
|
||||||
assertEquals("Unexpected number of PathableTestSuite.class resources found", 1, urls.length);
|
assertEquals("Unexpected number of PathableTestSuite.class resources found", 1, urls.length);
|
||||||
|
|
||||||
// getResources where the resource exists in both.
|
// getResources where the resource exists in both.
|
||||||
// resources should be returned in order (parent-resource, child-resource)
|
// resources should be returned in order (parent-resource, child-resource)
|
||||||
resources = childLoader.getResources("org/apache/commons/logging/impl/Log4JLogger.class");
|
resources = childLoader.getResources("org/apache/commons/logging/impl/Log4JLogger.class");
|
||||||
urls = toURLArray(resources);
|
urls = toURLArray(resources);
|
||||||
assertEquals("Unexpected number of Log4JLogger.class resources found", 2, urls.length);
|
assertEquals("Unexpected number of Log4JLogger.class resources found", 2, urls.length);
|
||||||
|
|
||||||
// There is no gaurantee about the ordering of results returned from getResources
|
// There is no gaurantee about the ordering of results returned from getResources
|
||||||
// To make this test portable across JVMs, sort the string to give them a known order
|
// To make this test portable across JVMs, sort the string to give them a known order
|
||||||
String[] urlsToStrings = new String[2];
|
String[] urlsToStrings = new String[2];
|
||||||
@@ -262,7 +262,7 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
urlsToStrings[0].indexOf("/commons-logging-1.") > 0);
|
urlsToStrings[0].indexOf("/commons-logging-1.") > 0);
|
||||||
assertTrue("Incorrect source for Log4JLogger class",
|
assertTrue("Incorrect source for Log4JLogger class",
|
||||||
urlsToStrings[1].indexOf("/commons-logging-adapters-1.") > 0);
|
urlsToStrings[1].indexOf("/commons-logging-adapters-1.") > 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -283,23 +283,23 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testResourceAsStream() throws Exception {
|
public void testResourceAsStream() throws Exception {
|
||||||
java.io.InputStream is;
|
java.io.InputStream is;
|
||||||
|
|
||||||
// verify the classloader hierarchy
|
// verify the classloader hierarchy
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
ClassLoader childLoader = contextLoader.getParent();
|
ClassLoader childLoader = contextLoader.getParent();
|
||||||
ClassLoader parentLoader = childLoader.getParent();
|
ClassLoader parentLoader = childLoader.getParent();
|
||||||
ClassLoader bootLoader = parentLoader.getParent();
|
ClassLoader bootLoader = parentLoader.getParent();
|
||||||
assertNull("Unexpected classloader hierarchy", bootLoader);
|
assertNull("Unexpected classloader hierarchy", bootLoader);
|
||||||
|
|
||||||
// getResourceAsStream where no instances exist
|
// getResourceAsStream where no instances exist
|
||||||
is = childLoader.getResourceAsStream("nosuchfile");
|
is = childLoader.getResourceAsStream("nosuchfile");
|
||||||
assertNull("Invalid resource returned non-null stream", is);
|
assertNull("Invalid resource returned non-null stream", is);
|
||||||
|
|
||||||
// getResourceAsStream where resource does exist
|
// getResourceAsStream where resource does exist
|
||||||
is = childLoader.getResourceAsStream("org/apache/commons/logging/Log.class");
|
is = childLoader.getResourceAsStream("org/apache/commons/logging/Log.class");
|
||||||
assertNotNull("Null returned for valid resource", is);
|
assertNotNull("Null returned for valid resource", is);
|
||||||
is.close();
|
is.close();
|
||||||
|
|
||||||
// It would be nice to test parent-first ordering here, but that would require
|
// It would be nice to test parent-first ordering here, but that would require
|
||||||
// having a resource with the same name in both the parent and child loaders,
|
// having a resource with the same name in both the parent and child loaders,
|
||||||
// but with different contents. That's a little tricky to set up so we'll
|
// but with different contents. That's a little tricky to set up so we'll
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ public class MockSecurityManager extends SecurityManager {
|
|||||||
// requiring RuntimePermission: "accessClassInPackage.sun.util.logging.resources"
|
// requiring RuntimePermission: "accessClassInPackage.sun.util.logging.resources"
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cname.equals("java.security.AccessController")) {
|
if (cname.equals("java.security.AccessController")) {
|
||||||
// Presumably method name equals "doPrivileged"
|
// Presumably method name equals "doPrivileged"
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -76,11 +76,11 @@ public class SecurityForbiddenTestCase extends TestCase
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
// save security manager so it can be restored in tearDown
|
// save security manager so it can be restored in tearDown
|
||||||
oldSecMgr = System.getSecurityManager();
|
oldSecMgr = System.getSecurityManager();
|
||||||
|
|
||||||
PathableClassLoader classLoader = new PathableClassLoader(null);
|
PathableClassLoader classLoader = new PathableClassLoader(null);
|
||||||
classLoader.addLogicalLib("commons-logging");
|
classLoader.addLogicalLib("commons-logging");
|
||||||
classLoader.addLogicalLib("testclasses");
|
classLoader.addLogicalLib("testclasses");
|
||||||
|
|
||||||
otherClassLoader = classLoader;
|
otherClassLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ public class SecurityForbiddenTestCase extends TestCase
|
|||||||
/**
|
/**
|
||||||
* Test what happens when JCL is run with absolutely no security
|
* Test what happens when JCL is run with absolutely no security
|
||||||
* privileges at all and a class loaded with a different classloader
|
* privileges at all and a class loaded with a different classloader
|
||||||
* than the context classloader of the current thread tries to log something.
|
* than the context classloader of the current thread tries to log something.
|
||||||
*/
|
*/
|
||||||
public void testContextClassLoader() {
|
public void testContextClassLoader() {
|
||||||
System.setProperty(
|
System.setProperty(
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
|||||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
loader.addLogicalLib("testclasses");
|
loader.addLogicalLib("testclasses");
|
||||||
loader.addLogicalLib("commons-logging");
|
loader.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
Class testClass = loader.loadClass(thisClass.getName());
|
Class testClass = loader.loadClass(thisClass.getName());
|
||||||
return new PathableTestSuite(testClass, loader);
|
return new PathableTestSuite(testClass, loader);
|
||||||
}
|
}
|
||||||
@@ -192,18 +192,18 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
|||||||
assertTrue(((DecoratedSimpleLog) log).getShowShortName());
|
assertTrue(((DecoratedSimpleLog) log).getShowShortName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Hook for subclassses */
|
/** Hook for subclassses */
|
||||||
protected void checkShowDateTime() {
|
protected void checkShowDateTime() {
|
||||||
assertTrue(!((DecoratedSimpleLog) log).getShowDateTime());
|
assertTrue(!((DecoratedSimpleLog) log).getShowDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Hook for subclasses */
|
/** Hook for subclasses */
|
||||||
protected void checkDecoratedDateTime() {
|
protected void checkDecoratedDateTime() {
|
||||||
assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz",
|
assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz",
|
||||||
((DecoratedSimpleLog) log).getDateTimeFormat());
|
((DecoratedSimpleLog) log).getDateTimeFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Check the actual log records against the expected ones
|
// Check the actual log records against the expected ones
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class DefaultConfigTestCase extends TestCase {
|
|||||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
loader.addLogicalLib("testclasses");
|
loader.addLogicalLib("testclasses");
|
||||||
loader.addLogicalLib("commons-logging");
|
loader.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
Class testClass = loader.loadClass(thisClass.getName());
|
Class testClass = loader.loadClass(thisClass.getName());
|
||||||
return new PathableTestSuite(testClass, loader);
|
return new PathableTestSuite(testClass, loader);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class LogRecord implements Serializable {
|
|||||||
* Generated serial version ID.
|
* Generated serial version ID.
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -5254831759209770665L;
|
private static final long serialVersionUID = -5254831759209770665L;
|
||||||
|
|
||||||
public LogRecord(int type, Object message, Throwable t) {
|
public LogRecord(int type, Object message, Throwable t) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class BadTCCLTestCase extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test methods
|
// test methods
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test just tests that a log implementation can be found
|
* This test just tests that a log implementation can be found
|
||||||
* by the LogFactory.
|
* by the LogFactory.
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class NullTCCLTestCase extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test methods
|
// test methods
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test just tests that a log implementation can be found
|
* This test just tests that a log implementation can be found
|
||||||
* by the LogFactory.
|
* by the LogFactory.
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import org.apache.commons.logging.PathableTestSuite;
|
|||||||
|
|
||||||
public class TcclDisabledTestCase extends TestCase {
|
public class TcclDisabledTestCase extends TestCase {
|
||||||
|
|
||||||
public static final String MY_LOG_PKG =
|
public static final String MY_LOG_PKG =
|
||||||
"org.apache.commons.logging.tccl.custom";
|
"org.apache.commons.logging.tccl.custom";
|
||||||
|
|
||||||
public static final String MY_LOG_IMPL =
|
public static final String MY_LOG_IMPL =
|
||||||
@@ -58,7 +58,7 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
dummy.addLogicalLib("testclasses");
|
dummy.addLogicalLib("testclasses");
|
||||||
dummy.addLogicalLib("commons-logging");
|
dummy.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||||
URL baseUrl = dummy.findResource(thisClassPath);
|
URL baseUrl = dummy.findResource(thisClassPath);
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
// Log class. Therefore if that class can be found, then the
|
// Log class. Therefore if that class can be found, then the
|
||||||
// TCCL must have been used to load it.
|
// TCCL must have been used to load it.
|
||||||
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||||
|
|
||||||
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
parentLoader.addLogicalLib("commons-logging");
|
parentLoader.addLogicalLib("commons-logging");
|
||||||
@@ -77,7 +77,7 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
// hack to ensure that the testcase classloader can't see
|
// hack to ensure that the testcase classloader can't see
|
||||||
// the custom MyLog
|
// the custom MyLog
|
||||||
parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
|
parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
|
||||||
|
|
||||||
URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
|
URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
|
||||||
parentLoader.addURL(propsEnableUrl);
|
parentLoader.addURL(propsEnableUrl);
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
* Verify that MyLog is only loadable via the tccl.
|
* Verify that MyLog is only loadable via the tccl.
|
||||||
*/
|
*/
|
||||||
public void testLoader() throws Exception {
|
public void testLoader() throws Exception {
|
||||||
|
|
||||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||||
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
} catch(ClassNotFoundException ex) {
|
} catch(ClassNotFoundException ex) {
|
||||||
// ok, expected
|
// ok, expected
|
||||||
}
|
}
|
||||||
|
|
||||||
// MyLog should be loadable via tccl loader
|
// MyLog should be loadable via tccl loader
|
||||||
try {
|
try {
|
||||||
Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
||||||
@@ -142,7 +142,7 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
public void testTcclLoading() throws Exception {
|
public void testTcclLoading() throws Exception {
|
||||||
LogFactory instance = LogFactory.getFactory();
|
LogFactory instance = LogFactory.getFactory();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Correct LogFactory loaded",
|
"Correct LogFactory loaded",
|
||||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||||
instance.getClass().getName());
|
instance.getClass().getName());
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import org.apache.commons.logging.PathableTestSuite;
|
|||||||
|
|
||||||
public class TcclEnabledTestCase extends TestCase {
|
public class TcclEnabledTestCase extends TestCase {
|
||||||
|
|
||||||
public static final String MY_LOG_PKG =
|
public static final String MY_LOG_PKG =
|
||||||
"org.apache.commons.logging.tccl.custom";
|
"org.apache.commons.logging.tccl.custom";
|
||||||
|
|
||||||
public static final String MY_LOG_IMPL =
|
public static final String MY_LOG_IMPL =
|
||||||
@@ -58,7 +58,7 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
dummy.addLogicalLib("testclasses");
|
dummy.addLogicalLib("testclasses");
|
||||||
dummy.addLogicalLib("commons-logging");
|
dummy.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||||
URL baseUrl = dummy.findResource(thisClassPath);
|
URL baseUrl = dummy.findResource(thisClassPath);
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
// Log class. Therefore if that class can be found, then the
|
// Log class. Therefore if that class can be found, then the
|
||||||
// TCCL must have been used to load it.
|
// TCCL must have been used to load it.
|
||||||
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||||
|
|
||||||
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
parentLoader.addLogicalLib("commons-logging");
|
parentLoader.addLogicalLib("commons-logging");
|
||||||
@@ -77,7 +77,7 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
// hack to ensure that the testcase classloader can't see
|
// hack to ensure that the testcase classloader can't see
|
||||||
// the custom MyLogFactoryImpl
|
// the custom MyLogFactoryImpl
|
||||||
parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
|
parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
|
||||||
|
|
||||||
URL propsEnableUrl = new URL(baseUrl, "props_enable_tccl/");
|
URL propsEnableUrl = new URL(baseUrl, "props_enable_tccl/");
|
||||||
parentLoader.addURL(propsEnableUrl);
|
parentLoader.addURL(propsEnableUrl);
|
||||||
|
|
||||||
@@ -108,10 +108,10 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
* Verify that MyLogFactoryImpl is only loadable via the tccl.
|
* Verify that MyLogFactoryImpl is only loadable via the tccl.
|
||||||
*/
|
*/
|
||||||
public void testLoader() throws Exception {
|
public void testLoader() throws Exception {
|
||||||
|
|
||||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||||
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
// the tccl loader should NOT be the same as the loader that loaded this test class.
|
// 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 classloader", thisClassLoader, tcclLoader);
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
} catch(ClassNotFoundException ex) {
|
} catch(ClassNotFoundException ex) {
|
||||||
// ok, expected
|
// ok, expected
|
||||||
}
|
}
|
||||||
|
|
||||||
// MyLog should be loadable via tccl loader
|
// MyLog should be loadable via tccl loader
|
||||||
try {
|
try {
|
||||||
Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
||||||
@@ -140,9 +140,9 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testTcclLoading() throws Exception {
|
public void testTcclLoading() throws Exception {
|
||||||
LogFactory instance = LogFactory.getFactory();
|
LogFactory instance = LogFactory.getFactory();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Correct LogFactory loaded",
|
"Correct LogFactory loaded",
|
||||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||||
instance.getClass().getName());
|
instance.getClass().getName());
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import org.apache.commons.logging.PathableTestSuite;
|
|||||||
|
|
||||||
public class TcclDisabledTestCase extends TestCase {
|
public class TcclDisabledTestCase extends TestCase {
|
||||||
|
|
||||||
public static final String MY_LOG_FACTORY_PKG =
|
public static final String MY_LOG_FACTORY_PKG =
|
||||||
"org.apache.commons.logging.tccl.custom";
|
"org.apache.commons.logging.tccl.custom";
|
||||||
|
|
||||||
public static final String MY_LOG_FACTORY_IMPL =
|
public static final String MY_LOG_FACTORY_IMPL =
|
||||||
@@ -58,7 +58,7 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
dummy.addLogicalLib("testclasses");
|
dummy.addLogicalLib("testclasses");
|
||||||
dummy.addLogicalLib("commons-logging");
|
dummy.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||||
URL baseUrl = dummy.findResource(thisClassPath);
|
URL baseUrl = dummy.findResource(thisClassPath);
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
// LogFactory class. Therefore if that class can be found, then the
|
// LogFactory class. Therefore if that class can be found, then the
|
||||||
// TCCL must have been used to load it.
|
// TCCL must have been used to load it.
|
||||||
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||||
|
|
||||||
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
parentLoader.addLogicalLib("commons-logging");
|
parentLoader.addLogicalLib("commons-logging");
|
||||||
@@ -79,7 +79,7 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
// the custom MyLogFactoryImpl
|
// the custom MyLogFactoryImpl
|
||||||
parentLoader.useExplicitLoader(
|
parentLoader.useExplicitLoader(
|
||||||
MY_LOG_FACTORY_PKG + ".", emptyLoader);
|
MY_LOG_FACTORY_PKG + ".", emptyLoader);
|
||||||
|
|
||||||
URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
|
URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
|
||||||
parentLoader.addURL(propsEnableUrl);
|
parentLoader.addURL(propsEnableUrl);
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
* Verify that MyLogFactoryImpl is only loadable via the tccl.
|
* Verify that MyLogFactoryImpl is only loadable via the tccl.
|
||||||
*/
|
*/
|
||||||
public void testLoader() throws Exception {
|
public void testLoader() throws Exception {
|
||||||
|
|
||||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||||
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
} catch(ClassNotFoundException ex) {
|
} catch(ClassNotFoundException ex) {
|
||||||
// ok, expected
|
// ok, expected
|
||||||
}
|
}
|
||||||
|
|
||||||
// MyLogFactoryImpl should be loadable via tccl loader
|
// MyLogFactoryImpl should be loadable via tccl loader
|
||||||
try {
|
try {
|
||||||
Class clazz = tcclLoader.loadClass(MY_LOG_FACTORY_IMPL);
|
Class clazz = tcclLoader.loadClass(MY_LOG_FACTORY_IMPL);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
dummy.addLogicalLib("testclasses");
|
dummy.addLogicalLib("testclasses");
|
||||||
dummy.addLogicalLib("commons-logging");
|
dummy.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||||
URL baseUrl = dummy.findResource(thisClassPath);
|
URL baseUrl = dummy.findResource(thisClassPath);
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
// LogFactory class. Therefore if that class can be found, then the
|
// LogFactory class. Therefore if that class can be found, then the
|
||||||
// TCCL must have been used to load it.
|
// TCCL must have been used to load it.
|
||||||
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||||
|
|
||||||
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
parentLoader.addLogicalLib("commons-logging");
|
parentLoader.addLogicalLib("commons-logging");
|
||||||
@@ -73,7 +73,7 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
// the cust MyLogFactoryImpl
|
// the cust MyLogFactoryImpl
|
||||||
parentLoader.useExplicitLoader(
|
parentLoader.useExplicitLoader(
|
||||||
"org.apache.commons.logging.tccl.custom.", emptyLoader);
|
"org.apache.commons.logging.tccl.custom.", emptyLoader);
|
||||||
|
|
||||||
URL propsEnableUrl = new URL(baseUrl, "props_enable_tccl/");
|
URL propsEnableUrl = new URL(baseUrl, "props_enable_tccl/");
|
||||||
parentLoader.addURL(propsEnableUrl);
|
parentLoader.addURL(propsEnableUrl);
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
* Verify that MyLogFactoryImpl is only loadable via the tccl.
|
* Verify that MyLogFactoryImpl is only loadable via the tccl.
|
||||||
*/
|
*/
|
||||||
public void testLoader() throws Exception {
|
public void testLoader() throws Exception {
|
||||||
|
|
||||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||||
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
} catch(ClassNotFoundException ex) {
|
} catch(ClassNotFoundException ex) {
|
||||||
// ok, expected
|
// ok, expected
|
||||||
}
|
}
|
||||||
|
|
||||||
// MyLogFactoryImpl should be loadable via tccl loader
|
// MyLogFactoryImpl should be loadable via tccl loader
|
||||||
try {
|
try {
|
||||||
Class clazz = tcclLoader.loadClass(
|
Class clazz = tcclLoader.loadClass(
|
||||||
@@ -138,9 +138,9 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testTcclLoading() throws Exception {
|
public void testTcclLoading() throws Exception {
|
||||||
LogFactory instance = LogFactory.getFactory();
|
LogFactory instance = LogFactory.getFactory();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Correct LogFactory loaded",
|
"Correct LogFactory loaded",
|
||||||
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl",
|
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl",
|
||||||
instance.getClass().getName());
|
instance.getClass().getName());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user