Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 1099 invoked from network); 28 Mar 2005 10:37:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 28 Mar 2005 10:37:46 -0000 Received: (qmail 78090 invoked by uid 500); 28 Mar 2005 10:37:18 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 77918 invoked by uid 500); 28 Mar 2005 10:37:16 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 77223 invoked by uid 500); 28 Mar 2005 10:37:11 -0000 Received: (qmail 76679 invoked by uid 99); 28 Mar 2005 10:37:09 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 28 Mar 2005 02:37:05 -0800 Received: (qmail 448 invoked by uid 65534); 28 Mar 2005 10:37:04 -0000 Message-ID: <20050328103704.447.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Mon, 28 Mar 2005 10:37:03 -0000 Subject: svn commit: r159228 [4/6] - in jakarta/commons/proper/logging/branches/DON_QUIXOTE: ./ classic/ classic/src/ classic/src/conf/ classic/src/java/ classic/src/java/org/ classic/src/java/org/apache/ classic/src/java/org/apache/commons/ classic/src/java/org/apache/commons/logging/ classic/src/java/org/apache/commons/logging/impl/ classic/src/media/ classic/src/test/ classic/src/test/org/ classic/src/test/org/apache/ classic/src/test/org/apache/commons/ classic/src/test/org/apache/commons/logging/ classic/src/test/org/apache/commons/logging/avalon/ classic/src/test/org/apache/commons/logging/jdk14/ classic/src/test/org/apache/commons/logging/log4j/ classic/src/test/org/apache/commons/logging/simple/ classic/xdocs/ classic/xdocs/images/ kernel/ kernel/src/ kernel/src/conf/ kernel/src/java/ kernel/src/java/org/ kernel/src/java/org/apache/ kernel/src/java/org/apache/commons/ kernel/src/java/org/apache/commons/logging/ kernel/src/java/org/apache/commons/logging/impl/ kernel/src/media/ kernel/src/test/ kernel/src/test/org/ kernel/src/test/org/apache/ kernel/src/test/org/apache/commons/ kernel/src/test/org/apache/commons/logging/ To: commons-cvs@jakarta.apache.org From: rdonkin@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/LogTest.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/LogTest.java?view= =3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/LogTest.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/LogTest.java Mon Mar 28 02:36:50 2005 @@ -0,0 +1,71 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 +=20 +package org.apache.commons.logging; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + *=20 + * + *=20 + *=20 + *=20 + *=20 + */ +public class LogTest extends AbstractLogTest +{ + + /** + *=20 + *=20 + * @param testName + *=20 + */ + public LogTest(String testName) + { + super(testName); + } + + /** + *=20 + *=20 + *=20 + */ + public Log getLogObject() + { + /** + * Pickup whatever is found/configured! + */ + return LogFactory.getLog(this.getClass().getName()); + } + + public static void main(String[] args) + { + String[] testCaseName =3D { LogTest.class.getName() }; + junit.textui.TestRunner.main(testCaseName); =20 + } + =20 + public static Test suite() { + TestSuite suite =3D new TestSuite(); + =20 + suite.addTestSuite(LogTest.class); + =20 + return suite; + } + =20 +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/NoOpLogTest.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/NoOpLogTest.java?vi= ew=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/NoOpLogTest.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/NoOpLogTest.java Mon Mar 28 02:36:50 2005 @@ -0,0 +1,68 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 +=20 +package org.apache.commons.logging; + +import org.apache.commons.logging.impl.NoOpLog; +import junit.framework.*; + +/** + *=20 + * + *=20 + *=20 + *=20 + *=20 + */ +public class NoOpLogTest extends AbstractLogTest +{ + + /** + *=20 + *=20 + * @param testName + *=20 + */ + public NoOpLogTest(String testName) + { + super(testName); + } + + /** + *=20 + *=20 + *=20 + */ + public Log getLogObject() + { + return (Log) new NoOpLog(this.getClass().getName()); + } + + public static void main(String[] args) + { + String[] testCaseName =3D { NoOpLogTest.class.getName() }; + junit.textui.TestRunner.main(testCaseName);=09 + } +=09 + public static Test suite() { + TestSuite suite =3D new TestSuite(); + =20 + suite.addTestSuite(NoOpLogTest.class); + =20 + return suite; + } +=09 +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/SimpleLogTest.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/SimpleLogTest.java?= view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/SimpleLogTest.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/SimpleLogTest.java Mon Mar 28 02:36:50 2005 @@ -0,0 +1,68 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 +=20 + package org.apache.commons.logging; + +import org.apache.commons.logging.impl.SimpleLog; +import junit.framework.*; + +/** + *=20 + * + *=20 + *=20 + *=20 + *=20 + */ +public class SimpleLogTest extends AbstractLogTest +{ + + /** + *=20 + *=20 + * @param testName + *=20 + */ + public SimpleLogTest(String testName) + { + super(testName); + } + + /** + *=20 + *=20 + *=20 + */ + public Log getLogObject() + { + return (Log) new SimpleLog(this.getClass().getName()); + } + + public static void main(String[] args) + { + String[] testCaseName =3D { SimpleLogTest.class.getName() }; + junit.textui.TestRunner.main(testCaseName);=09 + } +=09 + public static Test suite() { + TestSuite suite =3D new TestSuite(); + =20 + suite.addTestSuite(SimpleLogTest.class); + =20 + return suite; + } +=09 +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/TestAll.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/TestAll.java?view= =3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/TestAll.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/TestAll.java Mon Mar 28 02:36:50 2005 @@ -0,0 +1,58 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 +=20 +=20 +package org.apache.commons.logging; + +import junit.framework.*; + + +/** + *

The build script calls just one TestSuite - this one! + * All tests should be written into separate TestSuite's + * and added to this. Don't clutter this class with implementations.

+ * + *

This class is based on org.apache.commons.betwixt.TestAll=20 + * coded by James Strachan.

+ * + * @author Robert Burrell Donkin + * @version $Revision: 1.7 $ + */ +public class TestAll extends TestCase { + + public TestAll(String testName) { + super(testName); + } + + =20 + public static Test suite() { + TestSuite suite =3D new TestSuite(); + =20 + suite.addTest(SimpleLogTest.suite()); + suite.addTest(NoOpLogTest.suite()); + suite.addTest(LogTest.suite()); + =20 + return suite; + } + + /** + * This allows the tests to run as a standalone application. + */ + public static void main(String args[]) { + String[] testCaseName =3D { TestAll.class.getName() }; + junit.textui.TestRunner.main(testCaseName); + } +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/UserClass.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/UserClass.java?view= =3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/UserClass.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/UserClass.java Mon Mar 28 02:36:50 2005 @@ -0,0 +1,27 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 +=20 +package org.apache.commons.logging; + +public class UserClass { + =20 + =20 +=20 + public UserClass() { + Log log =3D LogFactory.getLog(LoadTest.class); + } + =20 +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/Wrapper.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/Wrapper.java?view= =3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/Wrapper.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/Wrapper.java Mon Mar 28 02:36:50 2005 @@ -0,0 +1,155 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 + +package org.apache.commons.logging; + + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.List; + + +/** + *

Wrapper around test cases that need to have a custom class loader + * hierarchy assembled. The wrapper is configured by the following + * system properties:

+ *
    + *
  • wrapper.hierarchy - Descriptive code describing how + * the class loader hierarchy should be assembled: + *
      + *
    • API - Parent class loader contains + * commons-logging-api.jar and child class loader + * contains commons-logging.jar. This is like the + * default configuration for Tomcat 4.1.
    • + *
    • FULL - Parent class loader contains + * commons-logging.jar. This is what would happen + * if you replaced commons-logging-api.jar with + * commons-logging.jar so that you did not need to + * include the latter with your application.
    • + *
    + * The child class loader also unconditionally includes + * commons-logging-tests.jar.
  • + *
  • wrapper.junit - Fully qualified pathname of the + * JUnit JAR file.
  • + *
  • wrapper.log4j - Fully qualified pathname of the + * Log4J JAR file, which will be placed in whichever class loader + * commons-logging.jar is placed in, if specified.
  • + *
  • wrapper.target - Fully qualified pathname of the + * "target" directory created by the build process. This directory + * must contain the commons-logging.jar, + * commons-logging-api.jar, and + * commons-logging-tests.jar files resulting from the + * execution of the compile.tests target.
  • + *
  • wrapper.testcase - Fully qualified Java class name + * of a TestCase that will ultimately be executed. This class must + * exist in the commons-logging-tests.jar file.
  • + *
+ * + *

When executed, the system classpath for the wrapper should include + * only the wrapper class itself.

+ * + * @author Craig R. McClanahan + * @version $Revision: 1.5 $ $Date: 2004-02-28 21:46:46 +0000 (Sat, 28 Feb= 2004) $ + */ + +public class Wrapper { + + + public static void main(String args[]) { + + try { + + // Create variables we will need + List parentList =3D new ArrayList(); + List childList =3D new ArrayList(); + URL urls[] =3D null; + + // Construct URLs for the various JAR files + File target =3D new File(System.getProperty("wrapper.target")); + URL commonsLogging =3D + (new File(target, "commons-logging.jar")).toURL(); + URL commonsLoggingApi =3D + (new File(target, "commons-logging-api.jar")).toURL(); + URL commonsLoggingKernel =3D + (new File(target, "commons-logging-kernel.jar")).toURL(); + URL commonsLoggingTests =3D + (new File(target, "commons-logging-tests.jar")).toURL(); + URL junit =3D + (new File(System.getProperty("wrapper.junit"))).toURL(); + URL appender =3D null; + URL log4j =3D null; + if (System.getProperty("wrapper.log4j") !=3D null) { + log4j =3D + (new File(System.getProperty("wrapper.log4j"))).toURL(= ); + appender =3D + (new File(target, "commons-logging-appender.jar")).toU= RL(); + } + + // Construct class loader repository lists for supported scena= rios + if ("API".equals(System.getProperty("wrapper.hierarchy"))) { + parentList.add(commonsLoggingApi); + parentList.add(commonsLoggingKernel); + childList.add(commonsLogging); + if (log4j !=3D null) { + childList.add(log4j); + childList.add(appender); + } + } else { // Assumes "FULL" + parentList.add(commonsLogging); + parentList.add(commonsLoggingKernel); + if (log4j !=3D null) { + parentList.add(log4j); + childList.add(appender); + } + } + childList.add(commonsLoggingTests); + childList.add(junit); + + // Construt the parent and child class loaders + urls =3D (URL[]) parentList.toArray(new URL[parentList.size()]= ); + ClassLoader parent =3D + new URLClassLoader(urls, + ClassLoader.getSystemClassLoader()); + urls =3D (URL[]) childList.toArray(new URL[childList.size()]); + ClassLoader child =3D new URLClassLoader(urls, parent); + + // Execute the test runner for this TestCase + ClassLoader old =3D Thread.currentThread().getContextClassLoad= er(); + Thread.currentThread().setContextClassLoader(child); + Class clazz =3D child.loadClass("junit.textui.TestRunner"); + String params[] =3D new String[1]; + params[0] =3D System.getProperty("wrapper.testcase"); + Method method =3D clazz.getMethod("main", + new Class[] { params.getClass(= ) }); + method.invoke(null, new Object[] { params }); + Thread.currentThread().setContextClassLoader(old); + + } catch (Exception e) { + + System.out.println("Wrapper Exception Occurred: " + e); + e.printStackTrace(System.out); + System.exit(1); + + } + + } + + + +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/avalon/AvalonLoggerTest.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/avalon/AvalonLogger= Test.java?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/avalon/AvalonLoggerTest.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/avalon/AvalonLoggerTest.java Mon Mar 28 02:36:50 2= 005 @@ -0,0 +1,51 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 +package org.apache.commons.logging.avalon; + +import org.apache.avalon.framework.logger.ConsoleLogger; +import org.apache.commons.logging.impl.AvalonLogger; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.AbstractLogTest; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * @author Neeme Praks + * @version $Revision: 1.4 $ $Date: 2004-02-28 21:46:46 +0000 (Sat, 28 Feb= 2004) $ + */ +public class AvalonLoggerTest extends AbstractLogTest { + + public static void main(String[] args) { + String[] testCaseName =3D { AvalonLoggerTest.class.getName() }; + junit.textui.TestRunner.main(testCaseName);=09 + } + + public static Test suite() { + TestSuite suite =3D new TestSuite(); + suite.addTestSuite(AvalonLoggerTest.class); + return suite; + } + + public AvalonLoggerTest(String testName) { + super(testName); + } + + public Log getLogObject() { + Log log =3D new AvalonLogger(new ConsoleLogger()); + return log; + } +} \ No newline at end of file Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/jdk14/CustomConfig.properties URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/jdk14/CustomConfig.= properties?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/jdk14/CustomConfig.properties (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/jdk14/CustomConfig.properties Mon Mar 28 02:36:50 = 2005 @@ -0,0 +1,24 @@ +# Copyright 2001-2004 The Apache Software Foundation. +#=20 +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +#=20 +# http://www.apache.org/licenses/LICENSE-2.0 +#=20 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# This is the custom configuration properties for the JDK 1.4 logger tests +# in CustomConfigTestCase. + +# Configure the Handler so we can examine the logged messages +handlers =3D org.apache.commons.logging.jdk14.TestHandler + +# Configre the default logging level to be FINE so we should get +# everything except trace messages +=2Elevel =3D FINE Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/jdk14/CustomConfigTestCase.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/jdk14/CustomConfigT= estCase.java?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/jdk14/CustomConfigTestCase.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/jdk14/CustomConfigTestCase.java Mon Mar 28 02:36:5= 0 2005 @@ -0,0 +1,302 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 + +package org.apache.commons.logging.jdk14; + + +import java.io.InputStream; +import java.util.Iterator; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogManager; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +import junit.framework.Test; +import junit.framework.TestSuite; + + +/** + *

TestCase for JDK 1.4 logging when running on a JDK 1.4 system with + * custom configuration, so that JDK 1.4 should be selected and an appropr= iate + * logger configured per the configuration properties.

+ * + * @author Craig R. McClanahan + * @version $Revision: 1.9 $ $Date: 2004-02-28 21:46:46 +0000 (Sat, 28 Feb= 2004) $ + */ + +public class CustomConfigTestCase extends DefaultConfigTestCase { + + + // ----------------------------------------------------------- Constru= ctors + + + /** + *

Construct a new instance of this test case.

+ * + * @param name Name of the test case + */ + public CustomConfigTestCase(String name) { + super(name); + } + + + // ----------------------------------------------------- Instance Vari= ables + + + /** + *

The customized Handler we will be using.

+ */ + protected TestHandler handler =3D null; + + + /** + *

The underlying Handlers we will be using.

+ */ + protected Handler handlers[] =3D null; + + + /** + *

The underlying Logger we will be using.

+ */ + protected Logger logger =3D null; + + + /** + *

The underlying LogManager we will be using.

+ */ + protected LogManager manager =3D null; + + + /** + *

The message levels that should have been logged.

+ */ + protected Level testLevels[] =3D + { Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE, Level.SEVERE }; + + + /** + *

The message strings that should have been logged.

+ */ + protected String testMessages[] =3D + { "debug", "info", "warn", "error", "fatal" }; + + + // ------------------------------------------- JUnit Infrastructure Me= thods + + + /** + * Set up instance variables required by this test case. + */ + public void setUp() throws Exception { + setUpManager + ("org/apache/commons/logging/jdk14/CustomConfig.properties"); + setUpLogger("TestLogger"); + setUpHandlers(); + setUpFactory(); + setUpLog("TestLogger"); + } + + + /** + * 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(); + handlers =3D null; + logger =3D null; + manager =3D null; + } + + + // ----------------------------------------------------------- Test Me= thods + + + // 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(); + checkLogRecords(false); + + } + + + // Test pristine Handlers instances + public void testPristineHandlers() { + + assertNotNull(handlers); + assertEquals(1, handlers.length); + assertTrue(handlers[0] instanceof TestHandler); + assertNotNull(handler); + + } + + + // Test pristine Logger instance + public void testPristineLogger() { + + assertNotNull("Logger exists", logger); + assertEquals("Logger name", "TestLogger", logger.getName()); + + // Assert which logging levels have been enabled + assertTrue(logger.isLoggable(Level.SEVERE)); + assertTrue(logger.isLoggable(Level.WARNING)); + assertTrue(logger.isLoggable(Level.INFO)); + assertTrue(logger.isLoggable(Level.CONFIG)); + assertTrue(logger.isLoggable(Level.FINE)); + assertTrue(!logger.isLoggable(Level.FINER)); + assertTrue(!logger.isLoggable(Level.FINEST)); + + } + + + // Test Serializability of Log instance + public void testSerializable() throws Exception { + + super.testSerializable(); + testExceptionMessages(); + + } + + + // -------------------------------------------------------- Support Me= thods + + + // Check the log instance + protected void checkLog() { + + assertNotNull("Log exists", log); + assertEquals("Log class", + "org.apache.commons.logging.impl.Jdk14Logger", + log.getClass().getName()); + + // Assert which logging levels have been enabled + assertTrue(log.isFatalEnabled()); + assertTrue(log.isErrorEnabled()); + assertTrue(log.isWarnEnabled()); + assertTrue(log.isInfoEnabled()); + assertTrue(log.isDebugEnabled()); + assertTrue(!log.isTraceEnabled()); + + } + + + // Check the recorded messages + protected void checkLogRecords(boolean thrown) { + Iterator records =3D handler.records(); + for (int i =3D 0; i < testMessages.length; i++) { + assertTrue(records.hasNext()); + LogRecord record =3D (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 IndexOutOfBoundsE= xception); + } else { + assertNull("LogRecord thrown", + record.getThrown()); + } + } + assertTrue(!records.hasNext()); + handler.flush(); + } + + + // Log the messages with exceptions + protected void logExceptionMessages() { + Throwable t =3D 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); + } + + + // Log the plain messages + protected void logPlainMessages() { + log.trace("trace"); // Should not actually get logged + log.debug("debug"); + log.info("info"); + log.warn("warn"); + log.error("error"); + log.fatal("fatal"); + } + + + // Set up handlers instance + protected void setUpHandlers() throws Exception { + Logger parent =3D logger; + while (parent.getParent() !=3D null) { + parent =3D parent.getParent(); + } + handlers =3D parent.getHandlers(); + if ((handlers !=3D null) && (handlers.length =3D=3D 1) && + (handlers[0] instanceof TestHandler)) { + handler =3D (TestHandler) handlers[0]; + } + } + + + // Set up logger instance + protected void setUpLogger(String name) throws Exception { + logger =3D Logger.getLogger(name); + } + + + // Set up LogManager instance + protected void setUpManager(String config) throws Exception { + manager =3D LogManager.getLogManager(); + InputStream is =3D + this.getClass().getClassLoader().getResourceAsStream(config); + manager.readConfiguration(is); + is.close(); + } + + +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/jdk14/DefaultConfigTestCase.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/jdk14/DefaultConfig= TestCase.java?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/jdk14/DefaultConfigTestCase.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/jdk14/DefaultConfigTestCase.java Mon Mar 28 02:36:= 50 2005 @@ -0,0 +1,183 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 + +package org.apache.commons.logging.jdk14; + + +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; + + +/** + *

TestCase for JDK 1.4 logging when running on a JDK 1.4 system with + * zero configuration, and with Log4J not present (so JDK 1.4 logging + * should be automatically configured.

+ * + * @author Craig R. McClanahan + * @version $Revision: 1.8 $ $Date: 2004-02-28 21:46:46 +0000 (Sat, 28 Feb= 2004) $ + */ + +public class DefaultConfigTestCase extends TestCase { + + + // ----------------------------------------------------------- Constru= ctors + + + /** + *

Construct a new instance of this test case.

+ * + * @param name Name of the test case + */ + public DefaultConfigTestCase(String name) { + super(name); + } + + + // ----------------------------------------------------- Instance Vari= ables + + + /** + *

The {@link LogFactory} implementation we have selected.

+ */ + protected LogFactory factory =3D null; + + + /** + *

The {@link Log} implementation we have selected.

+ */ + protected Log log =3D null; + + + // ------------------------------------------- JUnit Infrastructure Me= thods + + + /** + * 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 =3D null; + factory =3D null; + LogFactory.releaseAll(); + } + + + // ----------------------------------------------------------- Test Me= thods + + + // Test pristine Log instance + public void testPristineLog() { + + checkLog(); + + } + + + // 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[] =3D factory.getAttributeNames(); + assertNotNull("Names exists", names); + assertEquals("Names empty", 0, names.length); + + } + + + // Test Serializability of Log instance + public void testSerializable() throws Exception { + + // Serialize and deserialize the instance + ByteArrayOutputStream baos =3D new ByteArrayOutputStream(); + ObjectOutputStream oos =3D new ObjectOutputStream(baos); + oos.writeObject(log); + oos.close(); + ByteArrayInputStream bais =3D + new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream ois =3D new ObjectInputStream(bais); + log =3D (Log) ois.readObject(); + ois.close(); + + // Check the characteristics of the resulting object + checkLog(); + + } + + + // -------------------------------------------------------- Support Me= thods + + + + // Check the log instance + protected void checkLog() { + + assertNotNull("Log exists", log); + assertEquals("Log class", + "org.apache.commons.logging.impl.Jdk14Logger", + log.getClass().getName()); + + // Can we call level checkers with no exceptions? + log.isDebugEnabled(); + log.isErrorEnabled(); + log.isFatalEnabled(); + log.isInfoEnabled(); + log.isTraceEnabled(); + log.isWarnEnabled(); + + } + + + // Set up factory instance + protected void setUpFactory() throws Exception { + factory =3D LogFactory.getFactory(); + } + + + // Set up log instance + protected void setUpLog(String name) throws Exception { + log =3D LogFactory.getLog(name); + } + + +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/jdk14/TestHandler.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/jdk14/TestHandler.j= ava?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/jdk14/TestHandler.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/jdk14/TestHandler.java Mon Mar 28 02:36:50 2005 @@ -0,0 +1,69 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 +package org.apache.commons.logging.jdk14; + + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.logging.Handler; +import java.util.logging.LogRecord; + + +/** + *

Test implementation of java.util.logging.Handler.

+ * + * @author Craig R. McClanahan + * @version $Revision: 1.4 $ $Date: 2004-02-28 21:46:46 +0000 (Sat, 28 Feb= 2004) $ + */ + +public class TestHandler extends Handler { + + + + // ----------------------------------------------------- Instance Vari= ables + + + // The set of logged records for this handler + private List records =3D new ArrayList(); + + + // --------------------------------------------------------- Public Me= thods + + + public Iterator records() { + return (records.iterator()); + } + + + // -------------------------------------------------------- Handler Me= thods + + + public void close() { + } + + + public void flush() { + records.clear(); + } + + + public void publish(LogRecord record) { + records.add(record); + } + + +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/log4j/CustomConfig.properties URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/log4j/CustomConfig.= properties?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/log4j/CustomConfig.properties (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/log4j/CustomConfig.properties Mon Mar 28 02:36:50 = 2005 @@ -0,0 +1,23 @@ +# Copyright 2001-2004 The Apache Software Foundation. +#=20 +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +#=20 +# http://www.apache.org/licenses/LICENSE-2.0 +#=20 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# This is the custom configuration properties for the Log4J logger tests +# in CustomConfigTestCase. + +# Configure the root logger's level and appender +log4j.rootLogger =3D INFO, A1 + +# Configure the default appender +log4j.appender.A1 =3D org.apache.commons.logging.log4j.TestAppender Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/log4j/CustomConfigTestCase.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/log4j/CustomConfigT= estCase.java?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/log4j/CustomConfigTestCase.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/log4j/CustomConfigTestCase.java Mon Mar 28 02:36:5= 0 2005 @@ -0,0 +1,283 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 + +package org.apache.commons.logging.log4j; + + +import java.io.InputStream; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.Properties; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; +import org.apache.log4j.spi.LoggingEvent; + + +/** + *

TestCase for Log4J logging when running on a system with Log4J prese= nt, + * so that Log4J should be selected and an appropriate + * logger configured per the configuration properties.

+ * + * @author Craig R. McClanahan + * @version $Revision: 1.9 $ $Date: 2004-05-19 21:59:56 +0100 (Wed, 19 May= 2004) $ + */ + +public class CustomConfigTestCase extends DefaultConfigTestCase { + + + // ----------------------------------------------------------- Constru= ctors + + + /** + *

Construct a new instance of this test case.

+ * + * @param name Name of the test case + */ + public CustomConfigTestCase(String name) { + super(name); + } + + + // ----------------------------------------------------- Instance Vari= ables + + + /** + *

The Appender we are utilizing.

+ */ + protected TestAppender appender =3D null; + + + /** + *

The Logger we are utilizing.

+ */ + protected Logger logger =3D null; + + + /** + *

The message levels that should have been logged.

+ */ + protected Level testLevels[] =3D + { Level.INFO, Level.WARN, Level.ERROR, Level.FATAL }; + + + /** + *

The message strings that should have been logged.

+ */ + protected String testMessages[] =3D + { "info", "warn", "error", "fatal" }; + + + // ------------------------------------------- JUnit Infrastructure Me= thods + + + /** + * Set up instance variables required by this test case. + */ + public void setUp() throws Exception { + setUpAppender + ("org/apache/commons/logging/log4j/CustomConfig.properties"); + setUpLogger("TestLogger"); + setUpFactory(); + setUpLog("TestLogger"); + } + + + /** + * 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(); + Logger.getRootLogger().removeAppender(appender); + appender =3D null; + logger =3D null; + } + + + // ----------------------------------------------------------- Test Me= thods + + + // Test logging message strings with exceptions + public void testExceptionMessages() throws Exception { + + logExceptionMessages(); + checkLoggingEvents(true); + + } + + + // Test logging plain message strings + public void testPlainMessages() throws Exception { + + logPlainMessages(); + checkLoggingEvents(false); + + } + + + // Test pristine Appender instance + public void testPristineAppender() { + + assertNotNull("Appender exists", appender); + + } + + + // Test pristine Log instance + public void testPristineLog() { + + super.testPristineLog(); + + } + + + // Test pristine Logger instance + public void testPristineLogger() { + + assertNotNull("Logger exists", logger); + assertEquals("Logger level", Level.INFO, logger.getEffectiveLevel(= )); + assertEquals("Logger name", "TestLogger", logger.getName()); + + } + + + // Test Serializability of Log instance + public void testSerializable() throws Exception { + + super.testSerializable(); + testExceptionMessages(); + + } + + + // -------------------------------------------------------- Support Me= thods + + + // Check the log instance + protected void checkLog() { + + assertNotNull("Log exists", log); + assertEquals("Log class", + "org.apache.commons.logging.impl.Log4JLogger", + log.getClass().getName()); + + // Assert which logging levels have been enabled + assertTrue(log.isErrorEnabled()); + assertTrue(log.isWarnEnabled()); + assertTrue(log.isInfoEnabled()); + assertTrue(!log.isDebugEnabled()); + assertTrue(!log.isTraceEnabled()); + + } + + + // Check the recorded messages + protected void checkLoggingEvents(boolean thrown) { + Iterator events =3D appender.events(); + for (int i =3D 0; i < testMessages.length; i++) { + assertTrue("Logged event " + i + " exists",events.hasNext()); + LoggingEvent event =3D (LoggingEvent) events.next(); + assertEquals("LoggingEvent level", + testLevels[i], event.getLevel()); + assertEquals("LoggingEvent message", + testMessages[i], event.getMessage()); + /* Does not appear to be logged correctly? + assertEquals("LoggingEvent class", + this.getClass().getName(), + event.getLocationInformation().getClassName()); + */ + /* Does not appear to be logged correctly? + if (thrown) { + assertEquals("LoggingEvent method", + "logExceptionMessages", + event.getLocationInformation().getMethodName(= )); + } else { + assertEquals("LoggingEvent method", + "logPlainMessages", + event.getLocationInformation().getMethodName(= )); + } + */ + if (thrown) { + assertNotNull("LoggingEvent thrown", + event.getThrowableInformation().getThrowable= StrRep()); + assertTrue("LoggingEvent thrown type", + event.getThrowableInformation() + .getThrowableStrRep()[0] + .indexOf("IndexOutOfBoundsException")>= 0); + } else { + assertNull("LoggingEvent thrown", + event.getThrowableInformation()); + } + } + assertTrue(!events.hasNext()); + appender.flush(); + } + + + // Log the messages with exceptions + protected void logExceptionMessages() { + Throwable t =3D new IndexOutOfBoundsException(); + log.trace("trace", t); // Should not actually get logged + log.debug("debug", t); // Should not actually get logged + log.info("info", t); + log.warn("warn", t); + log.error("error", t); + log.fatal("fatal", t); + } + + + // Log the plain messages + protected void logPlainMessages() { + log.trace("trace"); // Should not actually get logged + log.debug("debug"); // Should not actually get logged + log.info("info"); + log.warn("warn"); + log.error("error"); + log.fatal("fatal"); + } + + + // Set up our custom Appender + protected void setUpAppender(String config) throws Exception { + Properties props =3D new Properties(); + InputStream is =3D + this.getClass().getClassLoader().getResourceAsStream(config); + props.load(is); + is.close(); + PropertyConfigurator.configure(props); + Enumeration appenders =3D Logger.getRootLogger().getAllAppenders(); + appender =3D (TestAppender) appenders.nextElement(); + } + + + // Set up our custom Logger + protected void setUpLogger(String name) throws Exception { + logger =3D Logger.getLogger(name); + } + + +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/log4j/DefaultConfigTestCase.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/log4j/DefaultConfig= TestCase.java?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/log4j/DefaultConfigTestCase.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/log4j/DefaultConfigTestCase.java Mon Mar 28 02:36:= 50 2005 @@ -0,0 +1,183 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 + +package org.apache.commons.logging.log4j; + + +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; + + +/** + *

TestCase for Log4J logging when running on a system with + * zero configuration, and with Log4J present (so Log4J logging + * should be automatically configured).

+ * + * @author Craig R. McClanahan + * @version $Revision: 1.7 $ $Date: 2004-02-28 21:46:46 +0000 (Sat, 28 Feb= 2004) $ + */ + +public class DefaultConfigTestCase extends TestCase { + + + // ----------------------------------------------------------- Constru= ctors + + + /** + *

Construct a new instance of this test case.

+ * + * @param name Name of the test case + */ + public DefaultConfigTestCase(String name) { + super(name); + } + + + // ----------------------------------------------------- Instance Vari= ables + + + /** + *

The {@link LogFactory} implementation we have selected.

+ */ + protected LogFactory factory =3D null; + + + /** + *

The {@link Log} implementation we have selected.

+ */ + protected Log log =3D null; + + + // ------------------------------------------- JUnit Infrastructure Me= thods + + + /** + * 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 =3D null; + factory =3D null; + LogFactory.releaseAll(); + } + + + // ----------------------------------------------------------- Test Me= thods + + + // Test pristine Log instance + public void testPristineLog() { + + checkLog(); + + } + + + // 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[] =3D factory.getAttributeNames(); + assertNotNull("Names exists", names); + assertEquals("Names empty", 0, names.length); + + } + + + // Test Serializability of Log instance + public void testSerializable() throws Exception { + + // Serialize and deserialize the instance + ByteArrayOutputStream baos =3D new ByteArrayOutputStream(); + ObjectOutputStream oos =3D new ObjectOutputStream(baos); + oos.writeObject(log); + oos.close(); + ByteArrayInputStream bais =3D + new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream ois =3D new ObjectInputStream(bais); + log =3D (Log) ois.readObject(); + ois.close(); + + // Check the characteristics of the resulting object + checkLog(); + + } + + + // -------------------------------------------------------- Support Me= thods + + + + // Check the log instance + protected void checkLog() { + + assertNotNull("Log exists", log); + assertEquals("Log class", + "org.apache.commons.logging.impl.Log4JLogger", + log.getClass().getName()); + + // Can we call level checkers with no exceptions? + log.isDebugEnabled(); + log.isErrorEnabled(); + log.isFatalEnabled(); + log.isInfoEnabled(); + log.isTraceEnabled(); + log.isWarnEnabled(); + + } + + + // Set up factory instance + protected void setUpFactory() throws Exception { + factory =3D LogFactory.getFactory(); + } + + + // Set up log instance + protected void setUpLog(String name) throws Exception { + log =3D LogFactory.getLog(name); + } + + +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/log4j/TestAppender.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/log4j/TestAppender.= java?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/log4j/TestAppender.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/log4j/TestAppender.java Mon Mar 28 02:36:50 2005 @@ -0,0 +1,75 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 + +package org.apache.commons.logging.log4j; + + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import org.apache.log4j.AppenderSkeleton; +import org.apache.log4j.spi.LoggingEvent; + + +/** + *

Test implementation of org.apache.log4j.Appender.

+ * + * @author Craig R. McClanahan + * @version $Revision: 1.4 $ $Date: 2004-02-28 21:46:46 +0000 (Sat, 28 Feb= 2004) $ + */ + +public class TestAppender extends AppenderSkeleton { + + + + // ----------------------------------------------------- Instance Vari= ables + + + // The set of logged events for this appender + private List events =3D new ArrayList(); + + + // --------------------------------------------------------- Public Me= thods + + + public Iterator events() { + return (events.iterator()); + } + + + public void flush() { + events.clear(); + } + + + // ------------------------------------------------------- Appender Me= thods + + + protected void append(LoggingEvent event) { + events.add(event); + } + + + public void close() { + } + + + public boolean requiresLayout() { + return (false); + } + + +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/simple/CustomConfigTestCase.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/simple/CustomConfig= TestCase.java?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/simple/CustomConfigTestCase.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/simple/CustomConfigTestCase.java Mon Mar 28 02:36:= 50 2005 @@ -0,0 +1,254 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 + +package org.apache.commons.logging.simple; + + +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; + + +/** + *

TestCase for simple logging when running with custom configuration + * properties.

+ * + * @author Craig R. McClanahan + * @version $Revision: 1.6 $ $Date: 2004-05-30 11:32:25 +0100 (Sun, 30 May= 2004) $ + */ +public class CustomConfigTestCase extends DefaultConfigTestCase { + + + // ----------------------------------------------------------- Constru= ctors + + + /** + *

Construct a new instance of this test case.

+ * + * @param name Name of the test case + */ + public CustomConfigTestCase(String name) { + super(name); + } + + + // ----------------------------------------------------- Instance Vari= ables + + + /** + *

The expected log records.

+ */ + protected List expected; + + + /** + *

The message levels that should have been logged.

+ */ + /* + protected Level testLevels[] =3D + { Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE, Level.SEVERE }; + */ + + + /** + *

The message strings that should have been logged.

+ */ + protected String testMessages[] =3D + { "debug", "info", "warn", "error", "fatal" }; + + + // ------------------------------------------- JUnit Infrastructure Me= thods + + + /** + * Set up instance variables required by this test case. + */ + public void setUp() throws Exception { + expected =3D 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 =3D null; + } + + + // ----------------------------------------------------------- Test Me= thods + + + // 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 Me= thods + + + // 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? + checkDecoratedDateTime(); + assertEquals("DecoratedLogger", + ((DecoratedSimpleLog) log).getLogName()); + checkShowDateTime(); + assertTrue(((DecoratedSimpleLog) log).getShowShortName()); + + } + =20 + /** Hook for subclassses */ + protected void checkShowDateTime() { + assertTrue(!((DecoratedSimpleLog) log).getShowDateTime()); + } + =20 + /** Hook for subclasses */ + protected void checkDecoratedDateTime() { + assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz", + ((DecoratedSimpleLog) log).getDateTimeFormat()); + } + =20 + + + // Check the actual log records against the expected ones + protected void checkExpected() { + + List acts =3D ((DecoratedSimpleLog) log).getCache(); + Iterator exps =3D expected.iterator(); + int n =3D 0; + while (exps.hasNext()) { + LogRecord exp =3D (LogRecord) exps.next(); + LogRecord act =3D (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 =3D 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", nul= l)); + 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", nul= l)); + expected.add(new LogRecord(SimpleLog.LOG_LEVEL_FATAL, "fatal", nul= l)); + + } + + +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/simple/DateTimeCustomConfigTestCase.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/simple/DateTimeCust= omConfigTestCase.java?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/simple/DateTimeCustomConfigTestCase.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/simple/DateTimeCustomConfigTestCase.java Mon Mar 2= 8 02:36:50 2005 @@ -0,0 +1,70 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 + +package org.apache.commons.logging.simple; + +import java.util.Date; +import java.text.SimpleDateFormat; +import java.text.DateFormat; + +import junit.framework.Test; +import junit.framework.TestSuite; + + +/** + * Tests custom date time format configuration + */ +public class DateTimeCustomConfigTestCase extends CustomConfigTestCase { + =20 + // ----------------------------------------------------------- Constru= ctors + + /** + * Return the tests included in this test suite. + */ + public static Test suite() { + return (new TestSuite(DateTimeCustomConfigTestCase.class)); + } + + + /** + *

Construct a new instance of this test case.

+ * + * @param name Name of the test case + */ + public DateTimeCustomConfigTestCase(String name) { + super(name); + } + =20 + // ----------------------------------------------------------- Methods + + /** Checks that the date time format has been successfully set */ + protected void checkDecoratedDateTime() { + assertEquals("Expected date format to be set", "dd.mm.yyyy", + ((DecoratedSimpleLog) log).getDateTimeFormat()); + =20 + // try the formatter + Date now =3D new Date(); + DateFormat formatter =3D ((DecoratedSimpleLog) log).getDateTimeFor= matter();=20 + SimpleDateFormat sampleFormatter =3D new SimpleDateFormat("dd.mm.y= yyy"); + assertEquals("Date should be formatters to pattern dd.mm.yyyy", sa= mpleFormatter.format(now), formatter.format(now)); + } + =20 + /** Hook for subclassses */ + protected void checkShowDateTime() { + assertTrue(((DecoratedSimpleLog) log).getShowDateTime()); + } + =20 +} \ No newline at end of file Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/simple/DecoratedSimpleLog.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/simple/DecoratedSim= pleLog.java?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/simple/DecoratedSimpleLog.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/simple/DecoratedSimpleLog.java Mon Mar 28 02:36:50= 2005 @@ -0,0 +1,100 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 + +package org.apache.commons.logging.simple; + + +import java.util.ArrayList; +import java.util.List; +import java.text.DateFormat; +import org.apache.commons.logging.impl.SimpleLog; + + +/** + *

Decorated instance of SimpleLog to expose internal state and + * support buffered output.

+ */ + +public class DecoratedSimpleLog extends SimpleLog { + + + // ------------------------------------------------------------ Constr= uctor + + + public DecoratedSimpleLog(String name) { + super(name); + } + + + // ------------------------------------------------------------- Prope= rties + + public DateFormat getDateTimeFormatter() { + return (dateFormatter); + } + + + public String getDateTimeFormat() { + return (dateTimeFormat); + } + + + public String getLogName() { + return (logName); + } + + + public boolean getShowDateTime() { + return (showDateTime); + } + + + public boolean getShowShortName() { + return (showShortName); + } + + + // ------------------------------------------------------- Protected M= ethods + + + // 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 M= ethods + + + // Cache of logged records + protected ArrayList cache =3D new ArrayList(); + + + // Clear cache + public void clearCache() { + cache.clear(); + } + + + // Return cache + public List getCache() { + return (this.cache); + } + + +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/simple/DefaultConfigTestCase.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/simple/DefaultConfi= gTestCase.java?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/simple/DefaultConfigTestCase.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/simple/DefaultConfigTestCase.java Mon Mar 28 02:36= :50 2005 @@ -0,0 +1,231 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 + +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; + + +/** + *

TestCase for simple logging when running with zero configuration + * other than selecting the SimpleLog implementation.

+ * + * @author Craig R. McClanahan + * @version $Revision: 1.5 $ $Date: 2004-05-29 11:43:35 +0100 (Sat, 29 May= 2004) $ + */ + +public class DefaultConfigTestCase extends TestCase { + + + // ----------------------------------------------------------- Constru= ctors + + + /** + *

Construct a new instance of this test case.

+ * + * @param name Name of the test case + */ + public DefaultConfigTestCase(String name) { + super(name); + } + + + // ----------------------------------------------------- Instance Vari= ables + + + /** + *

The {@link LogFactory} implementation we have selected.

+ */ + protected LogFactory factory =3D null; + + + /** + *

The {@link Log} implementation we have selected.

+ */ + protected Log log =3D null; + + + // ------------------------------------------- JUnit Infrastructure Me= thods + + + /** + * 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 =3D null; + factory =3D null; + LogFactory.releaseAll(); + } + + + // ----------------------------------------------------------- Test Me= thods + + + // 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[] =3D 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 =3D new ByteArrayOutputStream(); + ObjectOutputStream oos =3D new ObjectOutputStream(baos); + oos.writeObject(log); + oos.close(); + ByteArrayInputStream bais =3D + new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream ois =3D new ObjectInputStream(bais); + log =3D (Log) ois.readObject(); + ois.close(); + + // Check the characteristics of the resulting object + checkStandard(); + + } + + + // -------------------------------------------------------- Support Me= thods + + + + // 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("yyyy/MM/dd HH:mm:ss:SSS zzz", + ((DecoratedSimpleLog) log).getDateTimeFormat()); + 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 =3D new DecoratedSimpleLog(name); + } + + + // Set up factory instance + protected void setUpFactory() throws Exception { + factory =3D LogFactory.getFactory(); + } + + + // Set up log instance + protected void setUpLog(String name) throws Exception { + log =3D LogFactory.getLog(name); + } + + +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test= /org/apache/commons/logging/simple/LogRecord.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/src/test/org/apache/commons/logging/simple/LogRecord.ja= va?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/simple/LogRecord.java (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/src/test/or= g/apache/commons/logging/simple/LogRecord.java Mon Mar 28 02:36:50 2005 @@ -0,0 +1,37 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */=20 + + +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 =3D type; + this.message =3D message; + this.t =3D t; + } + + public int type; + public Object message; + public Throwable t; + +} Added: jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/xdocs/.c= vsignore URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/branches/= DON_QUIXOTE/classic/xdocs/.cvsignore?view=3Dauto&rev=3D159228 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/xdocs/.cvsi= gnore (added) +++ jakarta/commons/proper/logging/branches/DON_QUIXOTE/classic/xdocs/.cvsi= gnore Mon Mar 28 02:36:50 2005 @@ -0,0 +1 @@ +stylesheets --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org