diff --git a/build.xml b/build.xml
index a49da6b..4739f35 100644
--- a/build.xml
+++ b/build.xml
@@ -3,7 +3,7 @@
@@ -48,7 +48,7 @@
Wrapper around test cases that need to have a custom class loader + * hierarchy assembled. The wrapper is configured by the following + * system properties:
+ *commons-logging-api.jar and child class loader
+ * contains commons-logging.jar. This is like the
+ * default configuration for Tomcat 4.1.commons-logging.jar. This is what would happen
+ * if you replaced commons-logging-api.jar with
+ * commons-logging.jar so that you did not need to
+ * include the latter with your application.commons-logging-tests.jar.commons-logging.jar is placed in, if specified.commons-logging.jar,
+ * commons-logging-api.jar, and
+ * commons-logging-tests.jar files resulting from the
+ * execution of the compile.tests target.commons-logging-tests.jar file.When executed, the system classpath for the wrapper should include + * only the wrapper class itself.
+ * + * @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); + + } + + } + + + +} diff --git a/src/test/org/apache/commons/logging/jdk14/CustomConfigTestCase.java b/src/test/org/apache/commons/logging/jdk14/CustomConfigTestCase.java index 2490a4a..4e95a24 100644 --- a/src/test/org/apache/commons/logging/jdk14/CustomConfigTestCase.java +++ b/src/test/org/apache/commons/logging/jdk14/CustomConfigTestCase.java @@ -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. * * @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 + /** + *Construct a new instance of this test case.
+ */ + public CustomConfigTestCase() { + super(); + } + + /** *Construct a new instance of this test case.
* @@ -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 diff --git a/src/test/org/apache/commons/logging/jdk14/DefaultConfigTestCase.java b/src/test/org/apache/commons/logging/jdk14/DefaultConfigTestCase.java index e00cc78..dc9f602 100644 --- a/src/test/org/apache/commons/logging/jdk14/DefaultConfigTestCase.java +++ b/src/test/org/apache/commons/logging/jdk14/DefaultConfigTestCase.java @@ -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. * * @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 + /** + *Construct a new instance of this test case.
+ */ + public DefaultConfigTestCase() { + super(); + } + + /** *Construct a new instance of this test case.
*