You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sk...@apache.org on 2005/07/21 08:07:34 UTC

svn commit: r220001 - in /jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j: ./ log4j12/

Author: skitching
Date: Wed Jul 20 23:07:30 2005
New Revision: 220001

URL: http://svn.apache.org/viewcvs?rev=220001&view=rev
Log:
Implement a cleaner mechanism for setting up a test suite for classes whose
dependent libs are not present in the system classpath. The class containing
the suite() method *does not have to be* the class that contains the test
methods. By taking advantage of this, we can avoid the reflection stuff and
the trivial helper class that was introduced earlier to solve this same 
problem.

Removed:
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/TestHelper.java
Modified:
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/StandardTests.java
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ApiClasspathStandardTestCase.java
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/AppClasspathStandardTestCase.java
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ChildClasspathStandardTestCase.java
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ParentClasspathStandardTestCase.java

Modified: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/StandardTests.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/StandardTests.java?rev=220001&r1=220000&r2=220001&view=diff
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/StandardTests.java (original)
+++ jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/StandardTests.java Wed Jul 20 23:07:30 2005
@@ -54,31 +54,6 @@
         public String level;
         public Throwable throwable;
     }
-    
-    /**
-     * Simple helper class that can configure log4j to redirect all logged
-     * messages into a list of LogEvent messages.
-     * <p>
-     * The TestCase classes that junit will run later have two roles: they
-     * hold the tests to run, and they also provide the suite() method that
-     * indicates which tests to run. This causes complications for us in the
-     * case of log4j because of the binary-incompatible log4j versions. We 
-     * can't have any version of log4j to be in the classpath until we are
-     * actually running the tests returned by suite() - but junit can't load
-     * the class to call suite() on it if the class or any of its ancestors
-     * have direct references to log4j APIs (or NoClassDefFound occurs).
-     * <p>
-     * The answer is to move all the direct log4j calls out of the TestCase
-     * classes into a helper which is only loaded via reflection during the
-     * test runs (and not during calls to suite()). This class defines the
-     * interface required of that helper.
-     * <p>
-     * See also method getTestHelperClassName.  
-     */
-
-    public static interface TestHelper {
-        public void forwardMessages(List logEvents);
-    }
 
     // ------------------------------------------------------------------- 
     // JUnit Infrastructure Methods
@@ -102,8 +77,15 @@
     // abstract methods
     // ----------------------------------------------------------- 
 
-    protected abstract String getTestHelperClassName();
-
+    /**
+     * Modify log4j's setup so that all messages actually logged get redirected
+     * into the specified list.
+     * <p>
+     * This method also sets the logging level to INFO so that we
+     * can test whether messages are getting properly filtered.
+     */
+    public abstract void setUpTestAppender(List logEvents) throws Exception;
+    
     // ----------------------------------------------------------- Test Methods
 
     /**
@@ -167,20 +149,6 @@
     }
 
     // -------------------------------------------------------- Support Methods
-
-    /**
-     * Modify log4j's setup so that all messages actually logged get redirected
-     * into the specified list.
-     * <p>
-     * This method also sets the logging level to INFO so that we
-     * can test whether messages are getting properly filtered.
-     */
-    private void setUpTestAppender(List logEvents) throws Exception {
-        String testHelperClassName = getTestHelperClassName();
-        Class clazz = this.getClass().getClassLoader().loadClass(testHelperClassName);
-        TestHelper testHelper = (TestHelper) clazz.newInstance();
-        testHelper.forwardMessages(logEvents);
-    }
 
     /**
      * Verify that the TestAppender has received the expected

Modified: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ApiClasspathStandardTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ApiClasspathStandardTestCase.java?rev=220001&r1=220000&r2=220001&view=diff
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ApiClasspathStandardTestCase.java (original)
+++ jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ApiClasspathStandardTestCase.java Wed Jul 20 23:07:30 2005
@@ -29,14 +29,12 @@
  * the parent classpath and commons-logging.jar is in the child.
  */
 
-public class ApiClasspathStandardTestCase extends StandardTests {
+public class ApiClasspathStandardTestCase {
 
     /**
      * Return the tests included in this test suite.
      */
     public static Test suite() throws Exception {
-        Class thisClass = ApiClasspathStandardTestCase.class;
-        
         PathableClassLoader parent = new PathableClassLoader(null);
         parent.useSystemLoader("junit.");
         parent.addLogicalLib("commons-logging-api");
@@ -46,15 +44,8 @@
         child.addLogicalLib("commons-logging");
         child.addLogicalLib("testclasses");
 
-        Class testClass = child.loadClass(thisClass.getName());
+        Class testClass = child.loadClass(
+            "org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
         return new PathableTestSuite(testClass, child);
-    }
-    
-    /**
-     * Return the name of a class that makes all direct calls to log4j
-     * apis. See StandardTests.TestHelper for more information.
-     */
-    public String getTestHelperClassName() {
-        return "org.apache.commons.logging.log4j.log4j12.TestHelper";
     }
 }

Modified: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/AppClasspathStandardTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/AppClasspathStandardTestCase.java?rev=220001&r1=220000&r2=220001&view=diff
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/AppClasspathStandardTestCase.java (original)
+++ jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/AppClasspathStandardTestCase.java Wed Jul 20 23:07:30 2005
@@ -27,29 +27,20 @@
  * is in it, as would be the situation for a standalone application.
  */
 
-public class AppClasspathStandardTestCase extends StandardTests {
+public class AppClasspathStandardTestCase {
 
     /**
      * Return the tests included in this test suite.
      */
     public static Test suite() throws Exception {
-        Class thisClass = AppClasspathStandardTestCase.class;
-        
         PathableClassLoader loader = new PathableClassLoader(null);
         loader.useSystemLoader("junit.");
         loader.addLogicalLib("testclasses");
         loader.addLogicalLib("log4j12");
         loader.addLogicalLib("commons-logging");
         
-        Class testClass = loader.loadClass(thisClass.getName());
+        Class testClass = loader.loadClass(
+            "org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
         return new PathableTestSuite(testClass, loader);
-    }
-    
-    /**
-     * Return the name of a class that makes all direct calls to log4j
-     * apis. See StandardTests.TestHelper for more information.
-     */
-    public String getTestHelperClassName() {
-        return "org.apache.commons.logging.log4j.log4j12.TestHelper";
     }
 }

Modified: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ChildClasspathStandardTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ChildClasspathStandardTestCase.java?rev=220001&r1=220000&r2=220001&view=diff
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ChildClasspathStandardTestCase.java (original)
+++ jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ChildClasspathStandardTestCase.java Wed Jul 20 23:07:30 2005
@@ -28,14 +28,12 @@
  * a container where all the necessary libs are in the child.
  */
 
-public class ChildClasspathStandardTestCase extends StandardTests {
+public class ChildClasspathStandardTestCase {
 
     /**
      * Return the tests included in this test suite.
      */
     public static Test suite() throws Exception {
-        Class thisClass = ChildClasspathStandardTestCase.class;
-        
         PathableClassLoader parent = new PathableClassLoader(null);
         parent.useSystemLoader("junit.");
 
@@ -44,15 +42,8 @@
         child.addLogicalLib("log4j12");
         child.addLogicalLib("commons-logging");
         
-        Class testClass = child.loadClass(thisClass.getName());
+        Class testClass = child.loadClass(
+            "org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
         return new PathableTestSuite(testClass, child);
-    }
-    
-    /**
-     * Return the name of a class that makes all direct calls to log4j
-     * apis. See StandardTests.TestHelper for more information.
-     */
-    public String getTestHelperClassName() {
-        return "org.apache.commons.logging.log4j.log4j12.TestHelper";
     }
 }

Modified: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ParentClasspathStandardTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ParentClasspathStandardTestCase.java?rev=220001&r1=220000&r2=220001&view=diff
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ParentClasspathStandardTestCase.java (original)
+++ jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/log4j/log4j12/ParentClasspathStandardTestCase.java Wed Jul 20 23:07:30 2005
@@ -27,14 +27,12 @@
  * a container where all the necessary libs are in the parent.
  */
 
-public class ParentClasspathStandardTestCase extends StandardTests {
+public class ParentClasspathStandardTestCase {
 
     /**
      * Return the tests included in this test suite.
      */
     public static Test suite() throws Exception {
-        Class thisClass = ParentClasspathStandardTestCase.class;
-        
         PathableClassLoader parent = new PathableClassLoader(null);
         parent.useSystemLoader("junit.");
         parent.addLogicalLib("commons-logging");
@@ -43,15 +41,8 @@
         PathableClassLoader child = new PathableClassLoader(parent);
         child.addLogicalLib("testclasses");
         
-        Class testClass = child.loadClass(thisClass.getName());
+        Class testClass = child.loadClass(
+            "org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
         return new PathableTestSuite(testClass, child);
-    }
-    
-    /**
-     * Return the name of a class that makes all direct calls to log4j
-     * apis. See StandardTests.TestHelper for more information.
-     */
-    public String getTestHelperClassName() {
-        return "org.apache.commons.logging.log4j.log4j12.TestHelper";
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org