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/jdk14 CustomConfigTestCase.java DefaultConfigTestCase.java
Date Sun, 30 Mar 2003 02:30:37 GMT
craigmcc    2003/03/29 18:30:37

  Modified:    logging  build.xml
               logging/src/test/org/apache/commons/logging/jdk14
                        CustomConfigTestCase.java
                        DefaultConfigTestCase.java
  Added:       logging/src/test/org/apache/commons/logging Wrapper.java
  Log:
  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.
  
  Revision  Changes    Path
  1.27      +90 -3     jakarta-commons/logging/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/build.xml,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- build.xml	29 Mar 2003 22:04:54 -0000	1.26
  +++ build.xml	30 Mar 2003 02:30:36 -0000	1.27
  @@ -48,7 +48,7 @@
     <property name="component.version"       value="1.0.2"/>
   
     <!-- The base directory for compilation targets -->
  -  <property name="build.home"              value="target"/>
  +  <property name="build.home"              value="${basedir}/target"/>
   
     <!-- The base directory for component configuration files -->
     <property name="conf.home"               value="src/conf"/>
  @@ -103,12 +103,18 @@
       <pathelement location="${junit.jar}"/>
     </path>
   
  +  <!-- Construct unit test classpath (Minimal Wrapper) -->
  +  <path id="test.classpath.wrap">
  +    <pathelement location="${build.home}/commons-logging-wrapper.jar"/>
  +  </path>
  +
     <!-- Should all tests fail if one does? -->
     <property name="test.failonerror"        value="true"/>
   
     <!-- The test runner to execute -->
     <property name="test.runner"             value="junit.textui.TestRunner"/>
     <property name="test.entry" value="org.apache.commons.logging.TestAll"/>
  +  <property name="test.wrapper"    value="org.apache.commons.logging.Wrapper"/>
   
   <!-- ========== Executable Targets ======================================== -->
   
  @@ -216,6 +222,19 @@
       <copy    todir="${build.home}/tests" filtering="on">
         <fileset dir="${test.home}" excludes="**/*.java"/>
       </copy>
  +    <jar jarfile="${build.home}/commons-${component.name}-tests.jar"
  +         basedir="${build.home}/tests"
  +         manifest="${conf.home}/MANIFEST.MF">
  +      <exclude name="org/apache/commons/logging/Wrapper.class"/>
  +    </jar>
  +    <jar jarfile="${build.home}/commons-${component.name}-wrapper.jar"
  +         basedir="${build.home}/tests"
  +         manifest="${conf.home}/MANIFEST.MF">
  +      <include name="org/apache/commons/logging/Wrapper.class"/>
  +      <include name="org/apache/commons/logging/jdk14/TestHandler.class"
  +                 if="jdk.1.4.present"/>
  +    </jar>
  +
     </target>
   
   
  @@ -272,7 +291,7 @@
   <!-- ========== Unit Test Targets ========================================= -->
   
   
  -  <target name="test"  depends="compile.tests" if="test.entry"
  +  <target name="test"  depends="compile.tests,test.jdk14" if="test.entry"
      description="Run all unit test cases">
         <java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}">
           <arg value="${test.entry}"/>
  @@ -325,6 +344,74 @@
                    value="org.apache.commons.logging.impl.Jdk14Logger"/>
         <arg value="org.apache.commons.logging.jdk14.CustomConfigTestCase"/>
         <classpath refid="test.classpath.jdk14"/>
  +    </java>
  +
  +    <echo message="Hierarchy Configuration API (JDK 1.4 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.target" value="${build.home}"/>
  +      <sysproperty key="wrapper.testcase"
  +                 value="org.apache.commons.logging.jdk14.CustomConfigTestCase"/>
  +      <classpath refid="test.classpath.wrap"/>
  +    </java>
  +
  +    <echo message="Hierarchy Configuration API (JDK 1.4 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.target" value="${build.home}"/>
  +      <sysproperty key="wrapper.testcase"
  +                 value="org.apache.commons.logging.jdk14.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 (JDK 1.4 Jdk14Logger 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.target" value="${build.home}"/>
  +      <sysproperty key="wrapper.testcase"
  +                 value="org.apache.commons.logging.jdk14.CustomConfigTestCase"/>
  +      <sysproperty key="org.apache.commons.logging.Log"
  +                 value="org.apache.commons.logging.impl.Jdk14Logger"/>
  +      <classpath refid="test.classpath.wrap"/>
  +    </java>
  +
  +    <echo message="Hierarchy Configuration FULL (JDK 1.4 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.target" value="${build.home}"/>
  +      <sysproperty key="wrapper.testcase"
  +                 value="org.apache.commons.logging.jdk14.CustomConfigTestCase"/>
  +      <classpath refid="test.classpath.wrap"/>
  +    </java>
  +
  +    <echo message="Hierarchy Configuration FULL (JDK 1.4 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.target" value="${build.home}"/>
  +      <sysproperty key="wrapper.testcase"
  +                 value="org.apache.commons.logging.jdk14.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 (JDK 1.4 Jdk14Logger 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.target" value="${build.home}"/>
  +      <sysproperty key="wrapper.testcase"
  +                 value="org.apache.commons.logging.jdk14.CustomConfigTestCase"/>
  +      <sysproperty key="org.apache.commons.logging.Log"
  +                 value="org.apache.commons.logging.impl.Jdk14Logger"/>
  +      <classpath refid="test.classpath.wrap"/>
       </java>
   
     </target>
  
  
  
  1.1                  jakarta-commons/logging/src/test/org/apache/commons/logging/Wrapper.java
  
  Index: Wrapper.java
  ===================================================================
  /*
   * $Header: /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.2       +68 -20    jakarta-commons/logging/src/test/org/apache/commons/logging/jdk14/CustomConfigTestCase.java
  
  Index: CustomConfigTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/test/org/apache/commons/logging/jdk14/CustomConfigTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CustomConfigTestCase.java	29 Mar 2003 22:04:54 -0000	1.1
  +++ CustomConfigTestCase.java	30 Mar 2003 02:30:37 -0000	1.2
  @@ -95,6 +95,14 @@
   
       /**
        * <p>Construct a new instance of this test case.</p>
  +     */
  +    public CustomConfigTestCase() {
  +        super();
  +    }
  +
  +
  +    /**
  +     * <p>Construct a new instance of this test case.</p>
        *
        * @param name Name of the test case
        */
  @@ -181,27 +189,20 @@
       // ----------------------------------------------------------- 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);
   
       }
   
  @@ -251,6 +252,53 @@
   
   
       // -------------------------------------------------------- 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
  
  
  
  1.2       +11 -3     jakarta-commons/logging/src/test/org/apache/commons/logging/jdk14/DefaultConfigTestCase.java
  
  Index: DefaultConfigTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/test/org/apache/commons/logging/jdk14/DefaultConfigTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultConfigTestCase.java	29 Mar 2003 22:04:54 -0000	1.1
  +++ DefaultConfigTestCase.java	30 Mar 2003 02:30:37 -0000	1.2
  @@ -87,6 +87,14 @@
   
       /**
        * <p>Construct a new instance of this test case.</p>
  +     */
  +    public DefaultConfigTestCase() {
  +        super();
  +    }
  +
  +
  +    /**
  +     * <p>Construct a new instance of this test case.</p>
        *
        * @param name Name of the test case
        */
  
  
  

---------------------------------------------------------------------
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