Author: skitching
Date: Wed Jul 6 05:37:25 2005
New Revision: 209452
URL: http://svn.apache.org/viewcvs?rev=209452&view=rev
Log:
Use custom classloader setups to work around SimpleLog static insanity.
Modified:
jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/CustomConfigTestCase.java
jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/DateTimeCustomConfigTestCase.java
jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/DefaultConfigTestCase.java
Modified:
jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/CustomConfigTestCase.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/CustomConfigTestCase.java?rev=209452&r1=209451&r2=209452&view=diff
==============================================================================
---
jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/CustomConfigTestCase.java
(original)
+++
jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/CustomConfigTestCase.java
Wed Jul 6 05:37:25 2005
@@ -25,6 +25,8 @@
import junit.framework.TestSuite;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.PathableClassLoader;
+import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.impl.SimpleLog;
@@ -93,9 +95,26 @@
/**
* Return the tests included in this test suite.
- */
- public static Test suite() {
- return (new TestSuite(CustomConfigTestCase.class));
+ * <p>
+ * We need to use a PathableClassLoader here because the SimpleLog class
+ * is a pile of junk and chock-full of static variables. Any other test
+ * (like simple.CustomConfigTestCase) that has used the SimpleLog class
+ * will already have caused it to do once-only initialisation that we
+ * can't reset, even by calling LogFactory.releaseAll, because of those
+ * ugly statics. The only clean solution is to load a clean copy of
+ * commons-logging including SimpleLog via a nice clean classloader.
+ * Or we could fix SimpleLog to be sane...
+ */
+ public static Test suite() throws Exception {
+ Class thisClass = CustomConfigTestCase.class;
+
+ PathableClassLoader loader = new PathableClassLoader(null);
+ loader.useSystemLoader("junit.");
+ loader.addLogicalLib("testclasses");
+ loader.addLogicalLib("commons-logging");
+
+ Class testClass = loader.loadClass(thisClass.getName());
+ return new PathableTestSuite(testClass, loader);
}
/**
Modified:
jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/DateTimeCustomConfigTestCase.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/DateTimeCustomConfigTestCase.java?rev=209452&r1=209451&r2=209452&view=diff
==============================================================================
---
jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/DateTimeCustomConfigTestCase.java
(original)
+++
jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/DateTimeCustomConfigTestCase.java
Wed Jul 6 05:37:25 2005
@@ -16,6 +16,7 @@
package org.apache.commons.logging.simple;
+import java.util.ArrayList;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
@@ -23,6 +24,10 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.PathableTestSuite;
+import org.apache.commons.logging.PathableClassLoader;
+
/**
* Tests custom date time format configuration
@@ -33,21 +38,53 @@
/**
* Return the tests included in this test suite.
+ * <p>
+ * We need to use a PathableClassLoader here because the SimpleLog class
+ * is a pile of junk and chock-full of static variables. Any other test
+ * (like simple.CustomConfigTestCase) that has used the SimpleLog class
+ * will already have caused it to do once-only initialisation that we
+ * can't reset, even by calling LogFactory.releaseAll, because of those
+ * ugly statics. The only clean solution is to load a clean copy of
+ * commons-logging including SimpleLog via a nice clean classloader.
+ * Or we could fix SimpleLog to be sane...
*/
- public static Test suite() {
- return (new TestSuite(DateTimeCustomConfigTestCase.class));
+ public static Test suite() throws Exception {
+ Class thisClass = DateTimeCustomConfigTestCase.class;
+
+ PathableClassLoader loader = new PathableClassLoader(null);
+ loader.useSystemLoader("junit.");
+ loader.addLogicalLib("testclasses");
+ loader.addLogicalLib("commons-logging");
+
+ Class testClass = loader.loadClass(thisClass.getName());
+ return new PathableTestSuite(testClass, loader);
}
/**
- * <p>Construct a new instance of this test case.</p>
- *
- * @param name Name of the test case
+ * Set up system properties required by this unit test. Here, we
+ * set up the props defined in the parent class setProperties method,
+ * and add a few to configure the SimpleLog class date/time output.
*/
- public DateTimeCustomConfigTestCase(String name) {
- super(name);
+ public void setProperties() {
+ super.setProperties();
+
+ System.setProperty(
+ "org.apache.commons.logging.simplelog.dateTimeFormat",
+ "dd.mm.yyyy");
+ System.setProperty(
+ "org.apache.commons.logging.simplelog.showdatetime",
+ "true");
}
-
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+
// ----------------------------------------------------------- Methods
/** Checks that the date time format has been successfully set */
@@ -62,7 +99,7 @@
assertEquals("Date should be formatters to pattern dd.mm.yyyy",
sampleFormatter.format(now), formatter.format(now));
}
- /** Hook for subclassses */
+ /** Hook for subclassses */
protected void checkShowDateTime() {
assertTrue(((DecoratedSimpleLog) log).getShowDateTime());
}
Modified:
jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/DefaultConfigTestCase.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/DefaultConfigTestCase.java?rev=209452&r1=209451&r2=209452&view=diff
==============================================================================
---
jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/DefaultConfigTestCase.java
(original)
+++
jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/simple/DefaultConfigTestCase.java
Wed Jul 6 05:37:25 2005
@@ -28,6 +28,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.PathableClassLoader;
+import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.impl.SimpleLog;
@@ -61,20 +63,48 @@
/**
- * Set up instance variables required by this test case.
+ * Return the tests included in this test suite.
+ * <p>
+ * We need to use a PathableClassLoader here because the SimpleLog class
+ * is a pile of junk and chock-full of static variables. Any other test
+ * (like simple.CustomConfigTestCase) that has used the SimpleLog class
+ * will already have caused it to do once-only initialisation that we
+ * can't reset, even by calling LogFactory.releaseAll, because of those
+ * ugly statics. The only clean solution is to load a clean copy of
+ * commons-logging including SimpleLog via a nice clean classloader.
+ * Or we could fix SimpleLog to be sane...
*/
- public void setUp() throws Exception {
- LogFactory.releaseAll();
- setUpFactory();
- setUpLog("TestLogger");
+ public static Test suite() throws Exception {
+ Class thisClass = DefaultConfigTestCase.class;
+
+ PathableClassLoader loader = new PathableClassLoader(null);
+ loader.useSystemLoader("junit.");
+ loader.addLogicalLib("testclasses");
+ loader.addLogicalLib("commons-logging");
+
+ Class testClass = loader.loadClass(thisClass.getName());
+ return new PathableTestSuite(testClass, loader);
}
+ /**
+ * Set system properties that will control the LogFactory/Log objects
+ * when they are created. Subclasses can override this method to
+ * define properties that suit them.
+ */
+ public void setProperties() {
+ System.setProperty(
+ "org.apache.commons.logging.Log",
+ "org.apache.commons.logging.impl.SimpleLog");
+ }
/**
- * Return the tests included in this test suite.
+ * Set up instance variables required by this test case.
*/
- public static Test suite() {
- return (new TestSuite(DefaultConfigTestCase.class));
+ public void setUp() throws Exception {
+ LogFactory.releaseAll();
+ setProperties();
+ setUpFactory();
+ setUpLog("TestLogger");
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]