You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by cr...@apache.org on 2003/08/16 23:25:54 UTC

cvs commit: jakarta-commons/logging/src/test/org/apache/commons/logging/simple CustomConfigTestCase.java DecoratedSimpleLog.java DefaultConfigTestCase.java LogRecord.java

craigmcc    2003/08/16 14:25:54

  Modified:    logging  build.xml
               logging/src/java/org/apache/commons/logging/impl
                        SimpleLog.java
  Added:       logging/src/test/org/apache/commons/logging/simple
                        CustomConfigTestCase.java DecoratedSimpleLog.java
                        DefaultConfigTestCase.java LogRecord.java
  Log:
  Make o.a.c.l.impl.SimpleLog Serializable.
  
  Add more comprehensive unit tests for SimpleLog, including the ability
  to serialize and deserialize instances.
  
  This work will form the basis for making similar changes to the other
  Log implementations (and their corresponding test cases).
  
  Revision  Changes    Path
  1.39      +33 -5     jakarta-commons/logging/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/build.xml,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- build.xml	22 May 2003 13:55:28 -0000	1.38
  +++ build.xml	16 Aug 2003 21:25:53 -0000	1.39
  @@ -396,15 +396,18 @@
   <!-- ========== Unit Test Targets ========================================= -->
   
   
  -  <target name="test"  depends="compile.tests,test.jdk14,test.log4j,test.avalon
  -          " if="test.entry"
  +  <target name="test"
  +       depends="compile.tests,test.jdk14,test.log4j,test.simple,test.avalon"
  +            if="test.entry"
      description="Run all unit test cases">
  -      <java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}">
  -        <arg value="${test.entry}"/>
  +      <java    classname="${test.runner}" fork="yes"
  +             failonerror="${test.failonerror}">
  +        <arg       value="${test.entry}"/>
           <classpath refid="test.classpath"/>
         </java>
     </target>
   
  +
     <target name="test.jdk14" depends="compile.tests" if="jdk.1.4.present"
      description="Run unit tests specific to JDK 1.4 logging">
   
  @@ -645,6 +648,31 @@
       </java>
   
     </target>
  +
  +
  +  <target name="test.simple" depends="compile.tests"
  +   description="Run unit tests specific to SimpleLog logging">
  +
  +    <echo message="Default Configuration (SimpleLog Selected)"/>
  +    <java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}">
  +      <sysproperty key="org.apache.commons.logging.Log"
  +                 value="org.apache.commons.logging.impl.SimpleLog"/>
  +      <arg value="org.apache.commons.logging.simple.DefaultConfigTestCase"/>
  +      <classpath refid="test.classpath"/>
  +    </java>
  +
  +    <echo message="Custom Configuration (SimpleLog Selected)"/>
  +    <java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}">
  +      <sysproperty key="org.apache.commons.logging.Log"
  +                 value="org.apache.commons.logging.simple.DecoratedSimpleLog"/>
  +      <sysproperty key="org.apache.commons.logging.simplelog.defaultlog"
  +                 value="debug"/>
  +      <arg value="org.apache.commons.logging.simple.CustomConfigTestCase"/>
  +      <classpath refid="test.classpath"/>
  +    </java>
  +
  +  </target>
  +
   
     <target name="test.avalon" depends="compile.tests" if="avalon-framework.present"
      description="Run unit tests specific to Avalon (Framework) logging">
  
  
  
  1.12      +6 -5      jakarta-commons/logging/src/java/org/apache/commons/logging/impl/SimpleLog.java
  
  Index: SimpleLog.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/SimpleLog.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SimpleLog.java	16 Aug 2003 18:21:50 -0000	1.11
  +++ SimpleLog.java	16 Aug 2003 21:25:54 -0000	1.12
  @@ -63,6 +63,7 @@
   package org.apache.commons.logging.impl;
   
   import java.io.InputStream;
  +import java.io.Serializable;
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
   import java.security.AccessController;
  @@ -110,7 +111,7 @@
    *
    * @version $Id$
    */
  -public class SimpleLog implements Log {
  +public class SimpleLog implements Log, Serializable {
   
   
       // ------------------------------------------------------- Class Attributes
  
  
  
  1.1                  jakarta-commons/logging/src/test/org/apache/commons/logging/simple/CustomConfigTestCase.java
  
  Index: CustomConfigTestCase.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/logging/src/test/org/apache/commons/logging/simple/CustomConfigTestCase.java,v 1.1 2003/08/16 21:25:54 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2003/08/16 21:25:54 $
   *
   * ====================================================================
   *
   * 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.simple;
  
  
  import java.io.InputStream;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.logging.impl.SimpleLog;
  
  
  /**
   * <p>TestCase for sipmle logging when running with custom configuration
   * properties.</p>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2003/08/16 21:25:54 $
   */
  
  public class CustomConfigTestCase extends DefaultConfigTestCase {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * <p>Construct a new instance of this test case.</p>
       *
       * @param name Name of the test case
       */
      public CustomConfigTestCase(String name) {
          super(name);
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * <p>The expected log records.</p>
       */
      protected List expected;
  
  
      /**
       * <p>The message levels that should have been logged.</p>
       */
      /*
      protected Level testLevels[] =
      { Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE, Level.SEVERE };
      */
  
  
      /**
       * <p>The message strings that should have been logged.</p>
       */
      protected String testMessages[] =
      { "debug", "info", "warn", "error", "fatal" };
  
  
      // ------------------------------------------- JUnit Infrastructure Methods
  
  
      /**
       * Set up instance variables required by this test case.
       */
      public void setUp() throws Exception {
          expected = new ArrayList();
          setUpFactory();
          setUpLog("DecoratedLogger");
      }
  
  
      /**
       * Return the tests included in this test suite.
       */
      public static Test suite() {
          return (new TestSuite(CustomConfigTestCase.class));
      }
  
      /**
       * Tear down instance variables required by this test case.
       */
      public void tearDown() {
          super.tearDown();
          expected = null;
      }
  
  
      // ----------------------------------------------------------- Test Methods
  
  
      // Test logging message strings with exceptions
      public void testExceptionMessages() throws Exception {
  
          ((DecoratedSimpleLog) log).clearCache();
          logExceptionMessages();
          checkExpected();
  
      }
  
  
      // Test logging plain message strings
      public void testPlainMessages() throws Exception {
  
          ((DecoratedSimpleLog) log).clearCache();
          logPlainMessages();
          checkExpected();
  
      }
  
  
      // Test Serializability of standard instance
      public void testSerializable() throws Exception {
  
          ((DecoratedSimpleLog) log).clearCache();
          logPlainMessages();
          super.testSerializable();
          logExceptionMessages();
          checkExpected();
  
      }
  
  
      // -------------------------------------------------------- Support Methods
  
  
      // Check the decorated log instance
      protected void checkDecorated() {
  
          assertNotNull("Log exists", log);
          assertEquals("Log class",
                       "org.apache.commons.logging.simple.DecoratedSimpleLog",
                       log.getClass().getName());
  
          // Can we call level checkers with no exceptions?
          assertTrue(log.isDebugEnabled());
          assertTrue(log.isErrorEnabled());
          assertTrue(log.isFatalEnabled());
          assertTrue(log.isInfoEnabled());
          assertTrue(!log.isTraceEnabled());
          assertTrue(log.isWarnEnabled());
  
          // Can we retrieve the current log level?
          assertEquals(SimpleLog.LOG_LEVEL_DEBUG, ((SimpleLog) log).getLevel());
  
          // Can we validate the extra exposed properties?
          assertEquals("DecoratedLogger",
                       ((DecoratedSimpleLog) log).getLogName());
          assertTrue(!((DecoratedSimpleLog) log).getShowDateTime());
          assertTrue(((DecoratedSimpleLog) log).getShowShortName());
  
      }
  
  
      // Check the actual log records against the expected ones
      protected void checkExpected() {
  
          List acts = ((DecoratedSimpleLog) log).getCache();
          Iterator exps = expected.iterator();
          int n = 0;
          while (exps.hasNext()) {
              LogRecord exp = (LogRecord) exps.next();
              LogRecord act = (LogRecord) acts.get(n++);
              assertEquals("Row " + n + " type", exp.type, act.type);
              assertEquals("Row " + n + " message", exp.message, act.message);
              assertEquals("Row " + n + " throwable", exp.t, act.t);
          }
  
      }
  
  
      // Check the standard log instance
      protected void checkStandard() {
  
          checkDecorated();
  
      }
  
  
      // Log the messages with exceptions
      protected void logExceptionMessages() {
  
          // Generate log records
          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.fatal("fatal", t);
  
          // Record the log records we expect
          expected.add(new LogRecord(SimpleLog.LOG_LEVEL_DEBUG, "debug", t));
          expected.add(new LogRecord(SimpleLog.LOG_LEVEL_INFO, "info", t));
          expected.add(new LogRecord(SimpleLog.LOG_LEVEL_WARN, "warn", t));
          expected.add(new LogRecord(SimpleLog.LOG_LEVEL_ERROR, "error", t));
          expected.add(new LogRecord(SimpleLog.LOG_LEVEL_FATAL, "fatal", t));
  
      }
  
  
      // Log the plain messages
      protected void logPlainMessages() {
  
          // Generate log records
          log.trace("trace"); // Should not actually get logged
          log.debug("debug");
          log.info("info");
          log.warn("warn");
          log.error("error");
          log.fatal("fatal");
  
          // Record the log records we expect
          expected.add(new LogRecord(SimpleLog.LOG_LEVEL_DEBUG, "debug", null));
          expected.add(new LogRecord(SimpleLog.LOG_LEVEL_INFO, "info", null));
          expected.add(new LogRecord(SimpleLog.LOG_LEVEL_WARN, "warn", null));
          expected.add(new LogRecord(SimpleLog.LOG_LEVEL_ERROR, "error", null));
          expected.add(new LogRecord(SimpleLog.LOG_LEVEL_FATAL, "fatal", null));
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons/logging/src/test/org/apache/commons/logging/simple/DecoratedSimpleLog.java
  
  Index: DecoratedSimpleLog.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/logging/src/test/org/apache/commons/logging/simple/DecoratedSimpleLog.java,v 1.1 2003/08/16 21:25:54 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2003/08/16 21:25:54 $
   *
   * ====================================================================
   *
   * 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.simple;
  
  
  import java.util.ArrayList;
  import java.util.List;
  import org.apache.commons.logging.impl.SimpleLog;
  
  
  /**
   * <p>Decorated instance of SimpleLog to expose internal state and
   * support buffered output.</p>
   */
  
  public class DecoratedSimpleLog extends SimpleLog {
  
  
      // ------------------------------------------------------------ Constructor
  
  
      public DecoratedSimpleLog(String name) {
          super(name);
      }
  
  
      // ------------------------------------------------------------- Properties
  
  
      public String getLogName() {
          return (logName);
      }
  
  
      public boolean getShowDateTime() {
          return (showDateTime);
      }
  
  
      public boolean getShowShortName() {
          return (showShortName);
      }
  
  
      // ------------------------------------------------------- Protected Methods
  
  
      // Cache logged messages
      protected void log(int type, Object message, Throwable t) {
  
          super.log(type, message, t);
          cache.add(new LogRecord(type, message, t));
  
      }
  
  
      // ---------------------------------------------------------- Public Methods
  
  
      // Cache of logged records
      protected ArrayList cache = new ArrayList();
  
  
      // Clear cache
      public void clearCache() {
          cache.clear();
      }
  
  
      // Return cache
      public List getCache() {
          return (this.cache);
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons/logging/src/test/org/apache/commons/logging/simple/DefaultConfigTestCase.java
  
  Index: DefaultConfigTestCase.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/logging/src/test/org/apache/commons/logging/simple/DefaultConfigTestCase.java,v 1.1 2003/08/16 21:25:54 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2003/08/16 21:25:54 $
   *
   * ====================================================================
   *
   * 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.simple;
  
  
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.commons.logging.impl.SimpleLog;
  
  
  /**
   * <p>TestCase for simple logging when running with zero configuration
   * other than selecting the SimpleLog implementation.</p>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2003/08/16 21:25:54 $
   */
  
  public class DefaultConfigTestCase extends TestCase {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * <p>Construct a new instance of this test case.</p>
       *
       * @param name Name of the test case
       */
      public DefaultConfigTestCase(String name) {
          super(name);
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * <p>The {@link LogFactory} implementation we have selected.</p>
       */
      protected LogFactory factory = null;
  
  
      /**
       * <p>The {@link Log} implementation we have selected.</p>
       */
      protected Log log = null;
  
  
      // ------------------------------------------- JUnit Infrastructure Methods
  
  
      /**
       * Set up instance variables required by this test case.
       */
      public void setUp() throws Exception {
          setUpFactory();
          setUpLog("TestLogger");
      }
  
  
      /**
       * Return the tests included in this test suite.
       */
      public static Test suite() {
          return (new TestSuite(DefaultConfigTestCase.class));
      }
  
      /**
       * Tear down instance variables required by this test case.
       */
      public void tearDown() {
          log = null;
          factory = null;
          LogFactory.releaseAll();
      }
  
  
      // ----------------------------------------------------------- Test Methods
  
  
      // Test pristine DecoratedSimpleLog instance
      public void testPristineDecorated() {
  
          setUpDecorated("DecoratedLogger");
          checkDecorated();
  
      }
  
  
      // Test pristine Log instance
      public void testPristineLog() {
  
          checkStandard();
  
      }
  
  
      // Test pristine LogFactory instance
      public void testPristineFactory() {
  
          assertNotNull("LogFactory exists", factory);
          assertEquals("LogFactory class",
                       "org.apache.commons.logging.impl.LogFactoryImpl",
                       factory.getClass().getName());
  
          String names[] = factory.getAttributeNames();
          assertNotNull("Names exists", names);
          assertEquals("Names empty", 0, names.length);
  
      }
  
  
      // Test Serializability of standard instance
      public void testSerializable() throws Exception {
  
          // Serialize and deserialize the instance
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          ObjectOutputStream oos = new ObjectOutputStream(baos);
          oos.writeObject(log);
          oos.close();
          ByteArrayInputStream bais =
              new ByteArrayInputStream(baos.toByteArray());
          ObjectInputStream ois = new ObjectInputStream(bais);
          log = (Log) ois.readObject();
          ois.close();
  
          // Check the characteristics of the resulting object
          checkStandard();
  
      }
  
  
      // -------------------------------------------------------- Support Methods
  
  
  
      // Check the decorated log instance
      protected void checkDecorated() {
  
          assertNotNull("Log exists", log);
          assertEquals("Log class",
                       "org.apache.commons.logging.simple.DecoratedSimpleLog",
                       log.getClass().getName());
  
          // Can we call level checkers with no exceptions?
          assertTrue(!log.isDebugEnabled());
          assertTrue(log.isErrorEnabled());
          assertTrue(log.isFatalEnabled());
          assertTrue(log.isInfoEnabled());
          assertTrue(!log.isTraceEnabled());
          assertTrue(log.isWarnEnabled());
  
          // Can we retrieve the current log level?
          assertEquals(SimpleLog.LOG_LEVEL_INFO, ((SimpleLog) log).getLevel());
  
          // Can we validate the extra exposed properties?
          assertEquals("DecoratedLogger",
                       ((DecoratedSimpleLog) log).getLogName());
          assertTrue(!((DecoratedSimpleLog) log).getShowDateTime());
          assertTrue(((DecoratedSimpleLog) log).getShowShortName());
  
      }
  
  
      // Check the standard log instance
      protected void checkStandard() {
  
          assertNotNull("Log exists", log);
          assertEquals("Log class",
                       "org.apache.commons.logging.impl.SimpleLog",
                       log.getClass().getName());
  
          // Can we call level checkers with no exceptions?
          assertTrue(!log.isDebugEnabled());
          assertTrue(log.isErrorEnabled());
          assertTrue(log.isFatalEnabled());
          assertTrue(log.isInfoEnabled());
          assertTrue(!log.isTraceEnabled());
          assertTrue(log.isWarnEnabled());
  
          // Can we retrieve the current log level?
          assertEquals(SimpleLog.LOG_LEVEL_INFO, ((SimpleLog) log).getLevel());
  
      }
  
  
      // Set up decorated log instance
      protected void setUpDecorated(String name) {
          log = new DecoratedSimpleLog(name);
      }
  
  
      // Set up factory instance
      protected void setUpFactory() throws Exception {
          factory = LogFactory.getFactory();
      }
  
  
      // Set up log instance
      protected void setUpLog(String name) throws Exception {
          log = LogFactory.getLog(name);
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons/logging/src/test/org/apache/commons/logging/simple/LogRecord.java
  
  Index: LogRecord.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/logging/src/test/org/apache/commons/logging/simple/LogRecord.java,v 1.1 2003/08/16 21:25:54 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2003/08/16 21:25:54 $
   *
   * ====================================================================
   *
   * 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.simple;
  
  
  import java.io.Serializable;
  
  
  public class LogRecord implements Serializable {
  
  
      public LogRecord(int type, Object message, Throwable t) {
          this.type = type;
          this.message = message;
          this.t = t;
      }
  
      public int type;
      public Object message;
      public Throwable t;
  
  }
  
  
  

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