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,59 @@
/*
* 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.jdk14;
import junit.framework.Test;
import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.PathableClassLoader;
/**
* TestCase for Jdk14 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.");
// the TestHandler class must be accessable from the System classloader
// in order for java.util.logging.LogManager.readConfiguration to
// be able to instantiate it. And this test case must see the same
// class in order to be able to access its data. Yes this is ugly
// but the whole jdk14 API is a ******* mess anyway.
parent.useSystemLoader("org.apache.commons.logging.jdk14.TestHandler");
parent.addLogicalLib("commons-logging-api");
PathableClassLoader child = new PathableClassLoader(parent);
child.addLogicalLib("testclasses");
child.addLogicalLib("commons-logging");
Class testClass = child.loadClass(CustomConfigAPITestCase.class.getName());
return new PathableTestSuite(testClass, child);
}
}

View File

@@ -0,0 +1,59 @@
/*
* 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.jdk14;
import junit.framework.Test;
import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.PathableClassLoader;
/**
* TestCase for Jdk14 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.");
// the TestHandler class must be accessable from the System classloader
// in order for java.util.logging.LogManager.readConfiguration to
// be able to instantiate it. And this test case must see the same
// class in order to be able to access its data. Yes this is ugly
// but the whole jdk14 API is a ******* mess anyway.
parent.useSystemLoader("org.apache.commons.logging.jdk14.TestHandler");
parent.addLogicalLib("commons-logging");
PathableClassLoader child = new PathableClassLoader(parent);
child.addLogicalLib("testclasses");
Class testClass = child.loadClass(CustomConfigFullTestCase.class.getName());
return new PathableTestSuite(testClass, child);
}
}

View File

@@ -28,6 +28,9 @@ import java.util.logging.Logger;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.PathableClassLoader;
/**
* <p>TestCase for JDK 1.4 logging when running on a JDK 1.4 system with
@@ -114,8 +117,19 @@ 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 loader = new PathableClassLoader(null);
loader.useSystemLoader("junit.");
PathableClassLoader child = new PathableClassLoader(parent);
child.addLogicalLib("testclasses");
child.addLogicalLib("commons-logging");
Class testClass = child.loadClass(CustomConfigTestCase.class.getName());
return new PathableTestSuite(testClass, child);
*/
return new TestSuite(CustomConfigTestCase.class);
}
/**
@@ -220,9 +234,9 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
testLevels[i], record.getLevel());
assertEquals("LogRecord message",
testMessages[i], record.getMessage());
assertEquals("LogRecord class",
this.getClass().getName(),
record.getSourceClassName());
assertTrue("LogRecord class",
record.getSourceClassName().startsWith(
"org.apache.commons.logging.jdk14.CustomConfig"));
if (thrown) {
assertEquals("LogRecord method",
"logExceptionMessages",

View File

@@ -85,7 +85,7 @@ public class DefaultConfigTestCase extends TestCase {
/**
* Return the tests included in this test suite.
*/
public static Test suite() {
public static Test suite() throws Exception {
return (new TestSuite(DefaultConfigTestCase.class));
}