1
0

* renamed test cases from Test.java to TestCase.java for consistency.

* removed unneeded suite and constructor methods.


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@209711 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Kitching
2005-07-08 07:02:20 +00:00
parent d163dc0a8f
commit 4bd1bd70a0
8 changed files with 26 additions and 308 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2004 The Apache Software Foundation. * Copyright 2004,2005 The Apache Software Foundation.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -25,22 +25,17 @@ import junit.framework.TestCase;
* This is the minimum requirement for any well behaved logger * This is the minimum requirement for any well behaved logger
* and so this test should be run for each kind. * and so this test should be run for each kind.
*/ */
public class BasicOperationsTest extends TestCase public class BasicOperationsTestCase extends TestCase
{ {
public BasicOperationsTest(String testName)
{
super(testName);
}
public void testIsEnabledClassLog() public void testIsEnabledClassLog()
{ {
Log log = LogFactory.getLog(BasicOperationsTest.class); Log log = LogFactory.getLog(BasicOperationsTestCase.class);
executeIsEnabledTest(log); executeIsEnabledTest(log);
} }
public void testIsEnabledNamedLog() public void testIsEnabledNamedLog()
{ {
Log log = LogFactory.getLog(BasicOperationsTest.class.getName()); Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
executeIsEnabledTest(log); executeIsEnabledTest(log);
} }
@@ -65,13 +60,13 @@ public class BasicOperationsTest extends TestCase
public void testMessageWithoutExceptionClassLog() public void testMessageWithoutExceptionClassLog()
{ {
Log log = LogFactory.getLog(BasicOperationsTest.class); Log log = LogFactory.getLog(BasicOperationsTestCase.class);
executeMessageWithoutExceptionTest(log); executeMessageWithoutExceptionTest(log);
} }
public void testMessageWithoutExceptionNamedLog() public void testMessageWithoutExceptionNamedLog()
{ {
Log log = LogFactory.getLog(BasicOperationsTest.class.getName()); Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
executeMessageWithoutExceptionTest(log); executeMessageWithoutExceptionTest(log);
} }
@@ -95,13 +90,13 @@ public class BasicOperationsTest extends TestCase
public void testMessageWithExceptionClassLog() public void testMessageWithExceptionClassLog()
{ {
Log log = LogFactory.getLog(BasicOperationsTest.class); Log log = LogFactory.getLog(BasicOperationsTestCase.class);
executeMessageWithExceptionTest(log); executeMessageWithExceptionTest(log);
} }
public void testMessageWithExceptionNamedLog() public void testMessageWithExceptionNamedLog()
{ {
Log log = LogFactory.getLog(BasicOperationsTest.class.getName()); Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
executeMessageWithExceptionTest(log); executeMessageWithExceptionTest(log);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2004 The Apache Software Foundation. * Copyright 2001-2005 The Apache Software Foundation.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ import junit.framework.TestSuite;
* @author baliuka * @author baliuka
* @version $Id$ * @version $Id$
*/ */
public class LoadTest extends TestCase{ public class LoadTestCase extends TestCase{
//TODO: need some way to add service provider packages //TODO: need some way to add service provider packages
static private String LOG_PCKG[] = {"org.apache.commons.logging", static private String LOG_PCKG[] = {"org.apache.commons.logging",
"org.apache.commons.logging.impl"}; "org.apache.commons.logging.impl"};
@@ -213,28 +213,11 @@ public class LoadTest extends TestCase{
} }
/** Creates a new instance of LoadTest */
public LoadTest(String testName) {
super(testName);
}
public static void main(String[] args){ public static void main(String[] args){
String[] testCaseName = { LoadTest.class.getName() }; String[] testCaseName = { LoadTestCase.class.getName() };
junit.textui.TestRunner.main(testCaseName); junit.textui.TestRunner.main(testCaseName);
} }
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(LoadTest.class);
return suite;
}
public void setUp() { public void setUp() {
// save state before test starts so we can restore it when test ends // save state before test starts so we can restore it when test ends
origContextClassLoader = Thread.currentThread().getContextClassLoader(); origContextClassLoader = Thread.currentThread().getContextClassLoader();

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2004 The Apache Software Foundation. * Copyright 2001-2005 The Apache Software Foundation.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ import junit.framework.*;
* *
* *
*/ */
public class NoOpLogTest extends AbstractLogTest public class NoOpLogTestCase extends AbstractLogTest
{ {
/** /**
@@ -42,16 +42,7 @@ public class NoOpLogTest extends AbstractLogTest
public static void main(String[] args) public static void main(String[] args)
{ {
String[] testCaseName = { NoOpLogTest.class.getName() }; String[] testCaseName = { NoOpLogTestCase.class.getName() };
junit.textui.TestRunner.main(testCaseName); junit.textui.TestRunner.main(testCaseName);
} }
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(NoOpLogTest.class);
return suite;
}
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2004 The Apache Software Foundation. * Copyright 2001-2005 The Apache Software Foundation.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@ import junit.framework.TestSuite;
* JCL is deployed via the bootclassloader - something that could be done when * JCL is deployed via the bootclassloader - something that could be done when
* using java in embedded systems. * using java in embedded systems.
*/ */
public class NullClassLoaderTest extends TestCase{ public class NullClassLoaderTestCase extends TestCase {
//---------------------- Main --------------------------------- //---------------------- Main ---------------------------------
@@ -33,25 +33,10 @@ public class NullClassLoaderTest extends TestCase{
* Main method so this test case can be run direct from the command line. * Main method so this test case can be run direct from the command line.
*/ */
public static void main(String[] args){ public static void main(String[] args){
String[] testCaseName = { NullClassLoaderTest.class.getName() }; String[] testCaseName = { NullClassLoaderTestCase.class.getName() };
junit.textui.TestRunner.main(testCaseName); junit.textui.TestRunner.main(testCaseName);
} }
//---------------------- Constructors ---------------------------------
/** Creates a new instance of LoadTest */
public NullClassLoaderTest(String testName) {
super(testName);
}
//---------------------- JUnit methods ---------------------------------
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(NullClassLoaderTest.class);
return suite;
}
//---------------------- unit tests --------------------------------- //---------------------- unit tests ---------------------------------
/** /**

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2004 The Apache Software Foundation. * Copyright 2001-2005 The Apache Software Foundation.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -27,30 +27,20 @@ import junit.framework.*;
* *
* *
*/ */
public class SimpleLogTest extends AbstractLogTest public class SimpleLogTestCase extends AbstractLogTest
{ {
/** /**
* *
* *
* *
*/ */
public Log getLogObject() public Log getLogObject()
{ {
return (Log) new SimpleLog(this.getClass().getName()); return (Log) new SimpleLog(this.getClass().getName());
} }
public static void main(String[] args) public static void main(String[] args) {
{ String[] testCaseName = { SimpleLogTestCase.class.getName() };
String[] testCaseName = { SimpleLogTest.class.getName() };
junit.textui.TestRunner.main(testCaseName); junit.textui.TestRunner.main(testCaseName);
} }
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(SimpleLogTest.class);
return suite;
}
} }

View File

@@ -1,60 +0,0 @@
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.apache.commons.logging;
import junit.framework.*;
/**
* <p> The build script calls just one <code>TestSuite</code> - this one!
* All tests should be written into separate <code>TestSuite</code>'s
* and added to this. Don't clutter this class with implementations. </p>
*
* <p> This class is based on <code>org.apache.commons.betwixt.TestAll</code>
* coded by James Strachan. </p>
*
* @author Robert Burrell Donkin
* @version $Revision$
*/
public class TestAll extends TestCase {
public TestAll(String testName) {
super(testName);
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(SimpleLogTest.suite());
suite.addTest(NoOpLogTest.suite());
suite.addTest(LogTest.suite());
suite.addTest(NullClassLoaderTest.suite());
suite.addTest(LoadTest.suite());
return suite;
}
/**
* This allows the tests to run as a standalone application.
*/
public static void main(String args[]) {
String[] testCaseName = { TestAll.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
}

View File

@@ -36,7 +36,7 @@ public class UserClass {
} }
public UserClass() { public UserClass() {
Log log = LogFactory.getLog(LoadTest.class); Log log = LogFactory.getLog(LoadTestCase.class);
} }
} }

View File

@@ -1,166 +0,0 @@
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
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;
/**
* <p>Wrapper around test cases that need to have a custom class loader
* hierarchy assembled. The wrapper is configured by the following
* system properties:</p>
* <ul>
* <li><strong>wrapper.hierarchy</strong> - Descriptive code describing how
* the class loader hierarchy should be assembled:
* <ul>
* <li><strong>API</strong> - Parent class loader contains
* <code>commons-logging-api.jar</code> and child class loader
* contains <code>commons-logging.jar</code>. This is like the
* default configuration for Tomcat 4.1.</li>
* <li><strong>FULL</strong> - Parent class loader contains
* <code>commons-logging.jar</code>. This is what would happen
* if you replaced <code>commons-logging-api.jar</code> with
* <code>commons-logging.jar</code> so that you did not need to
* include the latter with your application.</li>
* </ul>
* The child class loader also unconditionally includes
* <code>commons-logging-tests.jar</code>.</li>
* <li><strong>wrapper.junit</strong> - Fully qualified pathname of the
* JUnit JAR file.</li>
* <li><strong>wrapper.log4j</strong> - Fully qualified pathname of the
* Log4J JAR file, which will be placed in whichever class loader
* <code>commons-logging.jar</code> is placed in, if specified.</li>
* <li><strong>wrapper.target</strong> - Fully qualified pathname of the
* "target" directory created by the build process. This directory
* must contain the <code>commons-logging.jar</code>,
* <code>commons-logging-api.jar</code>, and
* <code>commons-logging-tests.jar</code> files resulting from the
* execution of the <code>compile.tests</code> target.</li>
* <li><strong>wrapper.testcase</strong> - Fully qualified Java class name
* of a TestCase that will ultimately be executed. This class must
* exist in the <code>commons-logging-tests.jar</code> file.</li>
* </ul>
*
* <p>When executed, the system classpath for the wrapper should include
* only the wrapper class itself.</p>
*
* @author Craig R. McClanahan
* @version $Revision$ $Date$
*/
public class Wrapper {
public static void main(String args[]) {
try {
// Create variables we will need
List parentList = new ArrayList();
List childList = new ArrayList();
URL urls[] = null;
// Construct URLs for the various JAR files
File target = new File(System.getProperty("wrapper.target"));
// the test invoker is required to set these system properties
// to point to the appropriate jar files
String jcljar = System.getProperty("commons.logging.jar");
String jclapijar = System.getProperty("commons.logging.api.jar");
String jclappjar = System.getProperty("commons.logging.appenders.jar");
if ((jcljar==null) || (jclapijar==null) || (jclappjar==null)) {
throw new Exception(
"Required system property for test is missing. "
+ "One or more of the following is not defined: "
+ "commons.logging.jar, commons.logging.api.jar, "
+ "commons.logging.appenders.jar");
}
URL commonsLogging = (new File(target, jcljar)).toURL();
URL commonsLoggingApi = (new File(target, jclapijar)).toURL();
URL commonsLoggingTests =
(new File(target, "commons-logging-tests.jar")).toURL();
URL junit =
(new File(System.getProperty("wrapper.junit"))).toURL();
URL appender = null;
URL log4j = null;
if (System.getProperty("wrapper.log4j") != null) {
log4j =
(new File(System.getProperty("wrapper.log4j"))).toURL();
appender =
(new File(target, jclappjar)).toURL();
}
System.out.println("commonsLogging lib is at [" + commonsLogging + "]");
System.out.println("commonsLoggingApi lib is at [" + commonsLoggingApi + "]");
// Construct class loader repository lists for supported scenarios
if ("API".equals(System.getProperty("wrapper.hierarchy"))) {
parentList.add(commonsLoggingApi);
childList.add(commonsLogging);
if (log4j != null) {
childList.add(log4j);
childList.add(appender);
}
} else { // Assumes "FULL"
parentList.add(commonsLogging);
if (log4j != null) {
parentList.add(log4j);
childList.add(appender);
}
}
childList.add(commonsLoggingTests);
childList.add(junit);
// Construt the parent and child class loaders
urls = (URL[]) parentList.toArray(new URL[parentList.size()]);
ClassLoader parent =
new URLClassLoader(urls,
ClassLoader.getSystemClassLoader());
urls = (URL[]) childList.toArray(new URL[childList.size()]);
ClassLoader child = new URLClassLoader(urls, parent);
// Execute the test runner for this TestCase
ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(child);
Class clazz = child.loadClass("junit.textui.TestRunner");
String params[] = new String[1];
params[0] = System.getProperty("wrapper.testcase");
Method method = clazz.getMethod("main",
new Class[] { params.getClass() });
method.invoke(null, new Object[] { params });
Thread.currentThread().setContextClassLoader(old);
} catch (Exception e) {
System.out.println("Wrapper Exception Occurred: " + e);
e.printStackTrace(System.out);
System.exit(1);
}
}
}