1
0

Allow testcases to control the classloader hierarchy used during the test.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@202471 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Kitching
2005-06-30 03:21:03 +00:00
parent 8c1e4752ba
commit 9b59c323f6
11 changed files with 777 additions and 12 deletions

View File

@@ -0,0 +1,54 @@
/*
* Copyright 2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging.log4j;
import junit.framework.Test;
import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.PathableClassLoader;
/**
* TestCase for Log4J logging when the commons-logging-api jar file is in
* the parent classpath and commons-logging.jar is in the child.
*/
public class CustomConfigAPITestCase extends CustomConfigTestCase {
public CustomConfigAPITestCase(String name) {
super(name);
}
/**
* Return the tests included in this test suite.
*/
public static Test suite() throws Exception {
PathableClassLoader parent = new PathableClassLoader(null);
parent.useSystemLoader("junit.");
parent.addLogicalLib("commons-logging-api");
PathableClassLoader child = new PathableClassLoader(parent);
child.addLogicalLib("testclasses");
child.addLogicalLib("log4j12");
child.addLogicalLib("commons-logging");
Class testClass = child.loadClass(CustomConfigAPITestCase.class.getName());
return new PathableTestSuite(testClass, child);
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging.log4j;
import junit.framework.Test;
import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.PathableClassLoader;
/**
* TestCase for Log4J logging when the commons-logging jar file is in
* the parent classpath.
*/
public class CustomConfigFullTestCase extends CustomConfigTestCase {
public CustomConfigFullTestCase(String name) {
super(name);
}
/**
* Return the tests included in this test suite.
*/
public static Test suite() throws Exception {
PathableClassLoader parent = new PathableClassLoader(null);
parent.useSystemLoader("junit.");
parent.addLogicalLib("commons-logging");
parent.addLogicalLib("log4j12");
PathableClassLoader child = new PathableClassLoader(parent);
child.addLogicalLib("testclasses");
Class testClass = child.loadClass(CustomConfigFullTestCase.class.getName());
return new PathableTestSuite(testClass, child);
}
}

View File

@@ -23,13 +23,15 @@ import java.util.Iterator;
import java.util.Properties;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.PathableClassLoader;
/**
* <p>TestCase for Log4J logging when running on a system with Log4J present,
@@ -103,8 +105,17 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
/**
* Return the tests included in this test suite.
*/
public static Test suite() {
return (new TestSuite(CustomConfigTestCase.class));
public static Test suite() throws Exception {
PathableClassLoader parent = new PathableClassLoader(null);
parent.useSystemLoader("junit.");
PathableClassLoader child = new PathableClassLoader(parent);
child.addLogicalLib("testclasses");
child.addLogicalLib("log4j12");
child.addLogicalLib("commons-logging");
Class testClass = child.loadClass(CustomConfigTestCase.class.getName());
return new PathableTestSuite(testClass, child);
}
/**
@@ -123,7 +134,6 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
// Test logging message strings with exceptions
public void testExceptionMessages() throws Exception {
logExceptionMessages();
checkLoggingEvents(true);

View File

@@ -28,6 +28,8 @@ import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.PathableClassLoader;
/**
@@ -85,8 +87,17 @@ public class DefaultConfigTestCase extends TestCase {
/**
* Return the tests included in this test suite.
*/
public static Test suite() {
return (new TestSuite(DefaultConfigTestCase.class));
public static Test suite() throws Exception {
PathableClassLoader parent = new PathableClassLoader(null);
parent.useSystemLoader("junit.");
PathableClassLoader child = new PathableClassLoader(parent);
child.addLogicalLib("testclasses");
child.addLogicalLib("log4j12");
child.addLogicalLib("commons-logging");
Class testClass = child.loadClass(DefaultConfigTestCase.class.getName());
return new PathableTestSuite(testClass, child);
}
/**