We don't use author tag, CVS/SVN tags or lots of whitespace
Add a space before { when missing
This commit is contained in:
@@ -23,9 +23,6 @@ import junit.framework.TestCase;
|
||||
* Generic tests that can be applied to any log adapter by
|
||||
* subclassing this class and defining method getLogObject
|
||||
* appropriately.
|
||||
*
|
||||
* @author Sean C. Sullivan
|
||||
* @version $Revision$
|
||||
*/
|
||||
public abstract class AbstractLogTest extends TestCase {
|
||||
|
||||
@@ -34,61 +31,36 @@ public abstract class AbstractLogTest extends TestCase {
|
||||
public void testLoggingWithNullParameters()
|
||||
{
|
||||
final Log log = this.getLogObject();
|
||||
|
||||
assertNotNull(log);
|
||||
|
||||
|
||||
log.debug(null);
|
||||
|
||||
log.debug(null, null);
|
||||
|
||||
log.debug(log.getClass().getName() + ": debug statement");
|
||||
|
||||
log.debug(log.getClass().getName() + ": debug statement w/ null exception", new RuntimeException());
|
||||
|
||||
|
||||
log.error(null);
|
||||
|
||||
log.error(null, null);
|
||||
|
||||
log.error(log.getClass().getName() + ": error statement");
|
||||
|
||||
log.error(log.getClass().getName() + ": error statement w/ null exception", new RuntimeException());
|
||||
|
||||
|
||||
log.fatal(null);
|
||||
|
||||
log.fatal(null, null);
|
||||
|
||||
log.fatal(log.getClass().getName() + ": fatal statement");
|
||||
|
||||
log.fatal(log.getClass().getName() + ": fatal statement w/ null exception", new RuntimeException());
|
||||
|
||||
|
||||
log.info(null);
|
||||
|
||||
log.info(null, null);
|
||||
|
||||
log.info(log.getClass().getName() + ": info statement");
|
||||
|
||||
log.info(log.getClass().getName() + ": info statement w/ null exception", new RuntimeException());
|
||||
|
||||
|
||||
log.trace(null);
|
||||
|
||||
log.trace(null, null);
|
||||
|
||||
log.trace(log.getClass().getName() + ": trace statement");
|
||||
|
||||
log.trace(log.getClass().getName() + ": trace statement w/ null exception", new RuntimeException());
|
||||
|
||||
|
||||
log.warn(null);
|
||||
|
||||
log.warn(null, null);
|
||||
|
||||
log.warn(log.getClass().getName() + ": warn statement");
|
||||
|
||||
log.warn(log.getClass().getName() + ": warn statement w/ null exception", new RuntimeException());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* testcase to emulate container and application isolated from container
|
||||
* @author baliuka
|
||||
*/
|
||||
public class LoadTestCase extends TestCase{
|
||||
//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
|
||||
* as the classloader that loaded it.
|
||||
*/
|
||||
static class AppClassLoader extends ClassLoader{
|
||||
static class AppClassLoader extends ClassLoader {
|
||||
|
||||
java.util.Map classes = new java.util.HashMap();
|
||||
|
||||
AppClassLoader(final ClassLoader parent){
|
||||
AppClassLoader(final ClassLoader 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);
|
||||
if(result != null){
|
||||
Class result = (Class) classes.get(name);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
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.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
|
||||
|
||||
while(is.available() > 0){
|
||||
while (is.available() > 0) {
|
||||
out.write(is.read());
|
||||
}
|
||||
|
||||
final byte data [] = out.toByteArray();
|
||||
final byte data[] = out.toByteArray();
|
||||
|
||||
result = super.defineClass(name, data, 0, data.length );
|
||||
classes.put(name,result);
|
||||
result = super.defineClass(name, data, 0, data.length);
|
||||
classes.put(name, result);
|
||||
|
||||
return result;
|
||||
|
||||
}catch(final java.io.IOException ioe){
|
||||
} catch (final java.io.IOException ioe) {
|
||||
|
||||
throw new ClassNotFoundException( name + " caused by "
|
||||
+ ioe.getMessage() );
|
||||
throw new ClassNotFoundException(name + " caused by " + ioe.getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// not very trivial to emulate we must implement "findClass",
|
||||
// but it will delegete to junit class loder first
|
||||
@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.
|
||||
//filters exeptions to simlify handling in test
|
||||
// isolates all logging classes, application in the same classloader too.
|
||||
// filters exeptions to simlify handling in test
|
||||
for (final String element : LOG_PCKG) {
|
||||
if( name.startsWith( element ) &&
|
||||
name.indexOf("Exception") == -1 ){
|
||||
if (name.startsWith(element) && name.indexOf("Exception") == -1) {
|
||||
return def(name);
|
||||
}
|
||||
}
|
||||
@@ -179,36 +175,29 @@ public class LoadTestCase extends TestCase{
|
||||
* Load class UserClass via a temporary classloader which is a child of
|
||||
* the classloader used to load this test class.
|
||||
*/
|
||||
private Class reload()throws Exception{
|
||||
|
||||
private Class reload() throws Exception {
|
||||
Class testObjCls = null;
|
||||
|
||||
final AppClassLoader appLoader = new AppClassLoader(
|
||||
this.getClass().getClassLoader());
|
||||
try{
|
||||
final AppClassLoader appLoader = new AppClassLoader(this.getClass().getClassLoader());
|
||||
try {
|
||||
|
||||
testObjCls = appLoader.loadClass(UserClass.class.getName());
|
||||
|
||||
}catch(final ClassNotFoundException cnfe){
|
||||
} catch (final ClassNotFoundException cnfe) {
|
||||
throw cnfe;
|
||||
}catch(final Throwable t){
|
||||
} catch (final Throwable t) {
|
||||
t.printStackTrace();
|
||||
fail("AppClassLoader failed ");
|
||||
}
|
||||
|
||||
assertSame("app isolated", testObjCls.getClassLoader(), appLoader);
|
||||
|
||||
|
||||
return testObjCls;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void execute(final Class cls)throws Exception{
|
||||
|
||||
cls.newInstance();
|
||||
|
||||
private void execute(final Class cls) throws Exception {
|
||||
cls.newInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,8 +25,6 @@ import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public class AvalonLoggerTestCase extends AbstractLogTest {
|
||||
|
||||
|
||||
@@ -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
|
||||
* custom configuration, so that JDK 1.4 should be selected and an appropriate
|
||||
* logger configured per the configuration properties.</p>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
|
||||
public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
|
||||
@@ -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
|
||||
* zero configuration, and with Log4J not present (so JDK 1.4 logging
|
||||
* should be automatically configured.</p>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
|
||||
public class DefaultConfigTestCase extends TestCase {
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
|
||||
/**
|
||||
* <p>Construct a new instance of this test case.</p>
|
||||
*
|
||||
@@ -56,25 +48,16 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
/**
|
||||
* <p>The {@link LogFactory} implementation we have selected.</p>
|
||||
*/
|
||||
protected LogFactory factory;
|
||||
|
||||
|
||||
/**
|
||||
* <p>The {@link Log} implementation we have selected.</p>
|
||||
*/
|
||||
protected Log log;
|
||||
|
||||
|
||||
// ------------------------------------------- JUnit Infrastructure Methods
|
||||
|
||||
|
||||
/**
|
||||
* Set up instance variables required by this test case.
|
||||
*/
|
||||
@@ -84,7 +67,6 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
setUpLog("TestLogger");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the tests included in this test suite.
|
||||
*/
|
||||
@@ -108,21 +90,13 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
LogFactory.releaseAll();
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Test Methods
|
||||
|
||||
|
||||
// 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",
|
||||
@@ -131,7 +105,6 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
final String names[] = factory.getAttributeNames();
|
||||
assertNotNull("Names exists", names);
|
||||
assertEquals("Names empty", 0, names.length);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -154,11 +127,6 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------- Support Methods
|
||||
|
||||
|
||||
|
||||
// Check the log instance
|
||||
protected void checkLog() {
|
||||
|
||||
@@ -177,17 +145,14 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Set up factory instance
|
||||
protected void setUpFactory() throws Exception {
|
||||
factory = LogFactory.getFactory();
|
||||
}
|
||||
|
||||
|
||||
// Set up log instance
|
||||
protected void setUpLog(final String name) throws Exception {
|
||||
log = LogFactory.getLog(name);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,48 +26,28 @@ import java.util.logging.LogRecord;
|
||||
|
||||
/**
|
||||
* <p>Test implementation of {@code java.util.logging.Handler}.</p>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
|
||||
public class TestHandler extends Handler {
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
// The set of logged records for this handler
|
||||
private final List records = new ArrayList();
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
public Iterator records() {
|
||||
return records.iterator();
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------- Handler Methods
|
||||
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
records.clear();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void publish(final LogRecord record) {
|
||||
records.add(record);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -34,22 +34,14 @@ import org.apache.commons.logging.impl.SimpleLog;
|
||||
/**
|
||||
* <p>TestCase for simple logging when running with custom configuration
|
||||
* properties.</p>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
/**
|
||||
* <p>The expected log records.</p>
|
||||
*/
|
||||
protected List expected;
|
||||
|
||||
|
||||
/**
|
||||
* <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 };
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* <p>The message strings that should have been logged.</p>
|
||||
*/
|
||||
protected String testMessages[] =
|
||||
{ "debug", "info", "warn", "error", "fatal" };
|
||||
|
||||
|
||||
// ------------------------------------------- JUnit Infrastructure Methods
|
||||
|
||||
/**
|
||||
* Set system properties that will control the LogFactory/Log objects
|
||||
* when they are created. Subclasses can override this method to
|
||||
@@ -95,7 +83,6 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
setUpLog("DecoratedLogger");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the tests included in this test suite.
|
||||
* <p>
|
||||
@@ -129,46 +116,30 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
expected = null;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Test Methods
|
||||
|
||||
|
||||
// Test logging message strings with exceptions
|
||||
public void testExceptionMessages() throws Exception {
|
||||
|
||||
((DecoratedSimpleLog) log).clearCache();
|
||||
logExceptionMessages();
|
||||
checkExpected();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Test logging plain message strings
|
||||
public void testPlainMessages() throws Exception {
|
||||
|
||||
((DecoratedSimpleLog) log).clearCache();
|
||||
logPlainMessages();
|
||||
checkExpected();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Test Serializability of standard instance
|
||||
@Override
|
||||
public void testSerializable() throws Exception {
|
||||
|
||||
((DecoratedSimpleLog) log).clearCache();
|
||||
logPlainMessages();
|
||||
super.testSerializable();
|
||||
logExceptionMessages();
|
||||
checkExpected();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------- Support Methods
|
||||
|
||||
|
||||
// Check the decorated log instance
|
||||
@Override
|
||||
protected void checkDecorated() {
|
||||
@@ -213,7 +184,6 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
|
||||
// Check the actual log records against the expected ones
|
||||
protected void checkExpected() {
|
||||
|
||||
final List acts = ((DecoratedSimpleLog) log).getCache();
|
||||
final Iterator exps = expected.iterator();
|
||||
int n = 0;
|
||||
@@ -224,22 +194,18 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
||||
assertEquals("Row " + n + " message", exp.message, act.message);
|
||||
assertEquals("Row " + n + " throwable", exp.t, act.t);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Check the standard log instance
|
||||
@Override
|
||||
protected void checkStandard() {
|
||||
|
||||
checkDecorated();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Log the messages with exceptions
|
||||
protected void logExceptionMessages() {
|
||||
|
||||
// Generate log records
|
||||
final Throwable t = new DummyException();
|
||||
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_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");
|
||||
@@ -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_ERROR, "error", null));
|
||||
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_FATAL, "fatal", null));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -36,32 +36,20 @@ import org.apache.commons.logging.impl.SimpleLog;
|
||||
/**
|
||||
* <p>TestCase for simple logging when running with zero configuration
|
||||
* other than selecting the SimpleLog implementation.</p>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
|
||||
public class DefaultConfigTestCase extends TestCase {
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
/**
|
||||
* <p>The {@link LogFactory} implementation we have selected.</p>
|
||||
*/
|
||||
protected LogFactory factory;
|
||||
|
||||
|
||||
/**
|
||||
* <p>The {@link Log} implementation we have selected.</p>
|
||||
*/
|
||||
protected Log log;
|
||||
|
||||
|
||||
// ------------------------------------------- JUnit Infrastructure Methods
|
||||
|
||||
|
||||
/**
|
||||
* Return the tests included in this test suite.
|
||||
* <p>
|
||||
@@ -118,30 +106,19 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
LogFactory.releaseAll();
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Test Methods
|
||||
|
||||
|
||||
// Test pristine DecoratedSimpleLog instance
|
||||
public void testPristineDecorated() {
|
||||
|
||||
setUpDecorated("DecoratedLogger");
|
||||
checkDecorated();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Test pristine Log instance
|
||||
public void testPristineLog() {
|
||||
|
||||
checkStandard();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Test pristine LogFactory instance
|
||||
public void testPristineFactory() {
|
||||
|
||||
assertNotNull("LogFactory exists", factory);
|
||||
assertEquals("LogFactory class",
|
||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||
@@ -150,10 +127,8 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
final String names[] = factory.getAttributeNames();
|
||||
assertNotNull("Names exists", names);
|
||||
assertEquals("Names empty", 0, names.length);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Test Serializability of standard instance
|
||||
public void testSerializable() throws Exception {
|
||||
|
||||
@@ -173,14 +148,8 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------- Support Methods
|
||||
|
||||
|
||||
|
||||
// Check the decorated log instance
|
||||
protected void checkDecorated() {
|
||||
|
||||
assertNotNull("Log exists", log);
|
||||
assertEquals("Log class",
|
||||
"org.apache.commons.logging.simple.DecoratedSimpleLog",
|
||||
@@ -204,13 +173,11 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
((DecoratedSimpleLog) log).getLogName());
|
||||
assertFalse(((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",
|
||||
@@ -226,7 +193,6 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
|
||||
// Can we retrieve the current log level?
|
||||
assertEquals(SimpleLog.LOG_LEVEL_INFO, ((SimpleLog) log).getLevel());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -247,5 +213,4 @@ public class DefaultConfigTestCase extends TestCase {
|
||||
log = LogFactory.getLog(name);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user