Add test scenarios where two levels of class loader hierarchies are created -
one exactly like the default configuration of Tomcat 4.1 (with c-l placed inside the webapp) and one where you put c-l in the parent class loader (in place of commons-logging-api.jar) so webapps do not have to. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@138959 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
196
src/test/org/apache/commons/logging/Wrapper.java
Normal file
196
src/test/org/apache/commons/logging/Wrapper.java
Normal file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/test/org/apache/commons/logging/Wrapper.java,v 1.1 2003/03/30 02:30:36 craigmcc Exp $
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2003/03/30 02:30:36 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution, if
|
||||
* any, must include the following acknowlegement:
|
||||
* "This product includes software developed by the
|
||||
* Apache Software Foundation (http://www.apache.org/)."
|
||||
* Alternately, this acknowlegement may appear in the software itself,
|
||||
* if and wherever such third-party acknowlegements normally appear.
|
||||
*
|
||||
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||
* Foundation" must not be used to endorse or promote products derived
|
||||
* from this software without prior written permission. For written
|
||||
* permission, please contact apache@apache.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Apache"
|
||||
* nor may "Apache" appear in their names without prior written
|
||||
* permission of the Apache Group.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.commons.logging;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Wrapper around test cases that need to have a custom class loader
|
||||
* hierarchy assembled. The wrapper is configured by the following
|
||||
* system properties:</p>
|
||||
* <ul>
|
||||
* <li><strong>wrapper.hierarchy</strong> - Descriptive code describing how
|
||||
* the class loader hierarchy should be assembled:
|
||||
* <ul>
|
||||
* <li><strong>API</strong> - Parent class loader contains
|
||||
* <code>commons-logging-api.jar</code> and child class loader
|
||||
* contains <code>commons-logging.jar</code>. This is like the
|
||||
* default configuration for Tomcat 4.1.</li>
|
||||
* <li><strong>FULL</strong> - Parent class loader contains
|
||||
* <code>commons-logging.jar</code>. This is what would happen
|
||||
* if you replaced <code>commons-logging-api.jar</code> with
|
||||
* <code>commons-logging.jar</code> so that you did not need to
|
||||
* include the latter with your application.</li>
|
||||
* </ul>
|
||||
* The child class loader also unconditionally includes
|
||||
* <code>commons-logging-tests.jar</code>.</li>
|
||||
* <li><strong>wrapper.junit</strong> - Fully qualified pathname of the
|
||||
* JUnit JAR file.</li>
|
||||
* <li><strong>wrapper.log4j</strong> - Fully qualified pathname of the
|
||||
* Log4J JAR file, which will be placed in whichever class loader
|
||||
* <code>commons-logging.jar</code> is placed in, if specified.</li>
|
||||
* <li><strong>wrapper.target</strong> - Fully qualified pathname of the
|
||||
* "target" directory created by the build process. This directory
|
||||
* must contain the <code>commons-logging.jar</code>,
|
||||
* <code>commons-logging-api.jar</code>, and
|
||||
* <code>commons-logging-tests.jar</code> files resulting from the
|
||||
* execution of the <code>compile.tests</code> target.</li>
|
||||
* <li><strong>wrapper.testcase</strong> - Fully qualified Java class name
|
||||
* of a TestCase that will ultimately be executed. This class must
|
||||
* exist in the <code>commons-logging-tests.jar</code> file.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>When executed, the system classpath for the wrapper should include
|
||||
* only the wrapper class itself.</p>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @version $Revision: 1.1 $ $Date: 2003/03/30 02:30:36 $
|
||||
*/
|
||||
|
||||
public class Wrapper {
|
||||
|
||||
|
||||
public static void main(String args[]) {
|
||||
|
||||
try {
|
||||
|
||||
// Construct URLs for the various JAR files
|
||||
File target = new File(System.getProperty("wrapper.target"));
|
||||
URL commonsLogging =
|
||||
(new File(target, "commons-logging.jar")).toURL();
|
||||
URL commonsLoggingApi =
|
||||
(new File(target, "commons-logging-api.jar")).toURL();
|
||||
URL commonsLoggingTests =
|
||||
(new File(target, "commons-logging-tests.jar")).toURL();
|
||||
URL junit =
|
||||
(new File(System.getProperty("wrapper.junit"))).toURL();
|
||||
URL log4j = null;
|
||||
if (System.getProperty("wrapper.log4j") != null) {
|
||||
log4j = (new File(System.getProperty("wrapper.log4j"))).toURL();
|
||||
}
|
||||
|
||||
// Configure the parent class loader
|
||||
URL parentURLs[] = null;
|
||||
if ("API".equals(System.getProperty("wrapper.hierarchy"))) {
|
||||
parentURLs = new URL[1];
|
||||
parentURLs[0] = commonsLoggingApi;
|
||||
} else {
|
||||
if (log4j != null) {
|
||||
parentURLs = new URL[2];
|
||||
parentURLs[0] = commonsLogging;
|
||||
parentURLs[1] = log4j;
|
||||
} else {
|
||||
parentURLs = new URL[1];
|
||||
parentURLs[0] = commonsLogging;
|
||||
}
|
||||
}
|
||||
ClassLoader parent =
|
||||
new URLClassLoader(parentURLs,
|
||||
ClassLoader.getSystemClassLoader());
|
||||
|
||||
// Configure the child class loader
|
||||
URL childURLs[] = null;
|
||||
if ("API".equals(System.getProperty("wrapper.hierarchy"))) {
|
||||
if (log4j != null) {
|
||||
childURLs = new URL[4];
|
||||
} else {
|
||||
childURLs = new URL[3];
|
||||
}
|
||||
childURLs[0] = commonsLogging;
|
||||
childURLs[1] = commonsLoggingTests;
|
||||
childURLs[2] = junit;
|
||||
if (log4j != null) {
|
||||
childURLs[3] = log4j;
|
||||
}
|
||||
} else {
|
||||
childURLs = new URL[2];
|
||||
childURLs[0] = commonsLoggingTests;
|
||||
childURLs[1] = junit;
|
||||
}
|
||||
ClassLoader child = new URLClassLoader(childURLs, parent);
|
||||
|
||||
// Execute the test runner for this TestCase
|
||||
Class clazz = child.loadClass("junit.textui.TestRunner");
|
||||
String params[] = new String[1];
|
||||
params[0] = System.getProperty("wrapper.testcase");
|
||||
Method method = clazz.getMethod("main",
|
||||
new Class[] { params.getClass() });
|
||||
method.invoke(null, new Object[] { params });
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
System.out.println("Exception Occurred: " + e);
|
||||
e.printStackTrace(System.out);
|
||||
System.exit(1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/test/org/apache/commons/logging/jdk14/CustomConfigTestCase.java,v 1.1 2003/03/29 22:04:54 craigmcc Exp $
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2003/03/29 22:04:54 $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/test/org/apache/commons/logging/jdk14/CustomConfigTestCase.java,v 1.2 2003/03/30 02:30:37 craigmcc Exp $
|
||||
* $Revision: 1.2 $
|
||||
* $Date: 2003/03/30 02:30:37 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
@@ -84,7 +84,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
* logger configured per the configuration properties.</p>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @version $Revision: 1.1 $ $Date: 2003/03/29 22:04:54 $
|
||||
* @version $Revision: 1.2 $ $Date: 2003/03/30 02:30:37 $
|
||||
*/
|
||||
|
||||
public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
@@ -93,6 +93,14 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
|
||||
/**
|
||||
* <p>Construct a new instance of this test case.</p>
|
||||
*/
|
||||
public CustomConfigTestCase() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Construct a new instance of this test case.</p>
|
||||
*
|
||||
@@ -181,27 +189,20 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
// ----------------------------------------------------------- Test Methods
|
||||
|
||||
|
||||
// Test logging message strings with exceptions
|
||||
public void testExceptionMessages() throws Exception {
|
||||
|
||||
logExceptionMessages();
|
||||
checkLogRecords(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Test logging plain message strings
|
||||
public void testPlainMessages() throws Exception {
|
||||
|
||||
logPlainMessages();
|
||||
Iterator records = handler.records();
|
||||
for (int i = 0; i < testMessages.length; i++) {
|
||||
assertTrue(records.hasNext());
|
||||
LogRecord record = (LogRecord) records.next();
|
||||
assertEquals("LogRecord level",
|
||||
testLevels[i], record.getLevel());
|
||||
assertEquals("LogRecord message",
|
||||
testMessages[i], record.getMessage());
|
||||
assertEquals("LogRecord class",
|
||||
this.getClass().getName(),
|
||||
record.getSourceClassName());
|
||||
assertEquals("LogRecord method",
|
||||
"logPlainMessages",
|
||||
record.getSourceMethodName());
|
||||
}
|
||||
assertTrue(!records.hasNext());
|
||||
handler.flush();
|
||||
checkLogRecords(false);
|
||||
|
||||
}
|
||||
|
||||
@@ -253,6 +254,53 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
// -------------------------------------------------------- Support Methods
|
||||
|
||||
|
||||
// Check the recorded messages
|
||||
protected void checkLogRecords(boolean thrown) {
|
||||
Iterator records = handler.records();
|
||||
for (int i = 0; i < testMessages.length; i++) {
|
||||
assertTrue(records.hasNext());
|
||||
LogRecord record = (LogRecord) records.next();
|
||||
assertEquals("LogRecord level",
|
||||
testLevels[i], record.getLevel());
|
||||
assertEquals("LogRecord message",
|
||||
testMessages[i], record.getMessage());
|
||||
assertEquals("LogRecord class",
|
||||
this.getClass().getName(),
|
||||
record.getSourceClassName());
|
||||
if (thrown) {
|
||||
assertEquals("LogRecord method",
|
||||
"logExceptionMessages",
|
||||
record.getSourceMethodName());
|
||||
} else {
|
||||
assertEquals("LogRecord method",
|
||||
"logPlainMessages",
|
||||
record.getSourceMethodName());
|
||||
}
|
||||
if (thrown) {
|
||||
assertNotNull("LogRecord thrown", record.getThrown());
|
||||
assertTrue("LogRecord thrown type",
|
||||
record.getThrown() instanceof IndexOutOfBoundsException);
|
||||
} else {
|
||||
assertNull("LogRecord thrown",
|
||||
record.getThrown());
|
||||
}
|
||||
}
|
||||
assertTrue(!records.hasNext());
|
||||
handler.flush();
|
||||
}
|
||||
|
||||
|
||||
// Log the messages with exceptions
|
||||
protected void logExceptionMessages() {
|
||||
Throwable t = new IndexOutOfBoundsException();
|
||||
log.trace("trace", t); // Should not actually get logged
|
||||
log.debug("debug", t);
|
||||
log.info("info", t);
|
||||
log.warn("warn", t);
|
||||
log.error("error", t);
|
||||
}
|
||||
|
||||
|
||||
// Log the plain messages
|
||||
protected void logPlainMessages() {
|
||||
log.trace("trace"); // Should not actually get logged
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/test/org/apache/commons/logging/jdk14/DefaultConfigTestCase.java,v 1.1 2003/03/29 22:04:54 craigmcc Exp $
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2003/03/29 22:04:54 $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/test/org/apache/commons/logging/jdk14/DefaultConfigTestCase.java,v 1.2 2003/03/30 02:30:37 craigmcc Exp $
|
||||
* $Revision: 1.2 $
|
||||
* $Date: 2003/03/30 02:30:37 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
@@ -76,7 +76,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
* should be automatically configured.</p>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @version $Revision: 1.1 $ $Date: 2003/03/29 22:04:54 $
|
||||
* @version $Revision: 1.2 $ $Date: 2003/03/30 02:30:37 $
|
||||
*/
|
||||
|
||||
public class DefaultConfigTestCase extends TestCase {
|
||||
@@ -85,6 +85,14 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
|
||||
/**
|
||||
* <p>Construct a new instance of this test case.</p>
|
||||
*/
|
||||
public DefaultConfigTestCase() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Construct a new instance of this test case.</p>
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user