commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-commons/logging/src/test/org/apache/commons/logging/log4j CustomConfigTestCase.java
Date Wed, 02 Apr 2003 00:50:50 GMT
craigmcc    2003/04/01 16:50:49

  Modified:    logging  build.xml
               logging/src/test/org/apache/commons/logging Wrapper.java
               logging/src/test/org/apache/commons/logging/log4j
                        CustomConfigTestCase.java
  Log:
  Wrapper:
  - Refactor the setup of class loaders so that it is clearer what is
    going on
  - For the Log4J tests, add the custom Appender implementation to
    whichever class loader Log4J is put in
  - Set and reset the thread context class loader to more accurately
    simulate the environment of a servlet container.
  
  build.xml:
  - Implement the multi-classloader test scenarios for Log4J, equivalent
    to those for JDK 1.4.
  
  We now have a robust testing environment to catch any possible regressions
  when modifying the functionality (such as ripping out Log4jFactory, as
  discussed on COMMONS-DEV).
  
  I don't have time to do the corresponding test scenarios for Avalon LogKit,
  but anyone who wants to do so is welcome to create them.
  
  Revision  Changes    Path
  1.32      +85 -3     jakarta-commons/logging/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/build.xml,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- build.xml	31 Mar 2003 00:38:22 -0000	1.31
  +++ build.xml	2 Apr 2003 00:50:49 -0000	1.32
  @@ -236,16 +236,24 @@
       <copy    todir="${build.home}/tests" filtering="on">
         <fileset dir="${test.home}" excludes="**/*.java"/>
       </copy>
  +    <jar jarfile="${build.home}/commons-${component.name}-appender.jar"
  +         basedir="${build.home}/tests"
  +        manifest="${build.home}/conf/MANIFEST.MF">
  +      <include name="org/apache/commons/logging/log4j/CustomConfig.properties"
  +                 if="log4j.present"/>
  +      <include name="org/apache/commons/logging/log4j/TestAppender.class"
  +                 if="log4j.present"/>
  +    </jar>
       <jar jarfile="${build.home}/commons-${component.name}-tests.jar"
            basedir="${build.home}/tests"
  -         manifest="${build.home}/conf/MANIFEST.MF">
  +        manifest="${build.home}/conf/MANIFEST.MF">
         <exclude name="org/apache/commons/logging/Wrapper.class"/>
         <exclude name="org/apache/commons/logging/jdk14/TestHandler.class"
                    if="jdk.1.4.present"/>
       </jar>
       <jar jarfile="${build.home}/commons-${component.name}-wrapper.jar"
            basedir="${build.home}/tests"
  -         manifest="${build.home}/conf/MANIFEST.MF">
  +        manifest="${build.home}/conf/MANIFEST.MF">
         <include name="org/apache/commons/logging/Wrapper.class"/>
         <include name="org/apache/commons/logging/jdk14/TestHandler.class"
                    if="jdk.1.4.present"/>
  @@ -476,6 +484,80 @@
                    value="org.apache.commons.logging.impl.Log4JLogger"/>
         <arg value="org.apache.commons.logging.log4j.CustomConfigTestCase"/>
         <classpath refid="test.classpath.log4j"/>
  +    </java>
  +
  +    <echo message="Hierarchy Configuration API (Log4J Auto-Recognized)"/>
  +    <java classname="${test.wrapper}" fork="yes" failonerror="${test.failonerror}">
  +      <sysproperty key="wrapper.hierarchy" value="API"/>
  +      <sysproperty key="wrapper.junit" value="${junit.jar}"/>
  +      <sysproperty key="wrapper.log4j" value="${log4j.jar}"/>
  +      <sysproperty key="wrapper.target" value="${build.home}"/>
  +      <sysproperty key="wrapper.testcase"
  +                 value="org.apache.commons.logging.log4j.CustomConfigTestCase"/>
  +      <classpath refid="test.classpath.wrap"/>
  +    </java>
  +
  +    <echo message="Hierarchy Configuration API (Log4J LogFactoryImpl Selected)"/>
  +    <java classname="${test.wrapper}" fork="yes" failonerror="${test.failonerror}">
  +      <sysproperty key="wrapper.hierarchy" value="API"/>
  +      <sysproperty key="wrapper.junit" value="${junit.jar}"/>
  +      <sysproperty key="wrapper.log4j" value="${log4j.jar}"/>
  +      <sysproperty key="wrapper.target" value="${build.home}"/>
  +      <sysproperty key="wrapper.testcase"
  +                 value="org.apache.commons.logging.log4j.CustomConfigTestCase"/>
  +      <sysproperty key="org.apache.commons.logging.LogFactory"
  +                 value="org.apache.commons.logging.impl.LogFactoryImpl"/>
  +      <classpath refid="test.classpath.wrap"/>
  +    </java>
  +
  +    <echo message="Hierarchy Configuration API (Log4J Log4JLogger Selected)"/>
  +    <java classname="${test.wrapper}" fork="yes" failonerror="${test.failonerror}">
  +      <sysproperty key="wrapper.hierarchy" value="API"/>
  +      <sysproperty key="wrapper.junit" value="${junit.jar}"/>
  +      <sysproperty key="wrapper.log4j" value="${log4j.jar}"/>
  +      <sysproperty key="wrapper.target" value="${build.home}"/>
  +      <sysproperty key="wrapper.testcase"
  +                 value="org.apache.commons.logging.log4j.CustomConfigTestCase"/>
  +      <sysproperty key="org.apache.commons.logging.Log"
  +                 value="org.apache.commons.logging.impl.Log4JLogger"/>
  +      <classpath refid="test.classpath.wrap"/>
  +    </java>
  +
  +    <echo message="Hierarchy Configuration FULL (Log4J Auto-Recognized)"/>
  +    <java classname="${test.wrapper}" fork="yes" failonerror="${test.failonerror}">
  +      <sysproperty key="wrapper.hierarchy" value="FULL"/>
  +      <sysproperty key="wrapper.junit" value="${junit.jar}"/>
  +      <sysproperty key="wrapper.log4j" value="${log4j.jar}"/>
  +      <sysproperty key="wrapper.target" value="${build.home}"/>
  +      <sysproperty key="wrapper.testcase"
  +                 value="org.apache.commons.logging.log4j.CustomConfigTestCase"/>
  +      <classpath refid="test.classpath.wrap"/>
  +    </java>
  +
  +    <echo message="Hierarchy Configuration FULL (Log4J LogFactoryImpl Selected)"/>
  +    <java classname="${test.wrapper}" fork="yes" failonerror="${test.failonerror}">
  +      <sysproperty key="wrapper.hierarchy" value="FULL"/>
  +      <sysproperty key="wrapper.junit" value="${junit.jar}"/>
  +      <sysproperty key="wrapper.log4j" value="${log4j.jar}"/>
  +      <sysproperty key="wrapper.target" value="${build.home}"/>
  +      <sysproperty key="wrapper.testcase"
  +                 value="org.apache.commons.logging.log4j.CustomConfigTestCase"/>
  +      <sysproperty key="org.apache.commons.logging.LogFactory"
  +                 value="org.apache.commons.logging.impl.LogFactoryImpl"/>
  +      <classpath refid="test.classpath.wrap"/>
  +    </java>
  +
  +    <echo message="Hierarchy Configuration FULL (Log4J Log4JLogger Selected)"/>
  +    <java classname="${test.wrapper}" fork="yes" failonerror="${test.failonerror}">
  +      <sysproperty key="wrapper.hierarchy" value="FULL"/>
  +      <sysproperty key="wrapper.junit" value="${junit.jar}"/>
  +      <sysproperty key="wrapper.log4j" value="${log4j.jar}"/>
  +      <sysproperty key="wrapper.target" value="${build.home}"/>
  +      <sysproperty key="wrapper.testcase"
  +                 value="org.apache.commons.logging.log4j.CustomConfigTestCase"/>
  +      <sysproperty key="org.apache.commons.logging.Log"
  +                 value="org.apache.commons.logging.impl.Log4JLogger"/>
  +      <classpath refid="test.classpath.wrap"/>
       </java>
   
     </target>
  
  
  
  1.2       +38 -38    jakarta-commons/logging/src/test/org/apache/commons/logging/Wrapper.java
  
  Index: Wrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/test/org/apache/commons/logging/Wrapper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Wrapper.java	30 Mar 2003 02:30:36 -0000	1.1
  +++ Wrapper.java	2 Apr 2003 00:50:49 -0000	1.2
  @@ -66,6 +66,8 @@
   import java.lang.reflect.Method;
   import java.net.URL;
   import java.net.URLClassLoader;
  +import java.util.ArrayList;
  +import java.util.List;
   
   
   /**
  @@ -118,6 +120,11 @@
   
           try {
   
  +            // Create variables we will need
  +            List parentList = new ArrayList();
  +            List childList = new ArrayList();
  +            URL urls[] = null;
  +
               // Construct URLs for the various JAR files
               File target = new File(System.getProperty("wrapper.target"));
               URL commonsLogging =
  @@ -128,62 +135,55 @@
                   (new File(target, "commons-logging-tests.jar")).toURL();
               URL junit =
                   (new File(System.getProperty("wrapper.junit"))).toURL();
  +            URL appender = null;
               URL log4j = null;
               if (System.getProperty("wrapper.log4j") != null) {
  -                log4j = (new File(System.getProperty("wrapper.log4j"))).toURL();
  +                log4j =
  +                    (new File(System.getProperty("wrapper.log4j"))).toURL();
  +                appender =
  +                    (new File(target, "commons-logging-appender.jar")).toURL();
               }
   
  -            // Configure the parent class loader
  -            URL parentURLs[] = null;
  +            // Construct class loader repository lists for supported scenarios
               if ("API".equals(System.getProperty("wrapper.hierarchy"))) {
  -                parentURLs = new URL[1];
  -                parentURLs[0] = commonsLoggingApi;
  -            } else {
  +                parentList.add(commonsLoggingApi);
  +                childList.add(commonsLogging);
                   if (log4j != null) {
  -                    parentURLs = new URL[2];
  -                    parentURLs[0] = commonsLogging;
  -                    parentURLs[1] = log4j;
  -                } else {
  -                    parentURLs = new URL[1];
  -                    parentURLs[0] = commonsLogging;
  +                    childList.add(log4j);
  +                    childList.add(appender);
                   }
  -            }
  -            ClassLoader parent =
  -                new URLClassLoader(parentURLs,
  -                                   ClassLoader.getSystemClassLoader());
  -
  -            // Configure the child class loader
  -            URL childURLs[] = null;
  -            if ("API".equals(System.getProperty("wrapper.hierarchy"))) {
  +            } else { // Assumes "FULL"
  +                parentList.add(commonsLogging);
                   if (log4j != null) {
  -                    childURLs = new URL[4];
  -                } else {
  -                    childURLs = new URL[3];
  +                    parentList.add(log4j);
  +                    childList.add(appender);
                   }
  -                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);
  +            childList.add(commonsLoggingTests);
  +            childList.add(junit);
  +
  +            // Construt the parent and child class loaders
  +            urls = (URL[]) parentList.toArray(new URL[parentList.size()]);
  +            ClassLoader parent =
  +                new URLClassLoader(urls,
  +                                   ClassLoader.getSystemClassLoader());
  +            urls = (URL[]) childList.toArray(new URL[childList.size()]);
  +            ClassLoader child = new URLClassLoader(urls, parent);
   
               // Execute the test runner for this TestCase
  +            ClassLoader old = Thread.currentThread().getContextClassLoader();
  +            Thread.currentThread().setContextClassLoader(child);
               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 });
  +            Thread.currentThread().setContextClassLoader(old);
   
           } catch (Exception e) {
   
  -            System.out.println("Exception Occurred:  " + e);
  +            System.out.println("Wrapper Exception Occurred:  " + e);
               e.printStackTrace(System.out);
               System.exit(1);
   
  
  
  
  1.2       +5 -5      jakarta-commons/logging/src/test/org/apache/commons/logging/log4j/CustomConfigTestCase.java
  
  Index: CustomConfigTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/test/org/apache/commons/logging/log4j/CustomConfigTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CustomConfigTestCase.java	30 Mar 2003 05:22:50 -0000	1.1
  +++ CustomConfigTestCase.java	2 Apr 2003 00:50:49 -0000	1.2
  @@ -235,7 +235,7 @@
       protected void checkLoggingEvents(boolean thrown) {
           Iterator events = appender.events();
           for (int i = 0; i < testMessages.length; i++) {
  -            assertTrue(events.hasNext());
  +            assertTrue("Logged event " + i + " exists",events.hasNext());
               LoggingEvent event = (LoggingEvent) events.next();
               assertEquals("LoggingEvent level",
                            testLevels[i], event.getLevel());
  
  
  

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


Mime
View raw message