1
0

We don't use author tag, CVS/SVN tags or lots of whitespace

Add a space before { when missing
This commit is contained in:
Gary Gregory
2022-08-30 09:46:14 -04:00
parent 0080bcbf79
commit 5f5affb467
8 changed files with 932 additions and 1105 deletions

View File

@@ -23,9 +23,6 @@ import junit.framework.TestCase;
* Generic tests that can be applied to any log adapter by * Generic tests that can be applied to any log adapter by
* subclassing this class and defining method getLogObject * subclassing this class and defining method getLogObject
* appropriately. * appropriately.
*
* @author Sean C. Sullivan
* @version $Revision$
*/ */
public abstract class AbstractLogTest extends TestCase { public abstract class AbstractLogTest extends TestCase {
@@ -34,61 +31,36 @@ public abstract class AbstractLogTest extends TestCase {
public void testLoggingWithNullParameters() public void testLoggingWithNullParameters()
{ {
final Log log = this.getLogObject(); final Log log = this.getLogObject();
assertNotNull(log); assertNotNull(log);
log.debug(null); log.debug(null);
log.debug(null, null); log.debug(null, null);
log.debug(log.getClass().getName() + ": debug statement"); log.debug(log.getClass().getName() + ": debug statement");
log.debug(log.getClass().getName() + ": debug statement w/ null exception", new RuntimeException()); log.debug(log.getClass().getName() + ": debug statement w/ null exception", new RuntimeException());
log.error(null); log.error(null);
log.error(null, null); log.error(null, null);
log.error(log.getClass().getName() + ": error statement"); log.error(log.getClass().getName() + ": error statement");
log.error(log.getClass().getName() + ": error statement w/ null exception", new RuntimeException()); log.error(log.getClass().getName() + ": error statement w/ null exception", new RuntimeException());
log.fatal(null); log.fatal(null);
log.fatal(null, null); log.fatal(null, null);
log.fatal(log.getClass().getName() + ": fatal statement"); log.fatal(log.getClass().getName() + ": fatal statement");
log.fatal(log.getClass().getName() + ": fatal statement w/ null exception", new RuntimeException()); log.fatal(log.getClass().getName() + ": fatal statement w/ null exception", new RuntimeException());
log.info(null); log.info(null);
log.info(null, null); log.info(null, null);
log.info(log.getClass().getName() + ": info statement"); log.info(log.getClass().getName() + ": info statement");
log.info(log.getClass().getName() + ": info statement w/ null exception", new RuntimeException()); log.info(log.getClass().getName() + ": info statement w/ null exception", new RuntimeException());
log.trace(null); log.trace(null);
log.trace(null, null); log.trace(null, null);
log.trace(log.getClass().getName() + ": trace statement"); log.trace(log.getClass().getName() + ": trace statement");
log.trace(log.getClass().getName() + ": trace statement w/ null exception", new RuntimeException()); log.trace(log.getClass().getName() + ": trace statement w/ null exception", new RuntimeException());
log.warn(null); log.warn(null);
log.warn(null, null); log.warn(null, null);
log.warn(log.getClass().getName() + ": warn statement"); log.warn(log.getClass().getName() + ": warn statement");
log.warn(log.getClass().getName() + ": warn statement w/ null exception", new RuntimeException()); log.warn(log.getClass().getName() + ": warn statement w/ null exception", new RuntimeException());
} }
} }

View File

@@ -20,7 +20,6 @@ import junit.framework.TestCase;
/** /**
* testcase to emulate container and application isolated from container * testcase to emulate container and application isolated from container
* @author baliuka
*/ */
public class LoadTestCase 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
@@ -36,58 +35,55 @@ public class LoadTestCase extends TestCase{
* to be set up with a classpath, as it simply uses the same classpath * to be set up with a classpath, as it simply uses the same classpath
* as the classloader that loaded it. * as the classloader that loaded it.
*/ */
static class AppClassLoader extends ClassLoader{ static class AppClassLoader extends ClassLoader {
java.util.Map classes = new java.util.HashMap(); java.util.Map classes = new java.util.HashMap();
AppClassLoader(final ClassLoader parent){ AppClassLoader(final ClassLoader parent) {
super(parent); super(parent);
} }
private Class def(final String name)throws ClassNotFoundException{ private Class def(final String name) throws ClassNotFoundException {
Class result = (Class)classes.get(name); Class result = (Class) classes.get(name);
if(result != null){ if (result != null) {
return result; return result;
} }
try{ try {
final ClassLoader cl = this.getClass().getClassLoader(); final ClassLoader cl = this.getClass().getClassLoader();
final String classFileName = name.replace('.','/') + ".class"; final String classFileName = name.replace('.', '/') + ".class";
final java.io.InputStream is = cl.getResourceAsStream(classFileName); final java.io.InputStream is = cl.getResourceAsStream(classFileName);
final java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(); final java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
while(is.available() > 0){ while (is.available() > 0) {
out.write(is.read()); out.write(is.read());
} }
final byte data [] = out.toByteArray(); final byte data[] = out.toByteArray();
result = super.defineClass(name, data, 0, data.length ); result = super.defineClass(name, data, 0, data.length);
classes.put(name,result); classes.put(name, result);
return result; return result;
}catch(final java.io.IOException ioe){ } catch (final java.io.IOException ioe) {
throw new ClassNotFoundException( name + " caused by " throw new ClassNotFoundException(name + " caused by " + ioe.getMessage());
+ ioe.getMessage() );
} }
} }
// not very trivial to emulate we must implement "findClass", // not very trivial to emulate we must implement "findClass",
// but it will delegete to junit class loder first // but it will delegete to junit class loder first
@Override @Override
public Class loadClass(final String name)throws ClassNotFoundException{ public Class loadClass(final String name) throws ClassNotFoundException {
//isolates all logging classes, application in the same classloader too. // isolates all logging classes, application in the same classloader too.
//filters exeptions to simlify handling in test // filters exeptions to simlify handling in test
for (final String element : LOG_PCKG) { for (final String element : LOG_PCKG) {
if( name.startsWith( element ) && if (name.startsWith(element) && name.indexOf("Exception") == -1) {
name.indexOf("Exception") == -1 ){
return def(name); return def(name);
} }
} }
@@ -179,36 +175,29 @@ public class LoadTestCase extends TestCase{
* Load class UserClass via a temporary classloader which is a child of * Load class UserClass via a temporary classloader which is a child of
* the classloader used to load this test class. * the classloader used to load this test class.
*/ */
private Class reload()throws Exception{ private Class reload() throws Exception {
Class testObjCls = null; Class testObjCls = null;
final AppClassLoader appLoader = new AppClassLoader(this.getClass().getClassLoader());
final AppClassLoader appLoader = new AppClassLoader( try {
this.getClass().getClassLoader());
try{
testObjCls = appLoader.loadClass(UserClass.class.getName()); testObjCls = appLoader.loadClass(UserClass.class.getName());
}catch(final ClassNotFoundException cnfe){ } catch (final ClassNotFoundException cnfe) {
throw cnfe; throw cnfe;
}catch(final Throwable t){ } catch (final Throwable t) {
t.printStackTrace(); t.printStackTrace();
fail("AppClassLoader failed "); fail("AppClassLoader failed ");
} }
assertSame("app isolated", testObjCls.getClassLoader(), appLoader); assertSame("app isolated", testObjCls.getClassLoader(), appLoader);
return testObjCls; return testObjCls;
} }
private void execute(final Class cls)throws Exception{ private void execute(final Class cls) throws Exception {
cls.newInstance(); cls.newInstance();
} }
@Override @Override

View File

@@ -25,8 +25,6 @@ import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
/** /**
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
* @version $Revision$ $Date$
*/ */
public class AvalonLoggerTestCase extends AbstractLogTest { public class AvalonLoggerTestCase extends AbstractLogTest {

View File

@@ -39,9 +39,6 @@ import org.apache.commons.logging.PathableTestSuite;
* <p>TestCase for JDK 1.4 logging when running on a JDK 1.4 system with * <p>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 appropriate * custom configuration, so that JDK 1.4 should be selected and an appropriate
* logger configured per the configuration properties.</p> * logger configured per the configuration properties.</p>
*
* @author Craig R. McClanahan
* @version $Revision$ $Date$
*/ */
public class CustomConfigTestCase extends DefaultConfigTestCase { public class CustomConfigTestCase extends DefaultConfigTestCase {

View File

@@ -36,17 +36,9 @@ import org.apache.commons.logging.PathableTestSuite;
* <p>TestCase for JDK 1.4 logging when running on a JDK 1.4 system with * <p>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 * zero configuration, and with Log4J not present (so JDK 1.4 logging
* should be automatically configured.</p> * should be automatically configured.</p>
*
* @author Craig R. McClanahan
* @version $Revision$ $Date$
*/ */
public class DefaultConfigTestCase extends TestCase { public class DefaultConfigTestCase extends TestCase {
// ----------------------------------------------------------- Constructors
/** /**
* <p>Construct a new instance of this test case.</p> * <p>Construct a new instance of this test case.</p>
* *
@@ -56,25 +48,16 @@ public class DefaultConfigTestCase extends TestCase {
super(name); super(name);
} }
// ----------------------------------------------------- Instance Variables
/** /**
* <p>The {@link LogFactory} implementation we have selected.</p> * <p>The {@link LogFactory} implementation we have selected.</p>
*/ */
protected LogFactory factory; protected LogFactory factory;
/** /**
* <p>The {@link Log} implementation we have selected.</p> * <p>The {@link Log} implementation we have selected.</p>
*/ */
protected Log log; protected Log log;
// ------------------------------------------- JUnit Infrastructure Methods
/** /**
* Set up instance variables required by this test case. * Set up instance variables required by this test case.
*/ */
@@ -84,7 +67,6 @@ public class DefaultConfigTestCase extends TestCase {
setUpLog("TestLogger"); setUpLog("TestLogger");
} }
/** /**
* Return the tests included in this test suite. * Return the tests included in this test suite.
*/ */
@@ -108,21 +90,13 @@ public class DefaultConfigTestCase extends TestCase {
LogFactory.releaseAll(); LogFactory.releaseAll();
} }
// ----------------------------------------------------------- Test Methods
// Test pristine Log instance // Test pristine Log instance
public void testPristineLog() { public void testPristineLog() {
checkLog(); checkLog();
} }
// Test pristine LogFactory instance // Test pristine LogFactory instance
public void testPristineFactory() { public void testPristineFactory() {
assertNotNull("LogFactory exists", factory); assertNotNull("LogFactory exists", factory);
assertEquals("LogFactory class", assertEquals("LogFactory class",
"org.apache.commons.logging.impl.LogFactoryImpl", "org.apache.commons.logging.impl.LogFactoryImpl",
@@ -131,7 +105,6 @@ public class DefaultConfigTestCase extends TestCase {
final String names[] = factory.getAttributeNames(); final String names[] = factory.getAttributeNames();
assertNotNull("Names exists", names); assertNotNull("Names exists", names);
assertEquals("Names empty", 0, names.length); assertEquals("Names empty", 0, names.length);
} }
@@ -154,11 +127,6 @@ public class DefaultConfigTestCase extends TestCase {
} }
// -------------------------------------------------------- Support Methods
// Check the log instance // Check the log instance
protected void checkLog() { protected void checkLog() {
@@ -177,17 +145,14 @@ public class DefaultConfigTestCase extends TestCase {
} }
// Set up factory instance // Set up factory instance
protected void setUpFactory() throws Exception { protected void setUpFactory() throws Exception {
factory = LogFactory.getFactory(); factory = LogFactory.getFactory();
} }
// Set up log instance // Set up log instance
protected void setUpLog(final String name) throws Exception { protected void setUpLog(final String name) throws Exception {
log = LogFactory.getLog(name); log = LogFactory.getLog(name);
} }
} }

View File

@@ -26,48 +26,28 @@ import java.util.logging.LogRecord;
/** /**
* <p>Test implementation of {@code java.util.logging.Handler}.</p> * <p>Test implementation of {@code java.util.logging.Handler}.</p>
*
* @author Craig R. McClanahan
* @version $Revision$ $Date$
*/ */
public class TestHandler extends Handler { public class TestHandler extends Handler {
// ----------------------------------------------------- Instance Variables
// The set of logged records for this handler // The set of logged records for this handler
private final List records = new ArrayList(); private final List records = new ArrayList();
// --------------------------------------------------------- Public Methods
public Iterator records() { public Iterator records() {
return records.iterator(); return records.iterator();
} }
// -------------------------------------------------------- Handler Methods
@Override @Override
public void close() { public void close() {
} }
@Override @Override
public void flush() { public void flush() {
records.clear(); records.clear();
} }
@Override @Override
public void publish(final LogRecord record) { public void publish(final LogRecord record) {
records.add(record); records.add(record);
} }
} }

View File

@@ -34,22 +34,14 @@ import org.apache.commons.logging.impl.SimpleLog;
/** /**
* <p>TestCase for simple logging when running with custom configuration * <p>TestCase for simple logging when running with custom configuration
* properties.</p> * properties.</p>
*
* @author Craig R. McClanahan
* @version $Revision$ $Date$
*/ */
public class CustomConfigTestCase extends DefaultConfigTestCase { public class CustomConfigTestCase extends DefaultConfigTestCase {
// ----------------------------------------------------- Instance Variables
/** /**
* <p>The expected log records.</p> * <p>The expected log records.</p>
*/ */
protected List expected; protected List expected;
/** /**
* <p>The message levels that should have been logged.</p> * <p>The message levels that should have been logged.</p>
*/ */
@@ -58,16 +50,12 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
{ Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE, Level.SEVERE }; { Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE, Level.SEVERE };
*/ */
/** /**
* <p>The message strings that should have been logged.</p> * <p>The message strings that should have been logged.</p>
*/ */
protected String testMessages[] = protected String testMessages[] =
{ "debug", "info", "warn", "error", "fatal" }; { "debug", "info", "warn", "error", "fatal" };
// ------------------------------------------- JUnit Infrastructure Methods
/** /**
* Set system properties that will control the LogFactory/Log objects * Set system properties that will control the LogFactory/Log objects
* when they are created. Subclasses can override this method to * when they are created. Subclasses can override this method to
@@ -95,7 +83,6 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
setUpLog("DecoratedLogger"); setUpLog("DecoratedLogger");
} }
/** /**
* Return the tests included in this test suite. * Return the tests included in this test suite.
* <p> * <p>
@@ -129,46 +116,30 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
expected = null; expected = null;
} }
// ----------------------------------------------------------- Test Methods
// Test logging message strings with exceptions // Test logging message strings with exceptions
public void testExceptionMessages() throws Exception { public void testExceptionMessages() throws Exception {
((DecoratedSimpleLog) log).clearCache(); ((DecoratedSimpleLog) log).clearCache();
logExceptionMessages(); logExceptionMessages();
checkExpected(); checkExpected();
} }
// Test logging plain message strings // Test logging plain message strings
public void testPlainMessages() throws Exception { public void testPlainMessages() throws Exception {
((DecoratedSimpleLog) log).clearCache(); ((DecoratedSimpleLog) log).clearCache();
logPlainMessages(); logPlainMessages();
checkExpected(); checkExpected();
} }
// Test Serializability of standard instance // Test Serializability of standard instance
@Override @Override
public void testSerializable() throws Exception { public void testSerializable() throws Exception {
((DecoratedSimpleLog) log).clearCache(); ((DecoratedSimpleLog) log).clearCache();
logPlainMessages(); logPlainMessages();
super.testSerializable(); super.testSerializable();
logExceptionMessages(); logExceptionMessages();
checkExpected(); checkExpected();
} }
// -------------------------------------------------------- Support Methods
// Check the decorated log instance // Check the decorated log instance
@Override @Override
protected void checkDecorated() { protected void checkDecorated() {
@@ -213,7 +184,6 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
// Check the actual log records against the expected ones // Check the actual log records against the expected ones
protected void checkExpected() { protected void checkExpected() {
final List acts = ((DecoratedSimpleLog) log).getCache(); final List acts = ((DecoratedSimpleLog) log).getCache();
final Iterator exps = expected.iterator(); final Iterator exps = expected.iterator();
int n = 0; int n = 0;
@@ -224,22 +194,18 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
assertEquals("Row " + n + " message", exp.message, act.message); assertEquals("Row " + n + " message", exp.message, act.message);
assertEquals("Row " + n + " throwable", exp.t, act.t); assertEquals("Row " + n + " throwable", exp.t, act.t);
} }
} }
// Check the standard log instance // Check the standard log instance
@Override @Override
protected void checkStandard() { protected void checkStandard() {
checkDecorated(); checkDecorated();
} }
// Log the messages with exceptions // Log the messages with exceptions
protected void logExceptionMessages() { protected void logExceptionMessages() {
// Generate log records // Generate log records
final Throwable t = new DummyException(); final Throwable t = new DummyException();
log.trace("trace", t); // Should not actually get logged log.trace("trace", t); // Should not actually get logged
@@ -255,13 +221,11 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_WARN, "warn", 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_ERROR, "error", t));
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_FATAL, "fatal", t)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_FATAL, "fatal", t));
} }
// Log the plain messages // Log the plain messages
protected void logPlainMessages() { protected void logPlainMessages() {
// Generate log records // Generate log records
log.trace("trace"); // Should not actually get logged log.trace("trace"); // Should not actually get logged
log.debug("debug"); log.debug("debug");
@@ -276,8 +240,5 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_WARN, "warn", null)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_WARN, "warn", null));
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_ERROR, "error", null)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_ERROR, "error", null));
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_FATAL, "fatal", null)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_FATAL, "fatal", null));
} }
} }

View File

@@ -36,32 +36,20 @@ import org.apache.commons.logging.impl.SimpleLog;
/** /**
* <p>TestCase for simple logging when running with zero configuration * <p>TestCase for simple logging when running with zero configuration
* other than selecting the SimpleLog implementation.</p> * other than selecting the SimpleLog implementation.</p>
*
* @author Craig R. McClanahan
* @version $Revision$ $Date$
*/ */
public class DefaultConfigTestCase extends TestCase { public class DefaultConfigTestCase extends TestCase {
// ----------------------------------------------------- Instance Variables
/** /**
* <p>The {@link LogFactory} implementation we have selected.</p> * <p>The {@link LogFactory} implementation we have selected.</p>
*/ */
protected LogFactory factory; protected LogFactory factory;
/** /**
* <p>The {@link Log} implementation we have selected.</p> * <p>The {@link Log} implementation we have selected.</p>
*/ */
protected Log log; protected Log log;
// ------------------------------------------- JUnit Infrastructure Methods
/** /**
* Return the tests included in this test suite. * Return the tests included in this test suite.
* <p> * <p>
@@ -118,30 +106,19 @@ public class DefaultConfigTestCase extends TestCase {
LogFactory.releaseAll(); LogFactory.releaseAll();
} }
// ----------------------------------------------------------- Test Methods
// Test pristine DecoratedSimpleLog instance // Test pristine DecoratedSimpleLog instance
public void testPristineDecorated() { public void testPristineDecorated() {
setUpDecorated("DecoratedLogger"); setUpDecorated("DecoratedLogger");
checkDecorated(); checkDecorated();
} }
// Test pristine Log instance // Test pristine Log instance
public void testPristineLog() { public void testPristineLog() {
checkStandard(); checkStandard();
} }
// Test pristine LogFactory instance // Test pristine LogFactory instance
public void testPristineFactory() { public void testPristineFactory() {
assertNotNull("LogFactory exists", factory); assertNotNull("LogFactory exists", factory);
assertEquals("LogFactory class", assertEquals("LogFactory class",
"org.apache.commons.logging.impl.LogFactoryImpl", "org.apache.commons.logging.impl.LogFactoryImpl",
@@ -150,10 +127,8 @@ public class DefaultConfigTestCase extends TestCase {
final String names[] = factory.getAttributeNames(); final String names[] = factory.getAttributeNames();
assertNotNull("Names exists", names); assertNotNull("Names exists", names);
assertEquals("Names empty", 0, names.length); assertEquals("Names empty", 0, names.length);
} }
// Test Serializability of standard instance // Test Serializability of standard instance
public void testSerializable() throws Exception { public void testSerializable() throws Exception {
@@ -173,14 +148,8 @@ public class DefaultConfigTestCase extends TestCase {
} }
// -------------------------------------------------------- Support Methods
// Check the decorated log instance // Check the decorated log instance
protected void checkDecorated() { protected void checkDecorated() {
assertNotNull("Log exists", log); assertNotNull("Log exists", log);
assertEquals("Log class", assertEquals("Log class",
"org.apache.commons.logging.simple.DecoratedSimpleLog", "org.apache.commons.logging.simple.DecoratedSimpleLog",
@@ -204,13 +173,11 @@ public class DefaultConfigTestCase extends TestCase {
((DecoratedSimpleLog) log).getLogName()); ((DecoratedSimpleLog) log).getLogName());
assertFalse(((DecoratedSimpleLog) log).getShowDateTime()); assertFalse(((DecoratedSimpleLog) log).getShowDateTime());
assertTrue(((DecoratedSimpleLog) log).getShowShortName()); assertTrue(((DecoratedSimpleLog) log).getShowShortName());
} }
// Check the standard log instance // Check the standard log instance
protected void checkStandard() { protected void checkStandard() {
assertNotNull("Log exists", log); assertNotNull("Log exists", log);
assertEquals("Log class", assertEquals("Log class",
"org.apache.commons.logging.impl.SimpleLog", "org.apache.commons.logging.impl.SimpleLog",
@@ -226,7 +193,6 @@ public class DefaultConfigTestCase extends TestCase {
// Can we retrieve the current log level? // Can we retrieve the current log level?
assertEquals(SimpleLog.LOG_LEVEL_INFO, ((SimpleLog) log).getLevel()); assertEquals(SimpleLog.LOG_LEVEL_INFO, ((SimpleLog) log).getLevel());
} }
@@ -247,5 +213,4 @@ public class DefaultConfigTestCase extends TestCase {
log = LogFactory.getLog(name); log = LogFactory.getLog(name);
} }
} }