Use final.
This commit is contained in:
@@ -33,7 +33,7 @@ public abstract class AbstractLogTest extends TestCase {
|
||||
|
||||
public void testLoggingWithNullParameters()
|
||||
{
|
||||
Log log = this.getLogObject();
|
||||
final Log log = this.getLogObject();
|
||||
|
||||
assertNotNull(log);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class AltHashtable extends Hashtable {
|
||||
public static Object lastKey;
|
||||
public static Object lastValue;
|
||||
|
||||
public Object put(Object key, Object value) {
|
||||
public Object put(final Object key, final Object value) {
|
||||
lastKey = key;
|
||||
lastValue = value;
|
||||
return super.put(key, value);
|
||||
|
||||
@@ -28,15 +28,15 @@ import junit.framework.TestCase;
|
||||
public class AltHashtableTestCase extends TestCase {
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = AltHashtableTestCase.class;
|
||||
ClassLoader thisClassLoader = thisClass.getClassLoader();
|
||||
final Class thisClass = AltHashtableTestCase.class;
|
||||
final ClassLoader thisClassLoader = thisClass.getClassLoader();
|
||||
|
||||
PathableClassLoader loader = new PathableClassLoader(null);
|
||||
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||
loader.useExplicitLoader("junit.", thisClassLoader);
|
||||
loader.addLogicalLib("testclasses");
|
||||
loader.addLogicalLib("commons-logging");
|
||||
|
||||
Class testClass = loader.loadClass(thisClass.getName());
|
||||
final Class testClass = loader.loadClass(thisClass.getName());
|
||||
return new PathableTestSuite(testClass, loader);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class AltHashtableTestCase extends TestCase {
|
||||
AltHashtable.lastValue = null;
|
||||
|
||||
LogFactory.getLog(AltHashtableTestCase.class);
|
||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
assertEquals(contextLoader, AltHashtable.lastKey);
|
||||
assertNotNull(AltHashtable.lastValue);
|
||||
}
|
||||
|
||||
@@ -29,17 +29,17 @@ public class BasicOperationsTestCase extends TestCase
|
||||
{
|
||||
public void testIsEnabledClassLog()
|
||||
{
|
||||
Log log = LogFactory.getLog(BasicOperationsTestCase.class);
|
||||
final Log log = LogFactory.getLog(BasicOperationsTestCase.class);
|
||||
executeIsEnabledTest(log);
|
||||
}
|
||||
|
||||
public void testIsEnabledNamedLog()
|
||||
{
|
||||
Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
|
||||
final Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
|
||||
executeIsEnabledTest(log);
|
||||
}
|
||||
|
||||
public void executeIsEnabledTest(Log log)
|
||||
public void executeIsEnabledTest(final Log log)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -50,7 +50,7 @@ public class BasicOperationsTestCase extends TestCase
|
||||
log.isErrorEnabled();
|
||||
log.isFatalEnabled();
|
||||
}
|
||||
catch (Throwable t)
|
||||
catch (final Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
fail("Exception thrown: " + t);
|
||||
@@ -59,17 +59,17 @@ public class BasicOperationsTestCase extends TestCase
|
||||
|
||||
public void testMessageWithoutExceptionClassLog()
|
||||
{
|
||||
Log log = LogFactory.getLog(BasicOperationsTestCase.class);
|
||||
final Log log = LogFactory.getLog(BasicOperationsTestCase.class);
|
||||
executeMessageWithoutExceptionTest(log);
|
||||
}
|
||||
|
||||
public void testMessageWithoutExceptionNamedLog()
|
||||
{
|
||||
Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
|
||||
final Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
|
||||
executeMessageWithoutExceptionTest(log);
|
||||
}
|
||||
|
||||
public void executeMessageWithoutExceptionTest(Log log)
|
||||
public void executeMessageWithoutExceptionTest(final Log log)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -80,7 +80,7 @@ public class BasicOperationsTestCase extends TestCase
|
||||
log.error("Hello, Mum");
|
||||
log.fatal("Hello, Mum");
|
||||
}
|
||||
catch (Throwable t)
|
||||
catch (final Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
fail("Exception thrown: " + t);
|
||||
@@ -89,17 +89,17 @@ public class BasicOperationsTestCase extends TestCase
|
||||
|
||||
public void testMessageWithExceptionClassLog()
|
||||
{
|
||||
Log log = LogFactory.getLog(BasicOperationsTestCase.class);
|
||||
final Log log = LogFactory.getLog(BasicOperationsTestCase.class);
|
||||
executeMessageWithExceptionTest(log);
|
||||
}
|
||||
|
||||
public void testMessageWithExceptionNamedLog()
|
||||
{
|
||||
Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
|
||||
final Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
|
||||
executeMessageWithExceptionTest(log);
|
||||
}
|
||||
|
||||
public void executeMessageWithExceptionTest(Log log)
|
||||
public void executeMessageWithExceptionTest(final Log log)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -110,7 +110,7 @@ public class BasicOperationsTestCase extends TestCase
|
||||
log.error("Hello, Mum", new ArithmeticException());
|
||||
log.fatal("Hello, Mum", new ArithmeticException());
|
||||
}
|
||||
catch (Throwable t)
|
||||
catch (final Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
fail("Exception thrown: " + t);
|
||||
|
||||
@@ -41,11 +41,11 @@ public class LoadTestCase extends TestCase{
|
||||
|
||||
java.util.Map classes = new java.util.HashMap();
|
||||
|
||||
AppClassLoader(ClassLoader parent){
|
||||
AppClassLoader(final ClassLoader parent){
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private Class def(String name)throws ClassNotFoundException{
|
||||
private Class def(final String name)throws ClassNotFoundException{
|
||||
|
||||
Class result = (Class)classes.get(name);
|
||||
if(result != null){
|
||||
@@ -54,23 +54,23 @@ public class LoadTestCase extends TestCase{
|
||||
|
||||
try{
|
||||
|
||||
ClassLoader cl = this.getClass().getClassLoader();
|
||||
String classFileName = name.replace('.','/') + ".class";
|
||||
java.io.InputStream is = cl.getResourceAsStream(classFileName);
|
||||
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
|
||||
final ClassLoader cl = this.getClass().getClassLoader();
|
||||
final String classFileName = name.replace('.','/') + ".class";
|
||||
final java.io.InputStream is = cl.getResourceAsStream(classFileName);
|
||||
final java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
|
||||
|
||||
while(is.available() > 0){
|
||||
out.write(is.read());
|
||||
}
|
||||
|
||||
byte data [] = out.toByteArray();
|
||||
final byte data [] = out.toByteArray();
|
||||
|
||||
result = super.defineClass(name, data, 0, data.length );
|
||||
classes.put(name,result);
|
||||
|
||||
return result;
|
||||
|
||||
}catch(java.io.IOException ioe){
|
||||
}catch(final java.io.IOException ioe){
|
||||
|
||||
throw new ClassNotFoundException( name + " caused by "
|
||||
+ ioe.getMessage() );
|
||||
@@ -81,7 +81,7 @@ public class LoadTestCase extends TestCase{
|
||||
|
||||
// not very trivial to emulate we must implement "findClass",
|
||||
// but it will delegete to junit class loder first
|
||||
public Class loadClass(String name)throws ClassNotFoundException{
|
||||
public Class loadClass(final String name)throws ClassNotFoundException{
|
||||
|
||||
//isolates all logging classes, application in the same classloader too.
|
||||
//filters exeptions to simlify handling in test
|
||||
@@ -102,9 +102,9 @@ public class LoadTestCase extends TestCase{
|
||||
* (expected to be a UserClass loaded via a custom classloader), passing
|
||||
* it the specified state parameter.
|
||||
*/
|
||||
private void setAllowFlawedContext(Class c, String state) throws Exception {
|
||||
Class[] params = {String.class};
|
||||
java.lang.reflect.Method m = c.getDeclaredMethod("setAllowFlawedContext", params);
|
||||
private void setAllowFlawedContext(final Class c, final String state) throws Exception {
|
||||
final Class[] params = {String.class};
|
||||
final java.lang.reflect.Method m = c.getDeclaredMethod("setAllowFlawedContext", params);
|
||||
m.invoke(null, new Object[] {state});
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public class LoadTestCase extends TestCase{
|
||||
setAllowFlawedContext(cls, "false");
|
||||
execute(cls);
|
||||
fail("Logging config succeeded when context classloader was null!");
|
||||
} catch(LogConfigurationException ex) {
|
||||
} catch(final LogConfigurationException ex) {
|
||||
// expected; the boot classloader doesn't *have* JCL available
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public class LoadTestCase extends TestCase{
|
||||
execute(cls);
|
||||
fail("Error: somehow downcast a Logger loaded via system classloader"
|
||||
+ " to the Log interface loaded via a custom classloader");
|
||||
} catch(LogConfigurationException ex) {
|
||||
} catch(final LogConfigurationException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
@@ -183,15 +183,15 @@ public class LoadTestCase extends TestCase{
|
||||
|
||||
Class testObjCls = null;
|
||||
|
||||
AppClassLoader appLoader = new AppClassLoader(
|
||||
final AppClassLoader appLoader = new AppClassLoader(
|
||||
this.getClass().getClassLoader());
|
||||
try{
|
||||
|
||||
testObjCls = appLoader.loadClass(UserClass.class.getName());
|
||||
|
||||
}catch(ClassNotFoundException cnfe){
|
||||
}catch(final ClassNotFoundException cnfe){
|
||||
throw cnfe;
|
||||
}catch(Throwable t){
|
||||
}catch(final Throwable t){
|
||||
t.printStackTrace();
|
||||
fail("AppClassLoader failed ");
|
||||
}
|
||||
@@ -205,7 +205,7 @@ public class LoadTestCase extends TestCase{
|
||||
}
|
||||
|
||||
|
||||
private void execute(Class cls)throws Exception{
|
||||
private void execute(final Class cls)throws Exception{
|
||||
|
||||
cls.newInstance();
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* creates its own classloader to run unit tests in (eg maven2's
|
||||
* Surefire plugin).
|
||||
*/
|
||||
public PathableClassLoader(ClassLoader parent) {
|
||||
public PathableClassLoader(final ClassLoader parent) {
|
||||
super(NO_URLS, parent);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* use addLogicalLib instead, then define the location for that logical
|
||||
* library in the build.xml file.
|
||||
*/
|
||||
public void addURL(URL url) {
|
||||
public void addURL(final URL url) {
|
||||
super.addURL(url);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* <p>
|
||||
* This value defaults to true.
|
||||
*/
|
||||
public void setParentFirst(boolean state) {
|
||||
public void setParentFirst(final boolean state) {
|
||||
parentFirst = state;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* Of course, this assumes that the classes of interest are already
|
||||
* in the classpath of the system classloader.
|
||||
*/
|
||||
public void useSystemLoader(String prefix) {
|
||||
public void useSystemLoader(final String prefix) {
|
||||
useExplicitLoader(prefix, ClassLoader.getSystemClassLoader());
|
||||
|
||||
}
|
||||
@@ -168,7 +168,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* then a prefix used to map from here to one of those classloaders.
|
||||
* </ul>
|
||||
*/
|
||||
public void useExplicitLoader(String prefix, ClassLoader loader) {
|
||||
public void useExplicitLoader(final String prefix, final ClassLoader loader) {
|
||||
if (lookasides == null) {
|
||||
lookasides = new HashMap();
|
||||
}
|
||||
@@ -178,7 +178,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
/**
|
||||
* Specify a collection of logical libraries. See addLogicalLib.
|
||||
*/
|
||||
public void addLogicalLib(String[] logicalLibs) {
|
||||
public void addLogicalLib(final String[] logicalLibs) {
|
||||
for(int i=0; i<logicalLibs.length; ++i) {
|
||||
addLogicalLib(logicalLibs[i]);
|
||||
}
|
||||
@@ -204,22 +204,22 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* desired classpath without knowing the exact location of the necessary
|
||||
* classes.
|
||||
*/
|
||||
public void addLogicalLib(String logicalLib) {
|
||||
public void addLogicalLib(final String logicalLib) {
|
||||
// first, check the system properties
|
||||
String filename = System.getProperty(logicalLib);
|
||||
final String filename = System.getProperty(logicalLib);
|
||||
if (filename != null) {
|
||||
try {
|
||||
URL libUrl = new File(filename).toURL();
|
||||
final URL libUrl = new File(filename).toURL();
|
||||
addURL(libUrl);
|
||||
return;
|
||||
} catch(java.net.MalformedURLException e) {
|
||||
} catch(final java.net.MalformedURLException e) {
|
||||
throw new UnknownError(
|
||||
"Invalid file [" + filename + "] for logical lib [" + logicalLib + "]");
|
||||
}
|
||||
}
|
||||
|
||||
// now check the classpath for a similar-named lib
|
||||
URL libUrl = libFromClasspath(logicalLib);
|
||||
final URL libUrl = libFromClasspath(logicalLib);
|
||||
if (libUrl != null) {
|
||||
addURL(libUrl);
|
||||
return;
|
||||
@@ -250,18 +250,18 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* if "foo-1.1.jar" and "foobar-1.1.jar" are in the path, then a logicalLib
|
||||
* name of "foo" will match the first entry above.
|
||||
*/
|
||||
private URL libFromClasspath(String logicalLib) {
|
||||
ClassLoader cl = this.getClass().getClassLoader();
|
||||
private URL libFromClasspath(final String logicalLib) {
|
||||
final ClassLoader cl = this.getClass().getClassLoader();
|
||||
if (cl instanceof URLClassLoader == false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
URLClassLoader ucl = (URLClassLoader) cl;
|
||||
URL[] path = ucl.getURLs();
|
||||
final URLClassLoader ucl = (URLClassLoader) cl;
|
||||
final URL[] path = ucl.getURLs();
|
||||
URL shortestMatch = null;
|
||||
int shortestMatchLen = Integer.MAX_VALUE;
|
||||
for(int i=0; i<path.length; ++i) {
|
||||
URL u = path[i];
|
||||
final URL u = path[i];
|
||||
|
||||
// extract the filename bit on the end of the url
|
||||
String filename = u.toString();
|
||||
@@ -270,7 +270,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
continue;
|
||||
}
|
||||
|
||||
int lastSlash = filename.lastIndexOf('/');
|
||||
final int lastSlash = filename.lastIndexOf('/');
|
||||
if (lastSlash >= 0) {
|
||||
filename = filename.substring(lastSlash+1);
|
||||
}
|
||||
@@ -294,7 +294,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* prefix associated with that entry then attempt to load the class via
|
||||
* that entries' classloader.
|
||||
*/
|
||||
protected Class loadClass(String name, boolean resolve)
|
||||
protected Class loadClass(final String name, final boolean resolve)
|
||||
throws ClassNotFoundException {
|
||||
// just for performance, check java and javax
|
||||
if (name.startsWith("java.") || name.startsWith("javax.")) {
|
||||
@@ -302,12 +302,12 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
}
|
||||
|
||||
if (lookasides != null) {
|
||||
for(Iterator i = lookasides.entrySet().iterator(); i.hasNext(); ) {
|
||||
Map.Entry entry = (Map.Entry) i.next();
|
||||
String prefix = (String) entry.getKey();
|
||||
for(final Iterator i = lookasides.entrySet().iterator(); i.hasNext(); ) {
|
||||
final Map.Entry entry = (Map.Entry) i.next();
|
||||
final String prefix = (String) entry.getKey();
|
||||
if (name.startsWith(prefix) == true) {
|
||||
ClassLoader loader = (ClassLoader) entry.getValue();
|
||||
Class clazz = Class.forName(name, resolve, loader);
|
||||
final ClassLoader loader = (ClassLoader) entry.getValue();
|
||||
final Class clazz = Class.forName(name, resolve, loader);
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
@@ -332,7 +332,7 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
resolveClass(clazz);
|
||||
}
|
||||
return clazz;
|
||||
} catch(ClassNotFoundException e) {
|
||||
} catch(final ClassNotFoundException e) {
|
||||
return super.loadClass(name, resolve);
|
||||
}
|
||||
}
|
||||
@@ -343,11 +343,11 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* the resource is looked for in the local classpath before the parent
|
||||
* loader is consulted.
|
||||
*/
|
||||
public URL getResource(String name) {
|
||||
public URL getResource(final String name) {
|
||||
if (parentFirst) {
|
||||
return super.getResource(name);
|
||||
} else {
|
||||
URL local = super.findResource(name);
|
||||
final URL local = super.findResource(name);
|
||||
if (local != null) {
|
||||
return local;
|
||||
}
|
||||
@@ -363,13 +363,13 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* it's declared final in java1.4 (thought that's been removed for 1.5).
|
||||
* The inherited implementation always behaves as if parentFirst=true.
|
||||
*/
|
||||
public Enumeration getResourcesInOrder(String name) throws IOException {
|
||||
public Enumeration getResourcesInOrder(final String name) throws IOException {
|
||||
if (parentFirst) {
|
||||
return super.getResources(name);
|
||||
} else {
|
||||
Enumeration localUrls = super.findResources(name);
|
||||
final Enumeration localUrls = super.findResources(name);
|
||||
|
||||
ClassLoader parent = getParent();
|
||||
final ClassLoader parent = getParent();
|
||||
if (parent == null) {
|
||||
// Alas, there is no method to get matching resources
|
||||
// from a null (BOOT) parent classloader. Calling
|
||||
@@ -383,10 +383,10 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
// path!
|
||||
return localUrls;
|
||||
}
|
||||
Enumeration parentUrls = parent.getResources(name);
|
||||
final Enumeration parentUrls = parent.getResources(name);
|
||||
|
||||
ArrayList localItems = toList(localUrls);
|
||||
ArrayList parentItems = toList(parentUrls);
|
||||
final ArrayList localItems = toList(localUrls);
|
||||
final ArrayList parentItems = toList(parentUrls);
|
||||
localItems.addAll(parentItems);
|
||||
return Collections.enumeration(localItems);
|
||||
}
|
||||
@@ -400,11 +400,11 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* @return <code>ArrayList</code> containing the enumerated
|
||||
* elements in the enumerated order, not null
|
||||
*/
|
||||
private ArrayList toList(Enumeration en) {
|
||||
ArrayList results = new ArrayList();
|
||||
private ArrayList toList(final Enumeration en) {
|
||||
final ArrayList results = new ArrayList();
|
||||
if (en != null) {
|
||||
while (en.hasMoreElements()){
|
||||
Object element = en.nextElement();
|
||||
final Object element = en.nextElement();
|
||||
results.add(element);
|
||||
}
|
||||
}
|
||||
@@ -416,15 +416,15 @@ public class PathableClassLoader extends URLClassLoader {
|
||||
* the resource is looked for in the local classpath before the parent
|
||||
* loader is consulted.
|
||||
*/
|
||||
public InputStream getResourceAsStream(String name) {
|
||||
public InputStream getResourceAsStream(final String name) {
|
||||
if (parentFirst) {
|
||||
return super.getResourceAsStream(name);
|
||||
} else {
|
||||
URL local = super.findResource(name);
|
||||
final URL local = super.findResource(name);
|
||||
if (local != null) {
|
||||
try {
|
||||
return local.openStream();
|
||||
} catch(IOException e) {
|
||||
} catch(final IOException e) {
|
||||
// TODO: check if this is right or whether we should
|
||||
// fall back to trying parent. The javadoc doesn't say...
|
||||
return null;
|
||||
|
||||
@@ -120,7 +120,7 @@ public class PathableTestSuite extends TestSuite {
|
||||
* calls to Thread.currentThread.getContextClassLoader from test methods
|
||||
* (or any method called by test methods).
|
||||
*/
|
||||
public PathableTestSuite(Class testClass, ClassLoader contextClassLoader) {
|
||||
public PathableTestSuite(final Class testClass, final ClassLoader contextClassLoader) {
|
||||
super(testClass);
|
||||
contextLoader = contextClassLoader;
|
||||
}
|
||||
@@ -133,9 +133,9 @@ public class PathableTestSuite extends TestSuite {
|
||||
* The context classloader and system properties are saved before each
|
||||
* test, and restored after the test completes to better isolate tests.
|
||||
*/
|
||||
public void runTest(Test test, TestResult result) {
|
||||
ClassLoader origContext = Thread.currentThread().getContextClassLoader();
|
||||
Properties oldSysProps = (Properties) System.getProperties().clone();
|
||||
public void runTest(final Test test, final TestResult result) {
|
||||
final ClassLoader origContext = Thread.currentThread().getContextClassLoader();
|
||||
final Properties oldSysProps = (Properties) System.getProperties().clone();
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(contextLoader);
|
||||
test.run(result);
|
||||
|
||||
@@ -29,13 +29,13 @@ public class UserClass {
|
||||
* when an instance of this class is actually created <i>before</i> calling
|
||||
* this method!
|
||||
*/
|
||||
public static void setAllowFlawedContext(String state) {
|
||||
LogFactory f = LogFactory.getFactory();
|
||||
public static void setAllowFlawedContext(final String state) {
|
||||
final LogFactory f = LogFactory.getFactory();
|
||||
f.setAttribute(LogFactoryImpl.ALLOW_FLAWED_CONTEXT_PROPERTY, state);
|
||||
}
|
||||
|
||||
public UserClass() {
|
||||
Log log = LogFactory.getLog(LoadTestCase.class);
|
||||
final Log log = LogFactory.getLog(LoadTestCase.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,14 +31,14 @@ import junit.framework.TestSuite;
|
||||
public class AvalonLoggerTestCase extends AbstractLogTest {
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
final TestSuite suite = new TestSuite();
|
||||
suite.addTestSuite(AvalonLoggerTestCase.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
public Log getLogObject() {
|
||||
// Output does not seem to be used, so don't display it.
|
||||
Log log = new AvalonLogger(new NullLogger());
|
||||
final Log log = new AvalonLogger(new NullLogger());
|
||||
return log;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,39 +48,39 @@ public class FirstPriorityConfigTestCase extends TestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = FirstPriorityConfigTestCase.class;
|
||||
final Class thisClass = FirstPriorityConfigTestCase.class;
|
||||
|
||||
// Determine the URL to this .class file, so that we can then
|
||||
// append the priority dirs to it. For tidiness, load this
|
||||
// class through a dummy loader though this is not absolutely
|
||||
// necessary...
|
||||
PathableClassLoader dummy = new PathableClassLoader(null);
|
||||
final PathableClassLoader dummy = new PathableClassLoader(null);
|
||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
dummy.addLogicalLib("testclasses");
|
||||
dummy.addLogicalLib("commons-logging");
|
||||
|
||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
URL baseUrl = dummy.findResource(thisClassPath);
|
||||
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||
|
||||
// Now set up the desired classloader hierarchy. We'll put JCL
|
||||
// in the container path, the testcase in a webapp path, and
|
||||
// both config files into the webapp path too.
|
||||
PathableClassLoader containerLoader = new PathableClassLoader(null);
|
||||
final PathableClassLoader containerLoader = new PathableClassLoader(null);
|
||||
containerLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
containerLoader.addLogicalLib("commons-logging");
|
||||
|
||||
PathableClassLoader webappLoader = new PathableClassLoader(containerLoader);
|
||||
final PathableClassLoader webappLoader = new PathableClassLoader(containerLoader);
|
||||
webappLoader.addLogicalLib("testclasses");
|
||||
|
||||
URL pri20URL = new URL(baseUrl, "priority20/");
|
||||
final URL pri20URL = new URL(baseUrl, "priority20/");
|
||||
webappLoader.addURL(pri20URL);
|
||||
|
||||
URL pri10URL = new URL(baseUrl, "priority10/");
|
||||
final URL pri10URL = new URL(baseUrl, "priority10/");
|
||||
webappLoader.addURL(pri10URL);
|
||||
|
||||
// load the test class via webapp loader, and use the webapp loader
|
||||
// as the tccl loader too.
|
||||
Class testClass = webappLoader.loadClass(thisClass.getName());
|
||||
final Class testClass = webappLoader.loadClass(thisClass.getName());
|
||||
return new PathableTestSuite(testClass, webappLoader);
|
||||
}
|
||||
|
||||
@@ -105,11 +105,11 @@ public class FirstPriorityConfigTestCase extends TestCase {
|
||||
* the desired configId value.
|
||||
*/
|
||||
public void testPriority() throws Exception {
|
||||
LogFactory instance = LogFactory.getFactory();
|
||||
final LogFactory instance = LogFactory.getFactory();
|
||||
|
||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||
ClassLoader lfClassLoader = instance.getClass().getClassLoader();
|
||||
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||
final ClassLoader lfClassLoader = instance.getClass().getClassLoader();
|
||||
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
// context classloader should be thisClassLoader
|
||||
assertEquals(thisClassLoader, contextClassLoader);
|
||||
@@ -119,7 +119,7 @@ public class FirstPriorityConfigTestCase extends TestCase {
|
||||
assertEquals(PathableClassLoader.class.getName(),
|
||||
lfClassLoader.getClass().getName());
|
||||
|
||||
String id = (String) instance.getAttribute("configId");
|
||||
final String id = (String) instance.getAttribute("configId");
|
||||
assertEquals("Correct config file loaded", "priority20", id );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,19 +55,19 @@ public class PriorityConfigTestCase extends TestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = PriorityConfigTestCase.class;
|
||||
final Class thisClass = PriorityConfigTestCase.class;
|
||||
|
||||
// Determine the URL to this .class file, so that we can then
|
||||
// append the priority dirs to it. For tidiness, load this
|
||||
// class through a dummy loader though this is not absolutely
|
||||
// necessary...
|
||||
PathableClassLoader dummy = new PathableClassLoader(null);
|
||||
final PathableClassLoader dummy = new PathableClassLoader(null);
|
||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
dummy.addLogicalLib("testclasses");
|
||||
dummy.addLogicalLib("commons-logging");
|
||||
|
||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
URL baseUrl = dummy.findResource(thisClassPath);
|
||||
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
|
||||
// file of priority=10 in the container path, and ones of both
|
||||
@@ -76,29 +76,29 @@ public class PriorityConfigTestCase extends TestCase {
|
||||
// A second properties file with priority=20 is also added,
|
||||
// so we can check that the first one in the classpath is
|
||||
// used.
|
||||
PathableClassLoader containerLoader = new PathableClassLoader(null);
|
||||
final PathableClassLoader containerLoader = new PathableClassLoader(null);
|
||||
containerLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
containerLoader.addLogicalLib("commons-logging");
|
||||
|
||||
URL pri10URL = new URL(baseUrl, "priority10/");
|
||||
final URL pri10URL = new URL(baseUrl, "priority10/");
|
||||
containerLoader.addURL(pri10URL);
|
||||
|
||||
PathableClassLoader webappLoader = new PathableClassLoader(containerLoader);
|
||||
final PathableClassLoader webappLoader = new PathableClassLoader(containerLoader);
|
||||
webappLoader.setParentFirst(true);
|
||||
webappLoader.addLogicalLib("testclasses");
|
||||
|
||||
URL noPriorityURL = new URL(baseUrl, "nopriority/");
|
||||
final URL noPriorityURL = new URL(baseUrl, "nopriority/");
|
||||
webappLoader.addURL(noPriorityURL);
|
||||
|
||||
URL pri20URL = new URL(baseUrl, "priority20/");
|
||||
final URL pri20URL = new URL(baseUrl, "priority20/");
|
||||
webappLoader.addURL(pri20URL);
|
||||
|
||||
URL pri20aURL = new URL(baseUrl, "priority20a/");
|
||||
final URL pri20aURL = new URL(baseUrl, "priority20a/");
|
||||
webappLoader.addURL(pri20aURL);
|
||||
|
||||
// load the test class via webapp loader, and use the webapp loader
|
||||
// as the tccl loader too.
|
||||
Class testClass = webappLoader.loadClass(thisClass.getName());
|
||||
final Class testClass = webappLoader.loadClass(thisClass.getName());
|
||||
return new PathableTestSuite(testClass, webappLoader);
|
||||
}
|
||||
|
||||
@@ -123,8 +123,8 @@ public class PriorityConfigTestCase extends TestCase {
|
||||
* the desired configId value.
|
||||
*/
|
||||
public void testPriority() throws Exception {
|
||||
LogFactory instance = LogFactory.getFactory();
|
||||
String id = (String) instance.getAttribute("configId");
|
||||
final LogFactory instance = LogFactory.getFactory();
|
||||
final String id = (String) instance.getAttribute("configId");
|
||||
assertEquals("Correct config file loaded", "priority20", id );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
private Long valueTwo;
|
||||
private Long valueThree;
|
||||
|
||||
public WeakHashtableTestCase(String testName) {
|
||||
public WeakHashtableTestCase(final String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
@@ -105,8 +105,8 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
|
||||
/** Tests public Enumeration elements() */
|
||||
public void testElements() throws Exception {
|
||||
ArrayList elements = new ArrayList();
|
||||
for (Enumeration e = weakHashtable.elements(); e.hasMoreElements();) {
|
||||
final ArrayList elements = new ArrayList();
|
||||
for (final Enumeration e = weakHashtable.elements(); e.hasMoreElements();) {
|
||||
elements.add(e.nextElement());
|
||||
}
|
||||
assertEquals(3, elements.size());
|
||||
@@ -117,10 +117,10 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
|
||||
/** Tests public Set entrySet() */
|
||||
public void testEntrySet() throws Exception {
|
||||
Set entrySet = weakHashtable.entrySet();
|
||||
for (Iterator it = entrySet.iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
Object key = entry.getKey();
|
||||
final Set entrySet = weakHashtable.entrySet();
|
||||
for (final Iterator it = entrySet.iterator(); it.hasNext();) {
|
||||
final Map.Entry entry = (Map.Entry) it.next();
|
||||
final Object key = entry.getKey();
|
||||
if (keyOne.equals(key)) {
|
||||
assertEquals(valueOne, entry.getValue());
|
||||
} else if (keyTwo.equals(key)) {
|
||||
@@ -143,8 +143,8 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
|
||||
/** Tests public Enumeration keys() */
|
||||
public void testKeys() throws Exception {
|
||||
ArrayList keys = new ArrayList();
|
||||
for (Enumeration e = weakHashtable.keys(); e.hasMoreElements();) {
|
||||
final ArrayList keys = new ArrayList();
|
||||
for (final Enumeration e = weakHashtable.keys(); e.hasMoreElements();) {
|
||||
keys.add(e.nextElement());
|
||||
}
|
||||
assertEquals(3, keys.size());
|
||||
@@ -155,7 +155,7 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
|
||||
/** Tests public Set keySet() */
|
||||
public void testKeySet() throws Exception {
|
||||
Set keySet = weakHashtable.keySet();
|
||||
final Set keySet = weakHashtable.keySet();
|
||||
assertEquals(3, keySet.size());
|
||||
assertTrue(keySet.contains(keyOne));
|
||||
assertTrue(keySet.contains(keyTwo));
|
||||
@@ -164,7 +164,7 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
|
||||
/** Tests public Object put(Object key, Object value) */
|
||||
public void testPut() throws Exception {
|
||||
Long anotherKey = new Long(2004);
|
||||
final Long anotherKey = new Long(2004);
|
||||
weakHashtable.put(anotherKey, new Long(1066));
|
||||
|
||||
assertEquals(new Long(1066), weakHashtable.get(anotherKey));
|
||||
@@ -174,7 +174,7 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
try {
|
||||
weakHashtable.put(null, new Object());
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (final Exception e) {
|
||||
caught = e;
|
||||
}
|
||||
assertNotNull("did not throw an exception adding a null key", caught);
|
||||
@@ -182,7 +182,7 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
try {
|
||||
weakHashtable.put(new Object(), null);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (final Exception e) {
|
||||
caught = e;
|
||||
}
|
||||
assertNotNull("did not throw an exception adding a null value", caught);
|
||||
@@ -190,12 +190,12 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
|
||||
/** Tests public void putAll(Map t) */
|
||||
public void testPutAll() throws Exception {
|
||||
Map newValues = new HashMap();
|
||||
Long newKey = new Long(1066);
|
||||
Long newValue = new Long(1415);
|
||||
final Map newValues = new HashMap();
|
||||
final Long newKey = new Long(1066);
|
||||
final Long newValue = new Long(1415);
|
||||
newValues.put(newKey, newValue);
|
||||
Long anotherNewKey = new Long(1645);
|
||||
Long anotherNewValue = new Long(1815);
|
||||
final Long anotherNewKey = new Long(1645);
|
||||
final Long anotherNewValue = new Long(1815);
|
||||
newValues.put(anotherNewKey, anotherNewValue);
|
||||
weakHashtable.putAll(newValues);
|
||||
|
||||
@@ -213,7 +213,7 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
|
||||
/** Tests public Collection values() */
|
||||
public void testValues() throws Exception {
|
||||
Collection values = weakHashtable.values();
|
||||
final Collection values = weakHashtable.values();
|
||||
assertEquals(3, values.size());
|
||||
assertTrue(values.contains(valueOne));
|
||||
assertTrue(values.contains(valueTwo));
|
||||
@@ -229,8 +229,8 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
*/
|
||||
public void xxxIgnoretestRelease() throws Exception {
|
||||
assertNotNull(weakHashtable.get(new Long(1)));
|
||||
ReferenceQueue testQueue = new ReferenceQueue();
|
||||
WeakReference weakKeyOne = new WeakReference(keyOne, testQueue);
|
||||
final ReferenceQueue testQueue = new ReferenceQueue();
|
||||
final WeakReference weakKeyOne = new WeakReference(keyOne, testQueue);
|
||||
|
||||
// lose our references
|
||||
keyOne = null;
|
||||
@@ -253,7 +253,7 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
|
||||
} else {
|
||||
// create garbage:
|
||||
byte[] b = new byte[bytz];
|
||||
final byte[] b = new byte[bytz];
|
||||
bytz = bytz * 2;
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
|
||||
public static class StupidThread extends Thread {
|
||||
|
||||
public StupidThread(String name) {
|
||||
public StupidThread(final String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ public class WeakHashtableTestCase extends TestCase {
|
||||
}
|
||||
|
||||
public void testLOGGING_119() throws Exception {
|
||||
Thread [] t = new Thread[THREAD_COUNT];
|
||||
final Thread [] t = new Thread[THREAD_COUNT];
|
||||
for (int j=1; j <= OUTER_LOOP; j++) {
|
||||
hashtable = new WeakHashtable();
|
||||
for (int i = 0; i < t.length; i++) {
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.apache.commons.logging.PathableTestSuite;
|
||||
|
||||
public class CustomConfigAPITestCase extends CustomConfigTestCase {
|
||||
|
||||
public CustomConfigAPITestCase(String name) {
|
||||
public CustomConfigAPITestCase(final String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class CustomConfigAPITestCase extends CustomConfigTestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
PathableClassLoader parent = new PathableClassLoader(null);
|
||||
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
|
||||
// the TestHandler class must be accessable from the System classloader
|
||||
@@ -46,16 +46,16 @@ public class CustomConfigAPITestCase extends CustomConfigTestCase {
|
||||
// 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
|
||||
// but the whole jdk14 API is a ******* mess anyway.
|
||||
ClassLoader scl = ClassLoader.getSystemClassLoader();
|
||||
final ClassLoader scl = ClassLoader.getSystemClassLoader();
|
||||
loadTestHandler(HANDLER_NAME, scl);
|
||||
parent.useExplicitLoader(HANDLER_NAME, scl);
|
||||
parent.addLogicalLib("commons-logging-api");
|
||||
|
||||
PathableClassLoader child = new PathableClassLoader(parent);
|
||||
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||
child.addLogicalLib("testclasses");
|
||||
child.addLogicalLib("commons-logging");
|
||||
|
||||
Class testClass = child.loadClass(CustomConfigAPITestCase.class.getName());
|
||||
final Class testClass = child.loadClass(CustomConfigAPITestCase.class.getName());
|
||||
return new PathableTestSuite(testClass, child);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.apache.commons.logging.PathableClassLoader;
|
||||
public class CustomConfigFullTestCase extends CustomConfigTestCase {
|
||||
|
||||
|
||||
public CustomConfigFullTestCase(String name) {
|
||||
public CustomConfigFullTestCase(final String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class CustomConfigFullTestCase extends CustomConfigTestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
PathableClassLoader parent = new PathableClassLoader(null);
|
||||
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
|
||||
// the TestHandler class must be accessable from the System classloader
|
||||
@@ -49,15 +49,15 @@ public class CustomConfigFullTestCase extends CustomConfigTestCase {
|
||||
// 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
|
||||
// but the whole jdk14 API is a ******* mess anyway.
|
||||
ClassLoader scl = ClassLoader.getSystemClassLoader();
|
||||
final ClassLoader scl = ClassLoader.getSystemClassLoader();
|
||||
loadTestHandler(HANDLER_NAME, scl);
|
||||
parent.useExplicitLoader(HANDLER_NAME, scl);
|
||||
parent.addLogicalLib("commons-logging");
|
||||
|
||||
PathableClassLoader child = new PathableClassLoader(parent);
|
||||
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||
child.addLogicalLib("testclasses");
|
||||
|
||||
Class testClass = child.loadClass(CustomConfigFullTestCase.class.getName());
|
||||
final Class testClass = child.loadClass(CustomConfigFullTestCase.class.getName());
|
||||
return new PathableTestSuite(testClass, child);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
*
|
||||
* @param name Name of the test case
|
||||
*/
|
||||
public CustomConfigTestCase(String name) {
|
||||
public CustomConfigTestCase(final String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@@ -109,15 +109,15 @@ 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.
|
||||
*/
|
||||
protected static byte[] readClass(String name, ClassLoader srcCL) throws Exception {
|
||||
String resName = name.replace('.', '/') + ".class";
|
||||
protected static byte[] readClass(final String name, final ClassLoader srcCL) throws Exception {
|
||||
final String resName = name.replace('.', '/') + ".class";
|
||||
System.err.println("Trying to load resource [" + resName + "]");
|
||||
InputStream is = srcCL.getResourceAsStream(resName);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final InputStream is = srcCL.getResourceAsStream(resName);
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
System.err.println("Reading resource [" + resName + "]");
|
||||
byte[] buf = new byte[1000];
|
||||
final byte[] buf = new byte[1000];
|
||||
for(;;) {
|
||||
int read = is.read(buf);
|
||||
final int read = is.read(buf);
|
||||
if (read <= 0) {
|
||||
break;
|
||||
}
|
||||
@@ -133,30 +133,30 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
* works for classes for which all dependencies are already loaded in
|
||||
* that classloader.
|
||||
*/
|
||||
protected static void loadTestHandler(String className, ClassLoader targetCL) {
|
||||
protected static void loadTestHandler(final String className, final ClassLoader targetCL) {
|
||||
try {
|
||||
targetCL.loadClass(className);
|
||||
// fail("Class already in target classloader");
|
||||
return;
|
||||
} catch(ClassNotFoundException ex) {
|
||||
} catch(final ClassNotFoundException ex) {
|
||||
// ok, go ahead and load it
|
||||
}
|
||||
|
||||
try {
|
||||
ClassLoader srcCL = CustomConfigAPITestCase.class.getClassLoader();
|
||||
byte[] classData = readClass(className, srcCL);
|
||||
final ClassLoader srcCL = CustomConfigAPITestCase.class.getClassLoader();
|
||||
final byte[] classData = readClass(className, srcCL);
|
||||
|
||||
Class[] params = new Class[] { String.class, classData.getClass(), Integer.TYPE, Integer.TYPE };
|
||||
Method m = ClassLoader.class.getDeclaredMethod("defineClass", params);
|
||||
final Class[] params = new Class[] { String.class, classData.getClass(), Integer.TYPE, Integer.TYPE };
|
||||
final Method m = ClassLoader.class.getDeclaredMethod("defineClass", params);
|
||||
|
||||
Object[] args = new Object[4];
|
||||
final Object[] args = new Object[4];
|
||||
args[0] = className;
|
||||
args[1] = classData;
|
||||
args[2] = new Integer(0);
|
||||
args[3] = new Integer(classData.length);
|
||||
m.setAccessible(true);
|
||||
m.invoke(targetCL, args);
|
||||
} catch(Exception e) {
|
||||
} catch(final Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Unable to load class " + className);
|
||||
}
|
||||
@@ -179,7 +179,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
PathableClassLoader cl = new PathableClassLoader(null);
|
||||
final PathableClassLoader cl = new PathableClassLoader(null);
|
||||
cl.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
|
||||
// the TestHandler class must be accessable from the System classloader
|
||||
@@ -187,13 +187,13 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
// 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
|
||||
// but the whole jdk14 API is a ******* mess anyway.
|
||||
ClassLoader scl = ClassLoader.getSystemClassLoader();
|
||||
final ClassLoader scl = ClassLoader.getSystemClassLoader();
|
||||
loadTestHandler(HANDLER_NAME, scl);
|
||||
cl.useExplicitLoader(HANDLER_NAME, scl);
|
||||
cl.addLogicalLib("commons-logging");
|
||||
cl.addLogicalLib("testclasses");
|
||||
|
||||
Class testClass = cl.loadClass(CustomConfigTestCase.class.getName());
|
||||
final Class testClass = cl.loadClass(CustomConfigTestCase.class.getName());
|
||||
return new PathableTestSuite(testClass, cl);
|
||||
}
|
||||
|
||||
@@ -290,11 +290,11 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
|
||||
|
||||
// Check the recorded messages
|
||||
protected void checkLogRecords(boolean thrown) {
|
||||
Iterator records = handler.records();
|
||||
protected void checkLogRecords(final boolean thrown) {
|
||||
final Iterator records = handler.records();
|
||||
for (int i = 0; i < testMessages.length; i++) {
|
||||
assertTrue(records.hasNext());
|
||||
LogRecord record = (LogRecord) records.next();
|
||||
final LogRecord record = (LogRecord) records.next();
|
||||
assertEquals("LogRecord level",
|
||||
testLevels[i], record.getLevel());
|
||||
assertEquals("LogRecord message",
|
||||
@@ -327,7 +327,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
|
||||
// Log the messages with exceptions
|
||||
protected void logExceptionMessages() {
|
||||
Throwable t = new DummyException();
|
||||
final Throwable t = new DummyException();
|
||||
log.trace("trace", t); // Should not actually get logged
|
||||
log.debug("debug", t);
|
||||
log.info("info", t);
|
||||
@@ -377,15 +377,15 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
|
||||
|
||||
// Set up logger instance
|
||||
protected void setUpLogger(String name) throws Exception {
|
||||
protected void setUpLogger(final String name) throws Exception {
|
||||
logger = Logger.getLogger(name);
|
||||
}
|
||||
|
||||
|
||||
// Set up LogManager instance
|
||||
protected void setUpManager(String config) throws Exception {
|
||||
protected void setUpManager(final String config) throws Exception {
|
||||
manager = LogManager.getLogManager();
|
||||
InputStream is =
|
||||
final InputStream is =
|
||||
this.getClass().getClassLoader().getResourceAsStream(config);
|
||||
manager.readConfiguration(is);
|
||||
is.close();
|
||||
|
||||
@@ -52,7 +52,7 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
*
|
||||
* @param name Name of the test case
|
||||
*/
|
||||
public DefaultConfigTestCase(String name) {
|
||||
public DefaultConfigTestCase(final String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@@ -88,12 +88,12 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
PathableClassLoader loader = new PathableClassLoader(null);
|
||||
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
loader.addLogicalLib("testclasses");
|
||||
loader.addLogicalLib("commons-logging");
|
||||
|
||||
Class testClass = loader.loadClass(DefaultConfigTestCase.class.getName());
|
||||
final Class testClass = loader.loadClass(DefaultConfigTestCase.class.getName());
|
||||
return new PathableTestSuite(testClass, loader);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||
factory.getClass().getName());
|
||||
|
||||
String names[] = factory.getAttributeNames();
|
||||
final String names[] = factory.getAttributeNames();
|
||||
assertNotNull("Names exists", names);
|
||||
assertEquals("Names empty", 0, names.length);
|
||||
|
||||
@@ -137,13 +137,13 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
public void testSerializable() throws Exception {
|
||||
|
||||
// Serialize and deserialize the instance
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(log);
|
||||
oos.close();
|
||||
ByteArrayInputStream bais =
|
||||
final ByteArrayInputStream bais =
|
||||
new ByteArrayInputStream(baos.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
final ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
log = (Log) ois.readObject();
|
||||
ois.close();
|
||||
|
||||
@@ -183,7 +183,7 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
|
||||
|
||||
// Set up log instance
|
||||
protected void setUpLog(String name) throws Exception {
|
||||
protected void setUpLog(final String name) throws Exception {
|
||||
log = LogFactory.getLog(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public class TestHandler extends Handler {
|
||||
}
|
||||
|
||||
|
||||
public void publish(LogRecord record) {
|
||||
public void publish(final LogRecord record) {
|
||||
records.add(record);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,13 +88,13 @@ public abstract class StandardTests extends TestCase {
|
||||
* Test that a LogFactory gets created as expected.
|
||||
*/
|
||||
public void testCreateFactory() {
|
||||
LogFactory factory = LogFactory.getFactory();
|
||||
final LogFactory factory = LogFactory.getFactory();
|
||||
assertNotNull("LogFactory exists", factory);
|
||||
assertEquals("LogFactory class",
|
||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||
factory.getClass().getName());
|
||||
|
||||
String names[] = factory.getAttributeNames();
|
||||
final String names[] = factory.getAttributeNames();
|
||||
assertNotNull("Names exists", names);
|
||||
assertEquals("Names empty", 0, names.length);
|
||||
}
|
||||
@@ -103,9 +103,9 @@ public abstract class StandardTests extends TestCase {
|
||||
* Verify that we can log messages without exceptions.
|
||||
*/
|
||||
public void testPlainMessages() throws Exception {
|
||||
List logEvents = new ArrayList();
|
||||
final List logEvents = new ArrayList();
|
||||
setUpTestAppender(logEvents);
|
||||
Log log = LogFactory.getLog("test-category");
|
||||
final Log log = LogFactory.getLog("test-category");
|
||||
logPlainMessages(log);
|
||||
checkLoggingEvents(logEvents, false);
|
||||
}
|
||||
@@ -114,9 +114,9 @@ public abstract class StandardTests extends TestCase {
|
||||
* Verify that we can log exception messages.
|
||||
*/
|
||||
public void testExceptionMessages() throws Exception {
|
||||
List logEvents = new ArrayList();
|
||||
final List logEvents = new ArrayList();
|
||||
setUpTestAppender(logEvents);
|
||||
Log log = LogFactory.getLog("test-category");
|
||||
final Log log = LogFactory.getLog("test-category");
|
||||
logExceptionMessages(log);
|
||||
checkLoggingEvents(logEvents, true);
|
||||
}
|
||||
@@ -125,18 +125,18 @@ public abstract class StandardTests extends TestCase {
|
||||
* Test Serializability of Log instance
|
||||
*/
|
||||
public void testSerializable() throws Exception {
|
||||
List logEvents = new ArrayList();
|
||||
final List logEvents = new ArrayList();
|
||||
setUpTestAppender(logEvents);
|
||||
Log log = LogFactory.getLog("test-category");
|
||||
final Log log = LogFactory.getLog("test-category");
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(log);
|
||||
oos.close();
|
||||
ByteArrayInputStream bais =
|
||||
final ByteArrayInputStream bais =
|
||||
new ByteArrayInputStream(baos.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
Log newLog = (Log) ois.readObject();
|
||||
final ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
final Log newLog = (Log) ois.readObject();
|
||||
ois.close();
|
||||
|
||||
// Check the characteristics of the resulting object
|
||||
@@ -162,7 +162,7 @@ public abstract class StandardTests extends TestCase {
|
||||
* logevents with no associated exception info). True if
|
||||
* logExceptionMessages was called.
|
||||
*/
|
||||
private void checkLoggingEvents(List logEvents, boolean thrown) {
|
||||
private void checkLoggingEvents(final List logEvents, final boolean thrown) {
|
||||
LogEvent ev;
|
||||
|
||||
assertEquals("Unexpected number of log events", 4, logEvents.size());
|
||||
@@ -192,7 +192,7 @@ public abstract class StandardTests extends TestCase {
|
||||
/**
|
||||
* Log plain messages.
|
||||
*/
|
||||
private void logPlainMessages(Log log) {
|
||||
private void logPlainMessages(final Log log) {
|
||||
log.trace("trace"); // Should not actually get logged
|
||||
log.debug("debug"); // Should not actually get logged
|
||||
log.info("info");
|
||||
@@ -204,8 +204,8 @@ public abstract class StandardTests extends TestCase {
|
||||
/**
|
||||
* Log messages with exceptions
|
||||
*/
|
||||
private void logExceptionMessages(Log log) {
|
||||
Throwable t = new DummyException();
|
||||
private void logExceptionMessages(final Log log) {
|
||||
final Throwable t = new DummyException();
|
||||
log.trace("trace", t); // Should not actually get logged
|
||||
log.debug("debug", t); // Should not actually get logged
|
||||
log.info("info", t);
|
||||
|
||||
@@ -36,16 +36,16 @@ public class ApiClasspathStandardTestCase extends TestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
PathableClassLoader parent = new PathableClassLoader(null);
|
||||
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
parent.addLogicalLib("commons-logging-api");
|
||||
|
||||
PathableClassLoader child = new PathableClassLoader(parent);
|
||||
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||
child.addLogicalLib("log4j12");
|
||||
child.addLogicalLib("commons-logging");
|
||||
child.addLogicalLib("testclasses");
|
||||
|
||||
Class testClass = child.loadClass(
|
||||
final Class testClass = child.loadClass(
|
||||
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
|
||||
return new PathableTestSuite(testClass, child);
|
||||
}
|
||||
|
||||
@@ -34,13 +34,13 @@ public class AppClasspathStandardTestCase extends TestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
PathableClassLoader loader = new PathableClassLoader(null);
|
||||
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
loader.addLogicalLib("testclasses");
|
||||
loader.addLogicalLib("log4j12");
|
||||
loader.addLogicalLib("commons-logging");
|
||||
|
||||
Class testClass = loader.loadClass(
|
||||
final Class testClass = loader.loadClass(
|
||||
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
|
||||
return new PathableTestSuite(testClass, loader);
|
||||
}
|
||||
|
||||
@@ -35,15 +35,15 @@ public class ChildClasspathStandardTestCase extends TestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
PathableClassLoader parent = new PathableClassLoader(null);
|
||||
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
|
||||
PathableClassLoader child = new PathableClassLoader(parent);
|
||||
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||
child.addLogicalLib("testclasses");
|
||||
child.addLogicalLib("log4j12");
|
||||
child.addLogicalLib("commons-logging");
|
||||
|
||||
Class testClass = child.loadClass(
|
||||
final Class testClass = child.loadClass(
|
||||
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
|
||||
return new PathableTestSuite(testClass, child);
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ import org.apache.log4j.Logger;
|
||||
|
||||
public class Log4j12StandardTests extends StandardTests {
|
||||
|
||||
public void setUpTestAppender(List logEvents) {
|
||||
TestAppender appender = new TestAppender(logEvents);
|
||||
Logger rootLogger = Logger.getRootLogger();
|
||||
public void setUpTestAppender(final List logEvents) {
|
||||
final TestAppender appender = new TestAppender(logEvents);
|
||||
final Logger rootLogger = Logger.getRootLogger();
|
||||
rootLogger.removeAllAppenders();
|
||||
rootLogger.addAppender(appender);
|
||||
rootLogger.setLevel(Level.INFO);
|
||||
|
||||
@@ -34,15 +34,15 @@ public class ParentClasspathStandardTestCase extends TestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
PathableClassLoader parent = new PathableClassLoader(null);
|
||||
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
parent.addLogicalLib("commons-logging");
|
||||
parent.addLogicalLib("log4j12");
|
||||
|
||||
PathableClassLoader child = new PathableClassLoader(parent);
|
||||
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||
child.addLogicalLib("testclasses");
|
||||
|
||||
Class testClass = child.loadClass(
|
||||
final Class testClass = child.loadClass(
|
||||
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
|
||||
return new PathableTestSuite(testClass, child);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class TestAppender extends AppenderSkeleton {
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public TestAppender(List logEvents) {
|
||||
public TestAppender(final List logEvents) {
|
||||
events = logEvents;
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ public class TestAppender extends AppenderSkeleton {
|
||||
|
||||
// ------------------------------------------------------- Appender Methods
|
||||
|
||||
protected void append(LoggingEvent event) {
|
||||
StandardTests.LogEvent lev = new StandardTests.LogEvent();
|
||||
protected void append(final LoggingEvent event) {
|
||||
final StandardTests.LogEvent lev = new StandardTests.LogEvent();
|
||||
|
||||
lev.level = event.getLevel().toString();
|
||||
|
||||
|
||||
@@ -61,15 +61,15 @@ public class StandardTestCase extends AbstractLogTest {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = StandardTestCase.class;
|
||||
final Class thisClass = StandardTestCase.class;
|
||||
|
||||
PathableClassLoader loader = new PathableClassLoader(null);
|
||||
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
loader.addLogicalLib("testclasses");
|
||||
loader.addLogicalLib("commons-logging");
|
||||
loader.addLogicalLib("logkit");
|
||||
|
||||
Class testClass = loader.loadClass(thisClass.getName());
|
||||
final Class testClass = loader.loadClass(thisClass.getName());
|
||||
return new PathableTestSuite(testClass, loader);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class StandardTestCase extends AbstractLogTest {
|
||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||
factory.getClass().getName());
|
||||
|
||||
String names[] = factory.getAttributeNames();
|
||||
final String names[] = factory.getAttributeNames();
|
||||
assertNotNull("Names exists", names);
|
||||
assertEquals("Names empty", 0, names.length);
|
||||
}
|
||||
@@ -130,13 +130,13 @@ public class StandardTestCase extends AbstractLogTest {
|
||||
checkStandard();
|
||||
|
||||
// Serialize and deserialize the instance
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(log);
|
||||
oos.close();
|
||||
ByteArrayInputStream bais =
|
||||
final ByteArrayInputStream bais =
|
||||
new ByteArrayInputStream(baos.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
final ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
log = (Log) ois.readObject();
|
||||
ois.close();
|
||||
|
||||
|
||||
@@ -68,13 +68,13 @@ public class NoOpLogTestCase extends AbstractLogTest
|
||||
checkLog(log);
|
||||
|
||||
// Serialize and deserialize the instance
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(log);
|
||||
oos.close();
|
||||
ByteArrayInputStream bais =
|
||||
final ByteArrayInputStream bais =
|
||||
new ByteArrayInputStream(baos.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
final ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
log = (Log) ois.readObject();
|
||||
ois.close();
|
||||
|
||||
@@ -84,7 +84,7 @@ public class NoOpLogTestCase extends AbstractLogTest
|
||||
|
||||
// -------------------------------------------------------- Support Methods
|
||||
|
||||
private void checkLog(Log log) {
|
||||
private void checkLog(final Log log) {
|
||||
|
||||
assertNotNull("Log exists", log);
|
||||
assertEquals("Log class",
|
||||
|
||||
@@ -52,12 +52,12 @@ public class ChildFirstTestCase extends TestCase {
|
||||
* </ul>
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = ChildFirstTestCase.class;
|
||||
ClassLoader thisClassLoader = thisClass.getClassLoader();
|
||||
final Class thisClass = ChildFirstTestCase.class;
|
||||
final ClassLoader thisClassLoader = thisClass.getClassLoader();
|
||||
|
||||
// Make the parent a direct child of the bootloader to hide all
|
||||
// other classes in the system classpath
|
||||
PathableClassLoader parent = new PathableClassLoader(null);
|
||||
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||
parent.setParentFirst(false);
|
||||
|
||||
// Make the junit classes visible as a special case, as junit
|
||||
@@ -71,7 +71,7 @@ public class ChildFirstTestCase extends TestCase {
|
||||
parent.addLogicalLib("commons-logging");
|
||||
|
||||
// Create a child classloader to load the test case through
|
||||
PathableClassLoader child = new PathableClassLoader(parent);
|
||||
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||
child.setParentFirst(false);
|
||||
|
||||
// Obviously, the child classloader needs to have the test classes
|
||||
@@ -80,11 +80,11 @@ public class ChildFirstTestCase extends TestCase {
|
||||
child.addLogicalLib("commons-logging-adapters");
|
||||
|
||||
// Create a third classloader to be the context classloader.
|
||||
PathableClassLoader context = new PathableClassLoader(child);
|
||||
final PathableClassLoader context = new PathableClassLoader(child);
|
||||
context.setParentFirst(false);
|
||||
|
||||
// reload this class via the child classloader
|
||||
Class testClass = child.loadClass(thisClass.getName());
|
||||
final Class testClass = child.loadClass(thisClass.getName());
|
||||
|
||||
// and return our custom TestSuite class
|
||||
return new PathableTestSuite(testClass, context);
|
||||
@@ -96,7 +96,7 @@ public class ChildFirstTestCase extends TestCase {
|
||||
* this object instance.
|
||||
*/
|
||||
private Set getAncestorCLs() {
|
||||
Set s = new HashSet();
|
||||
final Set s = new HashSet();
|
||||
ClassLoader cl = this.getClass().getClassLoader();
|
||||
while (cl != null) {
|
||||
s.add(cl);
|
||||
@@ -113,14 +113,14 @@ public class ChildFirstTestCase extends TestCase {
|
||||
*/
|
||||
public void testPaths() throws Exception {
|
||||
// the context classloader is not expected to be null
|
||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
assertNotNull("Context classloader is null", contextLoader);
|
||||
assertEquals("Context classloader has unexpected type",
|
||||
PathableClassLoader.class.getName(),
|
||||
contextLoader.getClass().getName());
|
||||
|
||||
// the classloader that loaded this class is obviously not null
|
||||
ClassLoader thisLoader = this.getClass().getClassLoader();
|
||||
final ClassLoader thisLoader = this.getClass().getClassLoader();
|
||||
assertNotNull("thisLoader is null", thisLoader);
|
||||
assertEquals("thisLoader has unexpected type",
|
||||
PathableClassLoader.class.getName(),
|
||||
@@ -132,7 +132,7 @@ public class ChildFirstTestCase extends TestCase {
|
||||
thisLoader, contextLoader.getParent());
|
||||
|
||||
// thisLoader's parent should be available
|
||||
ClassLoader parentLoader = thisLoader.getParent();
|
||||
final ClassLoader parentLoader = thisLoader.getParent();
|
||||
assertNotNull("Parent classloader is null", parentLoader);
|
||||
assertEquals("Parent classloader has unexpected type",
|
||||
PathableClassLoader.class.getName(),
|
||||
@@ -144,7 +144,7 @@ public class ChildFirstTestCase extends TestCase {
|
||||
// getSystemClassloader is not a PathableClassLoader; it's of a
|
||||
// built-in type. This also verifies that system classloader is none of
|
||||
// (context, child, parent).
|
||||
ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
|
||||
final ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
|
||||
assertNotNull("System classloader is null", systemLoader);
|
||||
assertFalse("System classloader has unexpected type",
|
||||
PathableClassLoader.class.getName().equals(
|
||||
@@ -153,38 +153,38 @@ public class ChildFirstTestCase extends TestCase {
|
||||
// junit classes should be visible; their classloader is not
|
||||
// in the hierarchy of parent classloaders for this class,
|
||||
// though it is accessable due to trickery in the PathableClassLoader.
|
||||
Class junitTest = contextLoader.loadClass("junit.framework.Test");
|
||||
Set ancestorCLs = getAncestorCLs();
|
||||
final Class junitTest = contextLoader.loadClass("junit.framework.Test");
|
||||
final Set ancestorCLs = getAncestorCLs();
|
||||
assertFalse("Junit not loaded by ancestor classloader",
|
||||
ancestorCLs.contains(junitTest.getClassLoader()));
|
||||
|
||||
// jcl api classes should be visible only via the parent
|
||||
Class logClass = contextLoader.loadClass("org.apache.commons.logging.Log");
|
||||
final Class logClass = contextLoader.loadClass("org.apache.commons.logging.Log");
|
||||
assertSame("Log class not loaded via parent",
|
||||
logClass.getClassLoader(), parentLoader);
|
||||
|
||||
// jcl adapter classes should be visible via both parent and child. However
|
||||
// as the classloaders are child-first we should see the child one.
|
||||
Class log4jClass = contextLoader.loadClass("org.apache.commons.logging.impl.Log4JLogger");
|
||||
final Class log4jClass = contextLoader.loadClass("org.apache.commons.logging.impl.Log4JLogger");
|
||||
assertSame("Log4JLogger not loaded via child",
|
||||
log4jClass.getClassLoader(), thisLoader);
|
||||
|
||||
// test classes should be visible via the child only
|
||||
Class testClass = contextLoader.loadClass("org.apache.commons.logging.PathableTestSuite");
|
||||
final Class testClass = contextLoader.loadClass("org.apache.commons.logging.PathableTestSuite");
|
||||
assertSame("PathableTestSuite not loaded via child",
|
||||
testClass.getClassLoader(), thisLoader);
|
||||
|
||||
// test loading of class that is not available
|
||||
try {
|
||||
Class noSuchClass = contextLoader.loadClass("no.such.class");
|
||||
final Class noSuchClass = contextLoader.loadClass("no.such.class");
|
||||
fail("Class no.such.class is unexpectedly available");
|
||||
assertNotNull(noSuchClass); // silence warning about unused var
|
||||
} catch(ClassNotFoundException ex) {
|
||||
} catch(final ClassNotFoundException ex) {
|
||||
// ok
|
||||
}
|
||||
|
||||
// String class classloader is null
|
||||
Class stringClass = contextLoader.loadClass("java.lang.String");
|
||||
final Class stringClass = contextLoader.loadClass("java.lang.String");
|
||||
assertNull("String class classloader is not null!",
|
||||
stringClass.getClassLoader());
|
||||
}
|
||||
@@ -195,8 +195,8 @@ public class ChildFirstTestCase extends TestCase {
|
||||
public void testResource() {
|
||||
URL resource;
|
||||
|
||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
ClassLoader childLoader = contextLoader.getParent();
|
||||
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader childLoader = contextLoader.getParent();
|
||||
|
||||
// getResource where it doesn't exist
|
||||
resource = childLoader.getResource("nosuchfile");
|
||||
@@ -228,10 +228,10 @@ public class ChildFirstTestCase extends TestCase {
|
||||
URL[] urls;
|
||||
|
||||
// verify the classloader hierarchy
|
||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
ClassLoader childLoader = contextLoader.getParent();
|
||||
ClassLoader parentLoader = childLoader.getParent();
|
||||
ClassLoader bootLoader = parentLoader.getParent();
|
||||
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);
|
||||
|
||||
// getResources where no instances exist
|
||||
@@ -264,7 +264,7 @@ public class ChildFirstTestCase extends TestCase {
|
||||
|
||||
// There is no guarantee about the ordering of results returned from getResources
|
||||
// To make this test portable across JVMs, sort the string to give them a known order
|
||||
String[] urlsToStrings = new String[2];
|
||||
final String[] urlsToStrings = new String[2];
|
||||
urlsToStrings[0] = urls[0].toString();
|
||||
urlsToStrings[1] = urls[1].toString();
|
||||
Arrays.sort(urlsToStrings);
|
||||
@@ -277,13 +277,13 @@ public class ChildFirstTestCase extends TestCase {
|
||||
/**
|
||||
* Utility method to convert an enumeration-of-URLs into an array of URLs.
|
||||
*/
|
||||
private static URL[] toURLArray(Enumeration e) {
|
||||
ArrayList l = new ArrayList();
|
||||
private static URL[] toURLArray(final Enumeration e) {
|
||||
final ArrayList l = new ArrayList();
|
||||
while (e.hasMoreElements()) {
|
||||
URL u = (URL) e.nextElement();
|
||||
final URL u = (URL) e.nextElement();
|
||||
l.add(u);
|
||||
}
|
||||
URL[] tmp = new URL[l.size()];
|
||||
final URL[] tmp = new URL[l.size()];
|
||||
return (URL[]) l.toArray(tmp);
|
||||
}
|
||||
|
||||
@@ -294,10 +294,10 @@ public class ChildFirstTestCase extends TestCase {
|
||||
java.io.InputStream is;
|
||||
|
||||
// verify the classloader hierarchy
|
||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
ClassLoader childLoader = contextLoader.getParent();
|
||||
ClassLoader parentLoader = childLoader.getParent();
|
||||
ClassLoader bootLoader = parentLoader.getParent();
|
||||
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);
|
||||
|
||||
// getResourceAsStream where no instances exist
|
||||
|
||||
@@ -35,15 +35,15 @@ public class GeneralTestCase extends TestCase {
|
||||
* Set up a custom classloader hierarchy for this test case.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = GeneralTestCase.class;
|
||||
ClassLoader thisClassLoader = thisClass.getClassLoader();
|
||||
final Class thisClass = GeneralTestCase.class;
|
||||
final ClassLoader thisClassLoader = thisClass.getClassLoader();
|
||||
|
||||
PathableClassLoader loader = new PathableClassLoader(null);
|
||||
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||
loader.useExplicitLoader("junit.", thisClassLoader);
|
||||
loader.addLogicalLib("testclasses");
|
||||
|
||||
// reload this class via the child classloader
|
||||
Class testClass = loader.loadClass(thisClass.getName());
|
||||
final Class testClass = loader.loadClass(thisClass.getName());
|
||||
|
||||
// and return our custom TestSuite class
|
||||
return new PathableTestSuite(testClass, loader);
|
||||
@@ -87,12 +87,12 @@ public class GeneralTestCase extends TestCase {
|
||||
* a non-custom one.
|
||||
*/
|
||||
private static void checkAndSetContext() {
|
||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
assertEquals("ContextLoader is of unexpected type",
|
||||
contextLoader.getClass().getName(),
|
||||
PathableClassLoader.class.getName());
|
||||
|
||||
URL[] noUrls = new URL[0];
|
||||
final URL[] noUrls = new URL[0];
|
||||
Thread.currentThread().setContextClassLoader(new URLClassLoader(noUrls));
|
||||
}
|
||||
|
||||
|
||||
@@ -52,12 +52,12 @@ public class ParentFirstTestCase extends TestCase {
|
||||
* </ul>
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = ParentFirstTestCase.class;
|
||||
ClassLoader thisClassLoader = thisClass.getClassLoader();
|
||||
final Class thisClass = ParentFirstTestCase.class;
|
||||
final ClassLoader thisClassLoader = thisClass.getClassLoader();
|
||||
|
||||
// Make the parent a direct child of the bootloader to hide all
|
||||
// other classes in the system classpath
|
||||
PathableClassLoader parent = new PathableClassLoader(null);
|
||||
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||
|
||||
// Make the junit classes visible as a special case, as junit
|
||||
// won't be able to call this class at all without this. The
|
||||
@@ -70,7 +70,7 @@ public class ParentFirstTestCase extends TestCase {
|
||||
parent.addLogicalLib("commons-logging");
|
||||
|
||||
// create a child classloader to load the test case through
|
||||
PathableClassLoader child = new PathableClassLoader(parent);
|
||||
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||
|
||||
// obviously, the child classloader needs to have the test classes
|
||||
// in its path!
|
||||
@@ -78,10 +78,10 @@ public class ParentFirstTestCase extends TestCase {
|
||||
child.addLogicalLib("commons-logging-adapters");
|
||||
|
||||
// create a third classloader to be the context classloader.
|
||||
PathableClassLoader context = new PathableClassLoader(child);
|
||||
final PathableClassLoader context = new PathableClassLoader(child);
|
||||
|
||||
// reload this class via the child classloader
|
||||
Class testClass = child.loadClass(thisClass.getName());
|
||||
final Class testClass = child.loadClass(thisClass.getName());
|
||||
|
||||
// and return our custom TestSuite class
|
||||
return new PathableTestSuite(testClass, context);
|
||||
@@ -93,7 +93,7 @@ public class ParentFirstTestCase extends TestCase {
|
||||
* this object instance.
|
||||
*/
|
||||
private Set getAncestorCLs() {
|
||||
Set s = new HashSet();
|
||||
final Set s = new HashSet();
|
||||
ClassLoader cl = this.getClass().getClassLoader();
|
||||
while (cl != null) {
|
||||
s.add(cl);
|
||||
@@ -110,14 +110,14 @@ public class ParentFirstTestCase extends TestCase {
|
||||
*/
|
||||
public void testPaths() throws Exception {
|
||||
// the context classloader is not expected to be null
|
||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
assertNotNull("Context classloader is null", contextLoader);
|
||||
assertEquals("Context classloader has unexpected type",
|
||||
PathableClassLoader.class.getName(),
|
||||
contextLoader.getClass().getName());
|
||||
|
||||
// the classloader that loaded this class is obviously not null
|
||||
ClassLoader thisLoader = this.getClass().getClassLoader();
|
||||
final ClassLoader thisLoader = this.getClass().getClassLoader();
|
||||
assertNotNull("thisLoader is null", thisLoader);
|
||||
assertEquals("thisLoader has unexpected type",
|
||||
PathableClassLoader.class.getName(),
|
||||
@@ -129,7 +129,7 @@ public class ParentFirstTestCase extends TestCase {
|
||||
thisLoader, contextLoader.getParent());
|
||||
|
||||
// thisLoader's parent should be available
|
||||
ClassLoader parentLoader = thisLoader.getParent();
|
||||
final ClassLoader parentLoader = thisLoader.getParent();
|
||||
assertNotNull("Parent classloader is null", parentLoader);
|
||||
assertEquals("Parent classloader has unexpected type",
|
||||
PathableClassLoader.class.getName(),
|
||||
@@ -141,7 +141,7 @@ public class ParentFirstTestCase extends TestCase {
|
||||
// getSystemClassloader is not a PathableClassLoader; it's of a
|
||||
// built-in type. This also verifies that system classloader is none of
|
||||
// (context, child, parent).
|
||||
ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
|
||||
final ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
|
||||
assertNotNull("System classloader is null", systemLoader);
|
||||
assertFalse("System classloader has unexpected type",
|
||||
PathableClassLoader.class.getName().equals(
|
||||
@@ -150,38 +150,38 @@ public class ParentFirstTestCase extends TestCase {
|
||||
// junit classes should be visible; their classloader is not
|
||||
// in the hierarchy of parent classloaders for this class,
|
||||
// though it is accessable due to trickery in the PathableClassLoader.
|
||||
Class junitTest = contextLoader.loadClass("junit.framework.Test");
|
||||
Set ancestorCLs = getAncestorCLs();
|
||||
final Class junitTest = contextLoader.loadClass("junit.framework.Test");
|
||||
final Set ancestorCLs = getAncestorCLs();
|
||||
assertFalse("Junit not loaded by ancestor classloader",
|
||||
ancestorCLs.contains(junitTest.getClassLoader()));
|
||||
|
||||
// jcl api classes should be visible only via the parent
|
||||
Class logClass = contextLoader.loadClass("org.apache.commons.logging.Log");
|
||||
final Class logClass = contextLoader.loadClass("org.apache.commons.logging.Log");
|
||||
assertSame("Log class not loaded via parent",
|
||||
logClass.getClassLoader(), parentLoader);
|
||||
|
||||
// jcl adapter classes should be visible via both parent and child. However
|
||||
// as the classloaders are parent-first we should see the parent one.
|
||||
Class log4jClass = contextLoader.loadClass("org.apache.commons.logging.impl.Log4JLogger");
|
||||
final Class log4jClass = contextLoader.loadClass("org.apache.commons.logging.impl.Log4JLogger");
|
||||
assertSame("Log4JLogger not loaded via parent",
|
||||
log4jClass.getClassLoader(), parentLoader);
|
||||
|
||||
// test classes should be visible via the child only
|
||||
Class testClass = contextLoader.loadClass("org.apache.commons.logging.PathableTestSuite");
|
||||
final Class testClass = contextLoader.loadClass("org.apache.commons.logging.PathableTestSuite");
|
||||
assertSame("PathableTestSuite not loaded via child",
|
||||
testClass.getClassLoader(), thisLoader);
|
||||
|
||||
// test loading of class that is not available
|
||||
try {
|
||||
Class noSuchClass = contextLoader.loadClass("no.such.class");
|
||||
final Class noSuchClass = contextLoader.loadClass("no.such.class");
|
||||
fail("Class no.such.class is unexpectedly available");
|
||||
assertNotNull(noSuchClass); // silence warning about unused var
|
||||
} catch(ClassNotFoundException ex) {
|
||||
} catch(final ClassNotFoundException ex) {
|
||||
// ok
|
||||
}
|
||||
|
||||
// String class classloader is null
|
||||
Class stringClass = contextLoader.loadClass("java.lang.String");
|
||||
final Class stringClass = contextLoader.loadClass("java.lang.String");
|
||||
assertNull("String class classloader is not null!",
|
||||
stringClass.getClassLoader());
|
||||
}
|
||||
@@ -192,8 +192,8 @@ public class ParentFirstTestCase extends TestCase {
|
||||
public void testResource() {
|
||||
URL resource;
|
||||
|
||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
ClassLoader childLoader = contextLoader.getParent();
|
||||
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader childLoader = contextLoader.getParent();
|
||||
|
||||
// getResource where it doesn't exist
|
||||
resource = childLoader.getResource("nosuchfile");
|
||||
@@ -225,10 +225,10 @@ public class ParentFirstTestCase extends TestCase {
|
||||
URL[] urls;
|
||||
|
||||
// verify the classloader hierarchy
|
||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
ClassLoader childLoader = contextLoader.getParent();
|
||||
ClassLoader parentLoader = childLoader.getParent();
|
||||
ClassLoader bootLoader = parentLoader.getParent();
|
||||
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);
|
||||
|
||||
// getResources where no instances exist
|
||||
@@ -254,7 +254,7 @@ public class ParentFirstTestCase extends TestCase {
|
||||
|
||||
// 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
|
||||
String[] urlsToStrings = new String[2];
|
||||
final String[] urlsToStrings = new String[2];
|
||||
urlsToStrings[0] = urls[0].toString();
|
||||
urlsToStrings[1] = urls[1].toString();
|
||||
Arrays.sort(urlsToStrings);
|
||||
@@ -268,13 +268,13 @@ public class ParentFirstTestCase extends TestCase {
|
||||
/**
|
||||
* Utility method to convert an enumeration-of-URLs into an array of URLs.
|
||||
*/
|
||||
private static URL[] toURLArray(Enumeration e) {
|
||||
ArrayList l = new ArrayList();
|
||||
private static URL[] toURLArray(final Enumeration e) {
|
||||
final ArrayList l = new ArrayList();
|
||||
while (e.hasMoreElements()) {
|
||||
URL u = (URL) e.nextElement();
|
||||
final URL u = (URL) e.nextElement();
|
||||
l.add(u);
|
||||
}
|
||||
URL[] tmp = new URL[l.size()];
|
||||
final URL[] tmp = new URL[l.size()];
|
||||
return (URL[]) l.toArray(tmp);
|
||||
}
|
||||
|
||||
@@ -285,10 +285,10 @@ public class ParentFirstTestCase extends TestCase {
|
||||
java.io.InputStream is;
|
||||
|
||||
// verify the classloader hierarchy
|
||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
ClassLoader childLoader = contextLoader.getParent();
|
||||
ClassLoader parentLoader = childLoader.getParent();
|
||||
ClassLoader bootLoader = parentLoader.getParent();
|
||||
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);
|
||||
|
||||
// getResourceAsStream where no instances exist
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
public class DummyClass {
|
||||
|
||||
public DummyClass() {
|
||||
Log log = LogFactory.getLog(DummyClass.class);
|
||||
final Log log = LogFactory.getLog(DummyClass.class);
|
||||
log.info("Some log message");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class MockSecurityManager extends SecurityManager {
|
||||
* Define the set of permissions to be granted to classes in the o.a.c.l package,
|
||||
* but NOT to unit-test classes in o.a.c.l.security package.
|
||||
*/
|
||||
public void addPermission(Permission p) {
|
||||
public void addPermission(final Permission p) {
|
||||
permissions.add(p);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class MockSecurityManager extends SecurityManager {
|
||||
return untrustedCodeCount;
|
||||
}
|
||||
|
||||
public void checkPermission(Permission p) throws SecurityException {
|
||||
public void checkPermission(final Permission p) throws SecurityException {
|
||||
if (setSecurityManagerPerm.implies(p)) {
|
||||
// ok, allow this; we don't want to block any calls to setSecurityManager
|
||||
// otherwise this custom security manager cannot be reset to the original.
|
||||
@@ -69,7 +69,7 @@ public class MockSecurityManager extends SecurityManager {
|
||||
// Allow read-only access to files, as this is needed to load classes!
|
||||
// Ideally, we would limit this to just .class and .jar files.
|
||||
if (p instanceof FilePermission) {
|
||||
FilePermission fp = (FilePermission) p;
|
||||
final FilePermission fp = (FilePermission) p;
|
||||
if (fp.getActions().equals("read")) {
|
||||
// System.out.println("Permit read of files");
|
||||
return;
|
||||
@@ -78,14 +78,14 @@ public class MockSecurityManager extends SecurityManager {
|
||||
|
||||
System.out.println("\n\ntesting permission:" + p.getClass() + ":"+ p);
|
||||
|
||||
Exception e = new Exception();
|
||||
final Exception e = new Exception();
|
||||
e.fillInStackTrace();
|
||||
StackTraceElement[] stack = e.getStackTrace();
|
||||
final StackTraceElement[] stack = e.getStackTrace();
|
||||
|
||||
// scan the call stack from most recent to oldest.
|
||||
// start at 1 to skip the entry in the stack for this method
|
||||
for(int i=1; i<stack.length; ++i) {
|
||||
String cname = stack[i].getClassName();
|
||||
final String cname = stack[i].getClassName();
|
||||
System.out.println("" + i + ":" + stack[i].getClassName() +
|
||||
"." + stack[i].getMethodName() + ":" + stack[i].getLineNumber());
|
||||
|
||||
|
||||
@@ -59,12 +59,12 @@ public class SecurityAllowedTestCase extends TestCase
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
PathableClassLoader parent = new PathableClassLoader(null);
|
||||
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
parent.addLogicalLib("commons-logging");
|
||||
parent.addLogicalLib("testclasses");
|
||||
|
||||
Class testClass = parent.loadClass(
|
||||
final Class testClass = parent.loadClass(
|
||||
"org.apache.commons.logging.security.SecurityAllowedTestCase");
|
||||
return new PathableTestSuite(testClass, parent);
|
||||
}
|
||||
@@ -88,17 +88,17 @@ public class SecurityAllowedTestCase extends TestCase
|
||||
System.setProperty(
|
||||
LogFactory.HASHTABLE_IMPLEMENTATION_PROPERTY,
|
||||
CustomHashtable.class.getName());
|
||||
MockSecurityManager mySecurityManager = new MockSecurityManager();
|
||||
final MockSecurityManager mySecurityManager = new MockSecurityManager();
|
||||
mySecurityManager.addPermission(new AllPermission());
|
||||
System.setSecurityManager(mySecurityManager);
|
||||
|
||||
try {
|
||||
// Use reflection so that we can control exactly when the static
|
||||
// initialiser for the LogFactory class is executed.
|
||||
Class c = this.getClass().getClassLoader().loadClass(
|
||||
final Class c = this.getClass().getClassLoader().loadClass(
|
||||
"org.apache.commons.logging.LogFactory");
|
||||
Method m = c.getMethod("getLog", new Class[] {Class.class});
|
||||
Log log = (Log) m.invoke(null, new Object[] {this.getClass()});
|
||||
final Method m = c.getMethod("getLog", new Class[] {Class.class});
|
||||
final Log log = (Log) m.invoke(null, new Object[] {this.getClass()});
|
||||
|
||||
// Check whether we had any security exceptions so far (which were
|
||||
// caught by the code). We should not, as every secure operation
|
||||
@@ -111,28 +111,28 @@ public class SecurityAllowedTestCase extends TestCase
|
||||
// wrap calls to log methods in AccessControllers because writes to
|
||||
// a log file *should* only be permitted if the original caller is
|
||||
// trusted to access that file.
|
||||
int untrustedCodeCount = mySecurityManager.getUntrustedCodeCount();
|
||||
final int untrustedCodeCount = mySecurityManager.getUntrustedCodeCount();
|
||||
log.info("testing");
|
||||
|
||||
// check that the default map implementation was loaded, as JCL was
|
||||
// forbidden from reading the HASHTABLE_IMPLEMENTATION_PROPERTY property.
|
||||
System.setSecurityManager(null);
|
||||
Field factoryField = c.getDeclaredField("factories");
|
||||
final Field factoryField = c.getDeclaredField("factories");
|
||||
factoryField.setAccessible(true);
|
||||
Object factoryTable = factoryField.get(null);
|
||||
final Object factoryTable = factoryField.get(null);
|
||||
assertNotNull(factoryTable);
|
||||
assertEquals(CustomHashtable.class.getName(), factoryTable.getClass().getName());
|
||||
|
||||
// we better compare that we have no security exception during the call to log
|
||||
// IBM JVM tries to load bundles during the invoke call, which increase the count
|
||||
assertEquals("Untrusted code count", untrustedCodeCount, mySecurityManager.getUntrustedCodeCount());
|
||||
} catch(Throwable t) {
|
||||
} catch(final Throwable t) {
|
||||
// Restore original security manager so output can be generated; the
|
||||
// PrintWriter constructor tries to read the line.separator
|
||||
// system property.
|
||||
System.setSecurityManager(oldSecMgr);
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
final StringWriter sw = new StringWriter();
|
||||
final PrintWriter pw = new PrintWriter(sw);
|
||||
t.printStackTrace(pw);
|
||||
fail("Unexpected exception:" + t.getMessage() + ":" + sw.toString());
|
||||
}
|
||||
|
||||
@@ -63,12 +63,12 @@ public class SecurityForbiddenTestCase extends TestCase
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
PathableClassLoader parent = new PathableClassLoader(null);
|
||||
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
parent.addLogicalLib("commons-logging");
|
||||
parent.addLogicalLib("testclasses");
|
||||
|
||||
Class testClass = parent.loadClass(
|
||||
final Class testClass = parent.loadClass(
|
||||
"org.apache.commons.logging.security.SecurityForbiddenTestCase");
|
||||
return new PathableTestSuite(testClass, parent);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class SecurityForbiddenTestCase extends TestCase
|
||||
// save security manager so it can be restored in tearDown
|
||||
oldSecMgr = System.getSecurityManager();
|
||||
|
||||
PathableClassLoader classLoader = new PathableClassLoader(null);
|
||||
final PathableClassLoader classLoader = new PathableClassLoader(null);
|
||||
classLoader.addLogicalLib("commons-logging");
|
||||
classLoader.addLogicalLib("testclasses");
|
||||
|
||||
@@ -99,17 +99,17 @@ public class SecurityForbiddenTestCase extends TestCase
|
||||
System.setProperty(
|
||||
LogFactory.HASHTABLE_IMPLEMENTATION_PROPERTY,
|
||||
CustomHashtable.class.getName());
|
||||
MockSecurityManager mySecurityManager = new MockSecurityManager();
|
||||
final MockSecurityManager mySecurityManager = new MockSecurityManager();
|
||||
|
||||
System.setSecurityManager(mySecurityManager);
|
||||
|
||||
try {
|
||||
// Use reflection so that we can control exactly when the static
|
||||
// initialiser for the LogFactory class is executed.
|
||||
Class c = this.getClass().getClassLoader().loadClass(
|
||||
final Class c = this.getClass().getClassLoader().loadClass(
|
||||
"org.apache.commons.logging.LogFactory");
|
||||
Method m = c.getMethod("getLog", new Class[] {Class.class});
|
||||
Log log = (Log) m.invoke(null, new Object[] {this.getClass()});
|
||||
final Method m = c.getMethod("getLog", new Class[] {Class.class});
|
||||
final Log log = (Log) m.invoke(null, new Object[] {this.getClass()});
|
||||
log.info("testing");
|
||||
|
||||
// check that the default map implementation was loaded, as JCL was
|
||||
@@ -118,22 +118,22 @@ public class SecurityForbiddenTestCase extends TestCase
|
||||
// The default is either the java Hashtable class (java < 1.2) or the
|
||||
// JCL WeakHashtable (java >= 1.3).
|
||||
System.setSecurityManager(oldSecMgr);
|
||||
Field factoryField = c.getDeclaredField("factories");
|
||||
final Field factoryField = c.getDeclaredField("factories");
|
||||
factoryField.setAccessible(true);
|
||||
Object factoryTable = factoryField.get(null);
|
||||
final Object factoryTable = factoryField.get(null);
|
||||
assertNotNull(factoryTable);
|
||||
String ftClassName = factoryTable.getClass().getName();
|
||||
final String ftClassName = factoryTable.getClass().getName();
|
||||
assertTrue("Custom hashtable unexpectedly used",
|
||||
!CustomHashtable.class.getName().equals(ftClassName));
|
||||
|
||||
assertEquals(0, mySecurityManager.getUntrustedCodeCount());
|
||||
} catch(Throwable t) {
|
||||
} catch(final Throwable t) {
|
||||
// Restore original security manager so output can be generated; the
|
||||
// PrintWriter constructor tries to read the line.separator
|
||||
// system property.
|
||||
System.setSecurityManager(oldSecMgr);
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
final StringWriter sw = new StringWriter();
|
||||
final PrintWriter pw = new PrintWriter(sw);
|
||||
t.printStackTrace(pw);
|
||||
fail("Unexpected exception:" + t.getMessage() + ":" + sw.toString());
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public class SecurityForbiddenTestCase extends TestCase
|
||||
System.setProperty(
|
||||
LogFactory.HASHTABLE_IMPLEMENTATION_PROPERTY,
|
||||
CustomHashtable.class.getName());
|
||||
MockSecurityManager mySecurityManager = new MockSecurityManager();
|
||||
final MockSecurityManager mySecurityManager = new MockSecurityManager();
|
||||
|
||||
System.setSecurityManager(mySecurityManager);
|
||||
|
||||
@@ -160,13 +160,13 @@ public class SecurityForbiddenTestCase extends TestCase
|
||||
|
||||
System.setSecurityManager(oldSecMgr);
|
||||
assertEquals(0, mySecurityManager.getUntrustedCodeCount());
|
||||
} catch(Throwable t) {
|
||||
} catch(final Throwable t) {
|
||||
// Restore original security manager so output can be generated; the
|
||||
// PrintWriter constructor tries to read the line.separator
|
||||
// system property.
|
||||
System.setSecurityManager(oldSecMgr);
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
final StringWriter sw = new StringWriter();
|
||||
final PrintWriter pw = new PrintWriter(sw);
|
||||
t.printStackTrace(pw);
|
||||
fail("Unexpected exception:" + t.getMessage() + ":" + sw.toString());
|
||||
}
|
||||
@@ -175,14 +175,14 @@ public class SecurityForbiddenTestCase extends TestCase
|
||||
/**
|
||||
* Loads a class with the given classloader.
|
||||
*/
|
||||
private Object loadClass(String name, ClassLoader classLoader) {
|
||||
private Object loadClass(final String name, final ClassLoader classLoader) {
|
||||
try {
|
||||
Class clazz = classLoader.loadClass(name);
|
||||
Object obj = clazz.newInstance();
|
||||
final Class clazz = classLoader.loadClass(name);
|
||||
final Object obj = clazz.newInstance();
|
||||
return obj;
|
||||
} catch ( Exception e ) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
} catch ( final Exception e ) {
|
||||
final StringWriter sw = new StringWriter();
|
||||
final PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
fail("Unexpected exception:" + e.getMessage() + ":" + sw.toString());
|
||||
}
|
||||
|
||||
@@ -43,21 +43,21 @@ public class BasicServletTestCase extends TestCase {
|
||||
// where a web.xml file specifies ServletContextCleaner as a listener, and
|
||||
// that class is deployed via a shared classloader.
|
||||
|
||||
PathableClassLoader parent = new PathableClassLoader(null);
|
||||
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
parent.addLogicalLib("commons-logging");
|
||||
parent.addLogicalLib("servlet-api");
|
||||
|
||||
PathableClassLoader child = new PathableClassLoader(parent);
|
||||
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||
child.setParentFirst(false);
|
||||
child.addLogicalLib("commons-logging");
|
||||
child.addLogicalLib("testclasses");
|
||||
|
||||
PathableClassLoader tccl = new PathableClassLoader(child);
|
||||
final PathableClassLoader tccl = new PathableClassLoader(child);
|
||||
tccl.setParentFirst(false);
|
||||
tccl.addLogicalLib("commons-logging");
|
||||
|
||||
Class testClass = child.loadClass(BasicServletTestCase.class.getName());
|
||||
final Class testClass = child.loadClass(BasicServletTestCase.class.getName());
|
||||
return new PathableTestSuite(testClass, tccl);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class BasicServletTestCase extends TestCase {
|
||||
* Testing anything else is rather difficult...
|
||||
*/
|
||||
public void testBasics() {
|
||||
ServletContextCleaner scc = new ServletContextCleaner();
|
||||
final ServletContextCleaner scc = new ServletContextCleaner();
|
||||
scc.contextDestroyed(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,14 +107,14 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
* Or we could fix SimpleLog to be sane...
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = CustomConfigTestCase.class;
|
||||
final Class thisClass = CustomConfigTestCase.class;
|
||||
|
||||
PathableClassLoader loader = new PathableClassLoader(null);
|
||||
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
loader.addLogicalLib("testclasses");
|
||||
loader.addLogicalLib("commons-logging");
|
||||
|
||||
Class testClass = loader.loadClass(thisClass.getName());
|
||||
final Class testClass = loader.loadClass(thisClass.getName());
|
||||
return new PathableTestSuite(testClass, loader);
|
||||
}
|
||||
|
||||
@@ -209,12 +209,12 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
// Check the actual log records against the expected ones
|
||||
protected void checkExpected() {
|
||||
|
||||
List acts = ((DecoratedSimpleLog) log).getCache();
|
||||
Iterator exps = expected.iterator();
|
||||
final List acts = ((DecoratedSimpleLog) log).getCache();
|
||||
final Iterator exps = expected.iterator();
|
||||
int n = 0;
|
||||
while (exps.hasNext()) {
|
||||
LogRecord exp = (LogRecord) exps.next();
|
||||
LogRecord act = (LogRecord) acts.get(n++);
|
||||
final LogRecord exp = (LogRecord) exps.next();
|
||||
final LogRecord act = (LogRecord) acts.get(n++);
|
||||
assertEquals("Row " + n + " type", exp.type, act.type);
|
||||
assertEquals("Row " + n + " message", exp.message, act.message);
|
||||
assertEquals("Row " + n + " throwable", exp.t, act.t);
|
||||
@@ -235,7 +235,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
protected void logExceptionMessages() {
|
||||
|
||||
// Generate log records
|
||||
Throwable t = new DummyException();
|
||||
final Throwable t = new DummyException();
|
||||
log.trace("trace", t); // Should not actually get logged
|
||||
log.debug("debug", t);
|
||||
log.info("info", t);
|
||||
|
||||
@@ -47,14 +47,14 @@ public class DateTimeCustomConfigTestCase extends CustomConfigTestCase {
|
||||
* Or we could fix SimpleLog to be sane...
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = DateTimeCustomConfigTestCase.class;
|
||||
final Class thisClass = DateTimeCustomConfigTestCase.class;
|
||||
|
||||
PathableClassLoader loader = new PathableClassLoader(null);
|
||||
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
loader.addLogicalLib("testclasses");
|
||||
loader.addLogicalLib("commons-logging");
|
||||
|
||||
Class testClass = loader.loadClass(thisClass.getName());
|
||||
final Class testClass = loader.loadClass(thisClass.getName());
|
||||
return new PathableTestSuite(testClass, loader);
|
||||
}
|
||||
|
||||
@@ -90,9 +90,9 @@ public class DateTimeCustomConfigTestCase extends CustomConfigTestCase {
|
||||
assertEquals("Expected date format to be set", "dd.mm.yyyy",
|
||||
((DecoratedSimpleLog) log).getDateTimeFormat());
|
||||
// try the formatter
|
||||
Date now = new Date();
|
||||
DateFormat formatter = ((DecoratedSimpleLog) log).getDateTimeFormatter();
|
||||
SimpleDateFormat sampleFormatter = new SimpleDateFormat("dd.mm.yyyy");
|
||||
final Date now = new Date();
|
||||
final DateFormat formatter = ((DecoratedSimpleLog) log).getDateTimeFormatter();
|
||||
final SimpleDateFormat sampleFormatter = new SimpleDateFormat("dd.mm.yyyy");
|
||||
assertEquals("Date should be formatters to pattern dd.mm.yyyy",
|
||||
sampleFormatter.format(now), formatter.format(now));
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class DecoratedSimpleLog extends SimpleLog {
|
||||
*/
|
||||
private static final long serialVersionUID = 196544280770017153L;
|
||||
|
||||
public DecoratedSimpleLog(String name) {
|
||||
public DecoratedSimpleLog(final String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class DecoratedSimpleLog extends SimpleLog {
|
||||
|
||||
|
||||
// Cache logged messages
|
||||
protected void log(int type, Object message, Throwable t) {
|
||||
protected void log(final int type, final Object message, final Throwable t) {
|
||||
|
||||
super.log(type, message, t);
|
||||
cache.add(new LogRecord(type, message, t));
|
||||
|
||||
@@ -75,14 +75,14 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
* Or we could fix SimpleLog to be sane...
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = DefaultConfigTestCase.class;
|
||||
final Class thisClass = DefaultConfigTestCase.class;
|
||||
|
||||
PathableClassLoader loader = new PathableClassLoader(null);
|
||||
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
loader.addLogicalLib("testclasses");
|
||||
loader.addLogicalLib("commons-logging");
|
||||
|
||||
Class testClass = loader.loadClass(thisClass.getName());
|
||||
final Class testClass = loader.loadClass(thisClass.getName());
|
||||
return new PathableTestSuite(testClass, loader);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||
factory.getClass().getName());
|
||||
|
||||
String names[] = factory.getAttributeNames();
|
||||
final String names[] = factory.getAttributeNames();
|
||||
assertNotNull("Names exists", names);
|
||||
assertEquals("Names empty", 0, names.length);
|
||||
|
||||
@@ -156,13 +156,13 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
public void testSerializable() throws Exception {
|
||||
|
||||
// Serialize and deserialize the instance
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(log);
|
||||
oos.close();
|
||||
ByteArrayInputStream bais =
|
||||
final ByteArrayInputStream bais =
|
||||
new ByteArrayInputStream(baos.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
final ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
log = (Log) ois.readObject();
|
||||
ois.close();
|
||||
|
||||
@@ -229,7 +229,7 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
|
||||
|
||||
// Set up decorated log instance
|
||||
protected void setUpDecorated(String name) {
|
||||
protected void setUpDecorated(final String name) {
|
||||
log = new DecoratedSimpleLog(name);
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
|
||||
|
||||
// Set up log instance
|
||||
protected void setUpLog(String name) throws Exception {
|
||||
protected void setUpLog(final String name) throws Exception {
|
||||
log = LogFactory.getLog(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class LogRecord implements Serializable {
|
||||
*/
|
||||
private static final long serialVersionUID = -5254831759209770665L;
|
||||
|
||||
public LogRecord(int type, Object message, Throwable t) {
|
||||
public LogRecord(final int type, final Object message, final Throwable t) {
|
||||
this.type = type;
|
||||
this.message = message;
|
||||
this.t = t;
|
||||
|
||||
@@ -30,9 +30,9 @@ import junit.framework.TestCase;
|
||||
public class BadTCCLTestCase extends TestCase {
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
PathableClassLoader contextClassLoader = new PathableClassLoader(null);
|
||||
final PathableClassLoader contextClassLoader = new PathableClassLoader(null);
|
||||
contextClassLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
PathableTestSuite suite = new PathableTestSuite(BadTCCLTestCase.class, contextClassLoader);
|
||||
final PathableTestSuite suite = new PathableTestSuite(BadTCCLTestCase.class, contextClassLoader);
|
||||
return suite;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class BadTCCLTestCase extends TestCase {
|
||||
* by the LogFactory.
|
||||
*/
|
||||
public void testGetLog() {
|
||||
Log log = LogFactory.getLog(BadTCCLTestCase.class);
|
||||
final Log log = LogFactory.getLog(BadTCCLTestCase.class);
|
||||
log.debug("Hello, Mum");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import junit.framework.TestCase;
|
||||
public class NullTCCLTestCase extends TestCase {
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
PathableTestSuite suite = new PathableTestSuite(NullTCCLTestCase.class, null);
|
||||
final PathableTestSuite suite = new PathableTestSuite(NullTCCLTestCase.class, null);
|
||||
return suite;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class NullTCCLTestCase extends TestCase {
|
||||
* by the LogFactory.
|
||||
*/
|
||||
public void testGetLog() {
|
||||
Log log = LogFactory.getLog(NullTCCLTestCase.class);
|
||||
final Log log = LogFactory.getLog(NullTCCLTestCase.class);
|
||||
log.debug("Hello, Mum");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.apache.commons.logging.Log;
|
||||
|
||||
public class MyLog implements Log {
|
||||
|
||||
public MyLog(String category) {}
|
||||
public MyLog(final String category) {}
|
||||
|
||||
public boolean isDebugEnabled() { return false; }
|
||||
public boolean isErrorEnabled() { return false; }
|
||||
@@ -29,16 +29,16 @@ public class MyLog implements Log {
|
||||
public boolean isTraceEnabled() { return false; }
|
||||
public boolean isWarnEnabled() { return false; }
|
||||
|
||||
public void trace(Object message) {}
|
||||
public void trace(Object message, Throwable t) {}
|
||||
public void debug(Object message) {}
|
||||
public void debug(Object message, Throwable t) {}
|
||||
public void info(Object message) {}
|
||||
public void info(Object message, Throwable t) {}
|
||||
public void warn(Object message) {}
|
||||
public void warn(Object message, Throwable t) {}
|
||||
public void error(Object message) {}
|
||||
public void error(Object message, Throwable t) {}
|
||||
public void fatal(Object message) {}
|
||||
public void fatal(Object message, Throwable t) {}
|
||||
public void trace(final Object message) {}
|
||||
public void trace(final Object message, final Throwable t) {}
|
||||
public void debug(final Object message) {}
|
||||
public void debug(final Object message, final Throwable t) {}
|
||||
public void info(final Object message) {}
|
||||
public void info(final Object message, final Throwable t) {}
|
||||
public void warn(final Object message) {}
|
||||
public void warn(final Object message, final Throwable t) {}
|
||||
public void error(final Object message) {}
|
||||
public void error(final Object message, final Throwable t) {}
|
||||
public void fatal(final Object message) {}
|
||||
public void fatal(final Object message, final Throwable t) {}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class MyLogFactoryImpl extends LogFactory {
|
||||
public Object getAttribute(String name) { return null; }
|
||||
public Object getAttribute(final String name) { return null; }
|
||||
public String[] getAttributeNames() { return null; }
|
||||
public Log getInstance(Class clazz) { return null; }
|
||||
public Log getInstance(String name) { return null; }
|
||||
public Log getInstance(final Class clazz) { return null; }
|
||||
public Log getInstance(final String name) { return null; }
|
||||
public void release() {}
|
||||
public void removeAttribute(String name) {}
|
||||
public void setAttribute(String name, Object value) {}
|
||||
public void removeAttribute(final String name) {}
|
||||
public void setAttribute(final String name, final Object value) {}
|
||||
}
|
||||
|
||||
@@ -48,19 +48,19 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = TcclDisabledTestCase.class;
|
||||
final Class thisClass = TcclDisabledTestCase.class;
|
||||
|
||||
// Determine the URL to this .class file, so that we can then
|
||||
// append the priority dirs to it. For tidiness, load this
|
||||
// class through a dummy loader though this is not absolutely
|
||||
// necessary...
|
||||
PathableClassLoader dummy = new PathableClassLoader(null);
|
||||
final PathableClassLoader dummy = new PathableClassLoader(null);
|
||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
dummy.addLogicalLib("testclasses");
|
||||
dummy.addLogicalLib("commons-logging");
|
||||
|
||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
URL baseUrl = dummy.findResource(thisClassPath);
|
||||
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||
|
||||
// Now set up the desired classloader hierarchy. Everything goes into
|
||||
// the parent classpath, but we exclude the custom Log class.
|
||||
@@ -68,9 +68,9 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
// We then create a tccl classloader that can see the custom
|
||||
// Log class. Therefore if that class can be found, then the
|
||||
// TCCL must have been used to load it.
|
||||
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||
final PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||
|
||||
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||
final PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
parentLoader.addLogicalLib("commons-logging");
|
||||
parentLoader.addLogicalLib("testclasses");
|
||||
@@ -78,13 +78,13 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
// the custom MyLog
|
||||
parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
|
||||
|
||||
URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
|
||||
final URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
|
||||
parentLoader.addURL(propsEnableUrl);
|
||||
|
||||
PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
||||
final PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
||||
tcclLoader.addLogicalLib("testclasses");
|
||||
|
||||
Class testClass = parentLoader.loadClass(thisClass.getName());
|
||||
final Class testClass = parentLoader.loadClass(thisClass.getName());
|
||||
return new PathableTestSuite(testClass, tcclLoader);
|
||||
}
|
||||
|
||||
@@ -109,26 +109,26 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
*/
|
||||
public void testLoader() throws Exception {
|
||||
|
||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||
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);
|
||||
|
||||
// MyLog should not be loadable via parent loader
|
||||
try {
|
||||
Class clazz = thisClassLoader.loadClass(MY_LOG_IMPL);
|
||||
final Class clazz = thisClassLoader.loadClass(MY_LOG_IMPL);
|
||||
fail("Unexpectedly able to load MyLog via test class classloader");
|
||||
assertNotNull(clazz); // silence warnings about unused var
|
||||
} catch(ClassNotFoundException ex) {
|
||||
} catch(final ClassNotFoundException ex) {
|
||||
// ok, expected
|
||||
}
|
||||
|
||||
// MyLog should be loadable via tccl loader
|
||||
try {
|
||||
Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
||||
final Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
||||
assertNotNull(clazz);
|
||||
} catch(ClassNotFoundException ex) {
|
||||
} catch(final ClassNotFoundException ex) {
|
||||
fail("Unexpectedly unable to load MyLog via tccl classloader");
|
||||
}
|
||||
}
|
||||
@@ -140,20 +140,20 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
* we should see the default Log rather than the custom one.
|
||||
*/
|
||||
public void testTcclLoading() throws Exception {
|
||||
LogFactory instance = LogFactory.getFactory();
|
||||
final LogFactory instance = LogFactory.getFactory();
|
||||
assertEquals(
|
||||
"Correct LogFactory loaded",
|
||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||
instance.getClass().getName());
|
||||
|
||||
try {
|
||||
Log log = instance.getInstance("test");
|
||||
final Log log = instance.getInstance("test");
|
||||
fail("Unexpectedly succeeded in loading a custom Log class"
|
||||
+ " that is only accessable via the tccl.");
|
||||
assertNotNull(log); // silence compiler warning about unused var
|
||||
} catch(LogConfigurationException ex) {
|
||||
} catch(final LogConfigurationException ex) {
|
||||
// ok, expected
|
||||
int index = ex.getMessage().indexOf(MY_LOG_IMPL);
|
||||
final int index = ex.getMessage().indexOf(MY_LOG_IMPL);
|
||||
assertTrue("MyLog not found", index >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,19 +48,19 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = TcclEnabledTestCase.class;
|
||||
final Class thisClass = TcclEnabledTestCase.class;
|
||||
|
||||
// Determine the URL to this .class file, so that we can then
|
||||
// append the priority dirs to it. For tidiness, load this
|
||||
// class through a dummy loader though this is not absolutely
|
||||
// necessary...
|
||||
PathableClassLoader dummy = new PathableClassLoader(null);
|
||||
final PathableClassLoader dummy = new PathableClassLoader(null);
|
||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
dummy.addLogicalLib("testclasses");
|
||||
dummy.addLogicalLib("commons-logging");
|
||||
|
||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
URL baseUrl = dummy.findResource(thisClassPath);
|
||||
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||
|
||||
// Now set up the desired classloader hierarchy. Everything goes into
|
||||
// the parent classpath, but we exclude the custom Log class.
|
||||
@@ -68,9 +68,9 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
// We then create a tccl classloader that can see the custom
|
||||
// Log class. Therefore if that class can be found, then the
|
||||
// TCCL must have been used to load it.
|
||||
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||
final PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||
|
||||
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||
final PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
parentLoader.addLogicalLib("commons-logging");
|
||||
parentLoader.addLogicalLib("testclasses");
|
||||
@@ -78,13 +78,13 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
// the custom MyLogFactoryImpl
|
||||
parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
|
||||
|
||||
URL propsEnableUrl = new URL(baseUrl, "props_enable_tccl/");
|
||||
final URL propsEnableUrl = new URL(baseUrl, "props_enable_tccl/");
|
||||
parentLoader.addURL(propsEnableUrl);
|
||||
|
||||
PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
||||
final PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
||||
tcclLoader.addLogicalLib("testclasses");
|
||||
|
||||
Class testClass = parentLoader.loadClass(thisClass.getName());
|
||||
final Class testClass = parentLoader.loadClass(thisClass.getName());
|
||||
return new PathableTestSuite(testClass, tcclLoader);
|
||||
}
|
||||
|
||||
@@ -109,26 +109,26 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
*/
|
||||
public void testLoader() throws Exception {
|
||||
|
||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||
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);
|
||||
|
||||
// MyLog should not be loadable via parent loader
|
||||
try {
|
||||
Class clazz = thisClassLoader.loadClass(MY_LOG_IMPL);
|
||||
final Class clazz = thisClassLoader.loadClass(MY_LOG_IMPL);
|
||||
fail("Unexpectedly able to load MyLog via test class classloader");
|
||||
assertNotNull(clazz); // silence warnings about unused var
|
||||
} catch(ClassNotFoundException ex) {
|
||||
} catch(final ClassNotFoundException ex) {
|
||||
// ok, expected
|
||||
}
|
||||
|
||||
// MyLog should be loadable via tccl loader
|
||||
try {
|
||||
Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
||||
final Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
||||
assertNotNull(clazz);
|
||||
} catch(ClassNotFoundException ex) {
|
||||
} catch(final ClassNotFoundException ex) {
|
||||
fail("Unexpectedly unable to load MyLog via tccl classloader");
|
||||
}
|
||||
}
|
||||
@@ -139,14 +139,14 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
* This proves that the TCCL was used to load that class.
|
||||
*/
|
||||
public void testTcclLoading() throws Exception {
|
||||
LogFactory instance = LogFactory.getFactory();
|
||||
final LogFactory instance = LogFactory.getFactory();
|
||||
|
||||
assertEquals(
|
||||
"Correct LogFactory loaded",
|
||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||
instance.getClass().getName());
|
||||
|
||||
Log log = instance.getInstance("test");
|
||||
final Log log = instance.getInstance("test");
|
||||
assertEquals(
|
||||
"Correct Log loaded",
|
||||
MY_LOG_IMPL,
|
||||
|
||||
@@ -48,19 +48,19 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = TcclDisabledTestCase.class;
|
||||
final Class thisClass = TcclDisabledTestCase.class;
|
||||
|
||||
// Determine the URL to this .class file, so that we can then
|
||||
// append the priority dirs to it. For tidiness, load this
|
||||
// class through a dummy loader though this is not absolutely
|
||||
// necessary...
|
||||
PathableClassLoader dummy = new PathableClassLoader(null);
|
||||
final PathableClassLoader dummy = new PathableClassLoader(null);
|
||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
dummy.addLogicalLib("testclasses");
|
||||
dummy.addLogicalLib("commons-logging");
|
||||
|
||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
URL baseUrl = dummy.findResource(thisClassPath);
|
||||
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||
|
||||
// Now set up the desired classloader hierarchy. Everything goes into
|
||||
// the parent classpath, but we exclude the custom LogFactoryImpl
|
||||
@@ -69,9 +69,9 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
// We then create a tccl classloader that can see the custom
|
||||
// LogFactory class. Therefore if that class can be found, then the
|
||||
// TCCL must have been used to load it.
|
||||
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||
final PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||
|
||||
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||
final PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
parentLoader.addLogicalLib("commons-logging");
|
||||
parentLoader.addLogicalLib("testclasses");
|
||||
@@ -80,13 +80,13 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
parentLoader.useExplicitLoader(
|
||||
MY_LOG_FACTORY_PKG + ".", emptyLoader);
|
||||
|
||||
URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
|
||||
final URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
|
||||
parentLoader.addURL(propsEnableUrl);
|
||||
|
||||
PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
||||
final PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
||||
tcclLoader.addLogicalLib("testclasses");
|
||||
|
||||
Class testClass = parentLoader.loadClass(thisClass.getName());
|
||||
final Class testClass = parentLoader.loadClass(thisClass.getName());
|
||||
return new PathableTestSuite(testClass, tcclLoader);
|
||||
}
|
||||
|
||||
@@ -111,26 +111,26 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
*/
|
||||
public void testLoader() throws Exception {
|
||||
|
||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||
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);
|
||||
|
||||
// MyLogFactoryImpl should not be loadable via parent loader
|
||||
try {
|
||||
Class clazz = thisClassLoader.loadClass(MY_LOG_FACTORY_IMPL);
|
||||
final Class clazz = thisClassLoader.loadClass(MY_LOG_FACTORY_IMPL);
|
||||
fail("Unexpectedly able to load MyLogFactoryImpl via test class classloader");
|
||||
assertNotNull(clazz); // silence warning about unused var
|
||||
} catch(ClassNotFoundException ex) {
|
||||
} catch(final ClassNotFoundException ex) {
|
||||
// ok, expected
|
||||
}
|
||||
|
||||
// MyLogFactoryImpl should be loadable via tccl loader
|
||||
try {
|
||||
Class clazz = tcclLoader.loadClass(MY_LOG_FACTORY_IMPL);
|
||||
final Class clazz = tcclLoader.loadClass(MY_LOG_FACTORY_IMPL);
|
||||
assertNotNull(clazz);
|
||||
} catch(ClassNotFoundException ex) {
|
||||
} catch(final ClassNotFoundException ex) {
|
||||
fail("Unexpectedly unable to load MyLogFactoryImpl via tccl classloader");
|
||||
}
|
||||
}
|
||||
@@ -143,13 +143,13 @@ public class TcclDisabledTestCase extends TestCase {
|
||||
*/
|
||||
public void testTcclLoading() throws Exception {
|
||||
try {
|
||||
LogFactory instance = LogFactory.getFactory();
|
||||
final LogFactory instance = LogFactory.getFactory();
|
||||
fail("Unexpectedly succeeded in loading custom factory, though TCCL disabled.");
|
||||
assertNotNull(instance); // silence warning about unused var
|
||||
} catch(org.apache.commons.logging.LogConfigurationException ex) {
|
||||
} catch(final org.apache.commons.logging.LogConfigurationException ex) {
|
||||
// ok, custom MyLogFactoryImpl as specified in props_disable_tccl
|
||||
// could not be found.
|
||||
int index = ex.getMessage().indexOf(MY_LOG_FACTORY_IMPL);
|
||||
final int index = ex.getMessage().indexOf(MY_LOG_FACTORY_IMPL);
|
||||
assertTrue("MylogFactoryImpl not found", index >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,19 +42,19 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
public static Test suite() throws Exception {
|
||||
Class thisClass = TcclEnabledTestCase.class;
|
||||
final Class thisClass = TcclEnabledTestCase.class;
|
||||
|
||||
// Determine the URL to this .class file, so that we can then
|
||||
// append the priority dirs to it. For tidiness, load this
|
||||
// class through a dummy loader though this is not absolutely
|
||||
// necessary...
|
||||
PathableClassLoader dummy = new PathableClassLoader(null);
|
||||
final PathableClassLoader dummy = new PathableClassLoader(null);
|
||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
dummy.addLogicalLib("testclasses");
|
||||
dummy.addLogicalLib("commons-logging");
|
||||
|
||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
URL baseUrl = dummy.findResource(thisClassPath);
|
||||
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||
|
||||
// Now set up the desired classloader hierarchy. Everything goes into
|
||||
// the parent classpath, but we exclude the custom LogFactoryImpl
|
||||
@@ -63,9 +63,9 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
// We then create a tccl classloader that can see the custom
|
||||
// LogFactory class. Therefore if that class can be found, then the
|
||||
// TCCL must have been used to load it.
|
||||
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||
final PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||
|
||||
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||
final PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||
parentLoader.addLogicalLib("commons-logging");
|
||||
parentLoader.addLogicalLib("testclasses");
|
||||
@@ -74,13 +74,13 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
parentLoader.useExplicitLoader(
|
||||
"org.apache.commons.logging.tccl.custom.", emptyLoader);
|
||||
|
||||
URL propsEnableUrl = new URL(baseUrl, "props_enable_tccl/");
|
||||
final URL propsEnableUrl = new URL(baseUrl, "props_enable_tccl/");
|
||||
parentLoader.addURL(propsEnableUrl);
|
||||
|
||||
PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
||||
final PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
||||
tcclLoader.addLogicalLib("testclasses");
|
||||
|
||||
Class testClass = parentLoader.loadClass(thisClass.getName());
|
||||
final Class testClass = parentLoader.loadClass(thisClass.getName());
|
||||
return new PathableTestSuite(testClass, tcclLoader);
|
||||
}
|
||||
|
||||
@@ -105,28 +105,28 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
*/
|
||||
public void testLoader() throws Exception {
|
||||
|
||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||
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);
|
||||
|
||||
// MyLogFactoryImpl should not be loadable via parent loader
|
||||
try {
|
||||
Class clazz = thisClassLoader.loadClass(
|
||||
final Class clazz = thisClassLoader.loadClass(
|
||||
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl");
|
||||
fail("Unexpectedly able to load MyLogFactoryImpl via test class classloader");
|
||||
assertNotNull(clazz); // silence warning about unused var
|
||||
} catch(ClassNotFoundException ex) {
|
||||
} catch(final ClassNotFoundException ex) {
|
||||
// ok, expected
|
||||
}
|
||||
|
||||
// MyLogFactoryImpl should be loadable via tccl loader
|
||||
try {
|
||||
Class clazz = tcclLoader.loadClass(
|
||||
final Class clazz = tcclLoader.loadClass(
|
||||
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl");
|
||||
assertNotNull(clazz);
|
||||
} catch(ClassNotFoundException ex) {
|
||||
} catch(final ClassNotFoundException ex) {
|
||||
fail("Unexpectedly unable to load MyLogFactoryImpl via tccl classloader");
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ public class TcclEnabledTestCase extends TestCase {
|
||||
* This proves that the TCCL was used to load that class.
|
||||
*/
|
||||
public void testTcclLoading() throws Exception {
|
||||
LogFactory instance = LogFactory.getFactory();
|
||||
final LogFactory instance = LogFactory.getFactory();
|
||||
|
||||
assertEquals(
|
||||
"Correct LogFactory loaded",
|
||||
|
||||
Reference in New Issue
Block a user