1
0

Normalize Javadoc spelling

This commit is contained in:
Gary Gregory
2022-06-15 08:20:20 -04:00
parent 342b6a4971
commit e7bac9a257
4 changed files with 2350 additions and 2350 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,283 +1,283 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You 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. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.simple; package org.apache.commons.logging.simple;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import junit.framework.Test; import junit.framework.Test;
import org.apache.commons.logging.DummyException; import org.apache.commons.logging.DummyException;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.PathableClassLoader; import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite; import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.impl.SimpleLog; 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 * @author Craig R. McClanahan
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class CustomConfigTestCase extends DefaultConfigTestCase { public class CustomConfigTestCase extends DefaultConfigTestCase {
// ----------------------------------------------------- Instance Variables // ----------------------------------------------------- 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>
*/ */
/* /*
protected Level testLevels[] = protected Level testLevels[] =
{ 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 // ------------------------------------------- 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
* define properties that suit them. * define properties that suit them.
*/ */
@Override @Override
public void setProperties() { public void setProperties() {
System.setProperty( System.setProperty(
"org.apache.commons.logging.Log", "org.apache.commons.logging.Log",
"org.apache.commons.logging.simple.DecoratedSimpleLog"); "org.apache.commons.logging.simple.DecoratedSimpleLog");
System.setProperty( System.setProperty(
"org.apache.commons.logging.simplelog.defaultlog", "org.apache.commons.logging.simplelog.defaultlog",
"debug"); "debug");
} }
/** /**
* Set up instance variables required by this test case. * Set up instance variables required by this test case.
*/ */
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
LogFactory.releaseAll(); LogFactory.releaseAll();
setProperties(); setProperties();
expected = new ArrayList(); expected = new ArrayList();
setUpFactory(); setUpFactory();
setUpLog("DecoratedLogger"); setUpLog("DecoratedLogger");
} }
/** /**
* Return the tests included in this test suite. * Return the tests included in this test suite.
* <p> * <p>
* We need to use a PathableClassLoader here because the SimpleLog class * We need to use a PathableClassLoader here because the SimpleLog class
* is a pile of junk and chock-full of static variables. Any other test * is a pile of junk and chock-full of static variables. Any other test
* (like simple.CustomConfigTestCase) that has used the SimpleLog class * (like simple.CustomConfigTestCase) that has used the SimpleLog class
* will already have caused it to do once-only initialisation that we * will already have caused it to do once-only initialization that we
* can't reset, even by calling LogFactory.releaseAll, because of those * can't reset, even by calling LogFactory.releaseAll, because of those
* ugly statics. The only clean solution is to load a clean copy of * ugly statics. The only clean solution is to load a clean copy of
* commons-logging including SimpleLog via a nice clean classloader. * commons-logging including SimpleLog via a nice clean class loader.
* Or we could fix SimpleLog to be sane... * Or we could fix SimpleLog to be sane...
*/ */
public static Test suite() throws Exception { public static Test suite() throws Exception {
final Class thisClass = CustomConfigTestCase.class; final Class thisClass = CustomConfigTestCase.class;
final PathableClassLoader loader = new PathableClassLoader(null); final PathableClassLoader loader = new PathableClassLoader(null);
loader.useExplicitLoader("junit.", Test.class.getClassLoader()); loader.useExplicitLoader("junit.", Test.class.getClassLoader());
loader.addLogicalLib("testclasses"); loader.addLogicalLib("testclasses");
loader.addLogicalLib("commons-logging"); loader.addLogicalLib("commons-logging");
final Class testClass = loader.loadClass(thisClass.getName()); final Class testClass = loader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, loader); return new PathableTestSuite(testClass, loader);
} }
/** /**
* Tear down instance variables required by this test case. * Tear down instance variables required by this test case.
*/ */
@Override @Override
public void tearDown() { public void tearDown() {
super.tearDown(); super.tearDown();
expected = null; expected = null;
} }
// ----------------------------------------------------------- Test Methods // ----------------------------------------------------------- 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 // -------------------------------------------------------- Support Methods
// Check the decorated log instance // Check the decorated log instance
@Override @Override
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",
log.getClass().getName()); log.getClass().getName());
// Can we call level checkers with no exceptions? // Can we call level checkers with no exceptions?
assertTrue(log.isDebugEnabled()); assertTrue(log.isDebugEnabled());
assertTrue(log.isErrorEnabled()); assertTrue(log.isErrorEnabled());
assertTrue(log.isFatalEnabled()); assertTrue(log.isFatalEnabled());
assertTrue(log.isInfoEnabled()); assertTrue(log.isInfoEnabled());
assertFalse(log.isTraceEnabled()); assertFalse(log.isTraceEnabled());
assertTrue(log.isWarnEnabled()); assertTrue(log.isWarnEnabled());
// Can we retrieve the current log level? // Can we retrieve the current log level?
assertEquals(SimpleLog.LOG_LEVEL_DEBUG, ((SimpleLog) log).getLevel()); assertEquals(SimpleLog.LOG_LEVEL_DEBUG, ((SimpleLog) log).getLevel());
// Can we validate the extra exposed properties? // Can we validate the extra exposed properties?
checkDecoratedDateTime(); checkDecoratedDateTime();
assertEquals("DecoratedLogger", assertEquals("DecoratedLogger",
((DecoratedSimpleLog) log).getLogName()); ((DecoratedSimpleLog) log).getLogName());
checkShowDateTime(); checkShowDateTime();
assertTrue(((DecoratedSimpleLog) log).getShowShortName()); assertTrue(((DecoratedSimpleLog) log).getShowShortName());
} }
/** Hook for subclassses */ /** Hook for subclassses */
protected void checkShowDateTime() { protected void checkShowDateTime() {
assertFalse(((DecoratedSimpleLog) log).getShowDateTime()); assertFalse(((DecoratedSimpleLog) log).getShowDateTime());
} }
/** Hook for subclasses */ /** Hook for subclasses */
protected void checkDecoratedDateTime() { protected void checkDecoratedDateTime() {
assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz", assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz",
((DecoratedSimpleLog) log).getDateTimeFormat()); ((DecoratedSimpleLog) log).getDateTimeFormat());
} }
// 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;
while (exps.hasNext()) { while (exps.hasNext()) {
final LogRecord exp = (LogRecord) exps.next(); final LogRecord exp = (LogRecord) exps.next();
final LogRecord act = (LogRecord) acts.get(n++); final LogRecord act = (LogRecord) acts.get(n++);
assertEquals("Row " + n + " type", exp.type, act.type); assertEquals("Row " + n + " type", exp.type, act.type);
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
log.debug("debug", t); log.debug("debug", t);
log.info("info", t); log.info("info", t);
log.warn("warn", t); log.warn("warn", t);
log.error("error", t); log.error("error", t);
log.fatal("fatal", t); log.fatal("fatal", t);
// Record the log records we expect // Record the log records we expect
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_DEBUG, "debug", t)); 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_INFO, "info", t));
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");
log.info("info"); log.info("info");
log.warn("warn"); log.warn("warn");
log.error("error"); log.error("error");
log.fatal("fatal"); log.fatal("fatal");
// Record the log records we expect // Record the log records we expect
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_DEBUG, "debug", null)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_DEBUG, "debug", null));
expected.add(new LogRecord(SimpleLog.LOG_LEVEL_INFO, "info", null)); expected.add(new LogRecord(SimpleLog.LOG_LEVEL_INFO, "info", null));
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

@@ -1,109 +1,109 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You 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. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.simple; package org.apache.commons.logging.simple;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import junit.framework.Test; import junit.framework.Test;
import org.apache.commons.logging.PathableClassLoader; import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite; import org.apache.commons.logging.PathableTestSuite;
/** /**
* Tests custom date time format configuration * Tests custom date time format configuration
*/ */
public class DateTimeCustomConfigTestCase extends CustomConfigTestCase { public class DateTimeCustomConfigTestCase extends CustomConfigTestCase {
// ----------------------------------------------------------- Constructors // ----------------------------------------------------------- Constructors
/** /**
* Return the tests included in this test suite. * Return the tests included in this test suite.
* <p> * <p>
* We need to use a PathableClassLoader here because the SimpleLog class * We need to use a PathableClassLoader here because the SimpleLog class
* is a pile of junk and chock-full of static variables. Any other test * is a pile of junk and chock-full of static variables. Any other test
* (like simple.CustomConfigTestCase) that has used the SimpleLog class * (like simple.CustomConfigTestCase) that has used the SimpleLog class
* will already have caused it to do once-only initialisation that we * will already have caused it to do once-only initialization that we
* can't reset, even by calling LogFactory.releaseAll, because of those * can't reset, even by calling LogFactory.releaseAll, because of those
* ugly statics. The only clean solution is to load a clean copy of * ugly statics. The only clean solution is to load a clean copy of
* commons-logging including SimpleLog via a nice clean classloader. * commons-logging including SimpleLog via a nice clean class loader.
* Or we could fix SimpleLog to be sane... * Or we could fix SimpleLog to be sane...
*/ */
public static Test suite() throws Exception { public static Test suite() throws Exception {
final Class thisClass = DateTimeCustomConfigTestCase.class; final Class thisClass = DateTimeCustomConfigTestCase.class;
final PathableClassLoader loader = new PathableClassLoader(null); final PathableClassLoader loader = new PathableClassLoader(null);
loader.useExplicitLoader("junit.", Test.class.getClassLoader()); loader.useExplicitLoader("junit.", Test.class.getClassLoader());
loader.addLogicalLib("testclasses"); loader.addLogicalLib("testclasses");
loader.addLogicalLib("commons-logging"); loader.addLogicalLib("commons-logging");
final Class testClass = loader.loadClass(thisClass.getName()); final Class testClass = loader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, loader); return new PathableTestSuite(testClass, loader);
} }
/** /**
* Set up system properties required by this unit test. Here, we * Set up system properties required by this unit test. Here, we
* set up the props defined in the parent class setProperties method, * set up the props defined in the parent class setProperties method,
* and add a few to configure the SimpleLog class date/time output. * and add a few to configure the SimpleLog class date/time output.
*/ */
@Override @Override
public void setProperties() { public void setProperties() {
super.setProperties(); super.setProperties();
System.setProperty( System.setProperty(
"org.apache.commons.logging.simplelog.dateTimeFormat", "org.apache.commons.logging.simplelog.dateTimeFormat",
"dd.mm.yyyy"); "dd.mm.yyyy");
System.setProperty( System.setProperty(
"org.apache.commons.logging.simplelog.showdatetime", "org.apache.commons.logging.simplelog.showdatetime",
"true"); "true");
} }
/** /**
* Set up instance variables required by this test case. * Set up instance variables required by this test case.
*/ */
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
} }
// ----------------------------------------------------------- Methods // ----------------------------------------------------------- Methods
/** Checks that the date time format has been successfully set */ /** Checks that the date time format has been successfully set */
@Override @Override
protected void checkDecoratedDateTime() { protected void checkDecoratedDateTime() {
assertEquals("Expected date format to be set", "dd.mm.yyyy", assertEquals("Expected date format to be set", "dd.mm.yyyy",
((DecoratedSimpleLog) log).getDateTimeFormat()); ((DecoratedSimpleLog) log).getDateTimeFormat());
// try the formatter // try the formatter
final Date now = new Date(); final Date now = new Date();
final DateFormat formatter = ((DecoratedSimpleLog) log).getDateTimeFormatter(); final DateFormat formatter = ((DecoratedSimpleLog) log).getDateTimeFormatter();
final SimpleDateFormat sampleFormatter = new SimpleDateFormat("dd.mm.yyyy"); final SimpleDateFormat sampleFormatter = new SimpleDateFormat("dd.mm.yyyy");
assertEquals("Date should be formatters to pattern dd.mm.yyyy", assertEquals("Date should be formatters to pattern dd.mm.yyyy",
sampleFormatter.format(now), formatter.format(now)); sampleFormatter.format(now), formatter.format(now));
} }
/** Hook for subclassses */ /** Hook for subclassses */
@Override @Override
protected void checkShowDateTime() { protected void checkShowDateTime() {
assertTrue(((DecoratedSimpleLog) log).getShowDateTime()); assertTrue(((DecoratedSimpleLog) log).getShowDateTime());
} }
} }

View File

@@ -1,251 +1,251 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You 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. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.commons.logging.simple; package org.apache.commons.logging.simple;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.PathableClassLoader; import org.apache.commons.logging.PathableClassLoader;
import org.apache.commons.logging.PathableTestSuite; import org.apache.commons.logging.PathableTestSuite;
import org.apache.commons.logging.impl.SimpleLog; 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 * @author Craig R. McClanahan
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
public class DefaultConfigTestCase extends TestCase { public class DefaultConfigTestCase extends TestCase {
// ----------------------------------------------------- Instance Variables // ----------------------------------------------------- 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 // ------------------------------------------- JUnit Infrastructure Methods
/** /**
* Return the tests included in this test suite. * Return the tests included in this test suite.
* <p> * <p>
* We need to use a PathableClassLoader here because the SimpleLog class * We need to use a PathableClassLoader here because the SimpleLog class
* is a pile of junk and chock-full of static variables. Any other test * is a pile of junk and chock-full of static variables. Any other test
* (like simple.CustomConfigTestCase) that has used the SimpleLog class * (like simple.CustomConfigTestCase) that has used the SimpleLog class
* will already have caused it to do once-only initialisation that we * will already have caused it to do once-only initialization that we
* can't reset, even by calling LogFactory.releaseAll, because of those * can't reset, even by calling LogFactory.releaseAll, because of those
* ugly statics. The only clean solution is to load a clean copy of * ugly statics. The only clean solution is to load a clean copy of
* commons-logging including SimpleLog via a nice clean classloader. * commons-logging including SimpleLog via a nice clean class loader.
* Or we could fix SimpleLog to be sane... * Or we could fix SimpleLog to be sane...
*/ */
public static Test suite() throws Exception { public static Test suite() throws Exception {
final Class thisClass = DefaultConfigTestCase.class; final Class thisClass = DefaultConfigTestCase.class;
final PathableClassLoader loader = new PathableClassLoader(null); final PathableClassLoader loader = new PathableClassLoader(null);
loader.useExplicitLoader("junit.", Test.class.getClassLoader()); loader.useExplicitLoader("junit.", Test.class.getClassLoader());
loader.addLogicalLib("testclasses"); loader.addLogicalLib("testclasses");
loader.addLogicalLib("commons-logging"); loader.addLogicalLib("commons-logging");
final Class testClass = loader.loadClass(thisClass.getName()); final Class testClass = loader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, loader); return new PathableTestSuite(testClass, loader);
} }
/** /**
* 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
* define properties that suit them. * define properties that suit them.
*/ */
public void setProperties() { public void setProperties() {
System.setProperty( System.setProperty(
"org.apache.commons.logging.Log", "org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.SimpleLog"); "org.apache.commons.logging.impl.SimpleLog");
} }
/** /**
* Set up instance variables required by this test case. * Set up instance variables required by this test case.
*/ */
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
LogFactory.releaseAll(); LogFactory.releaseAll();
setProperties(); setProperties();
setUpFactory(); setUpFactory();
setUpLog("TestLogger"); setUpLog("TestLogger");
} }
/** /**
* Tear down instance variables required by this test case. * Tear down instance variables required by this test case.
*/ */
@Override @Override
public void tearDown() { public void tearDown() {
log = null; log = null;
factory = null; factory = null;
LogFactory.releaseAll(); LogFactory.releaseAll();
} }
// ----------------------------------------------------------- Test Methods // ----------------------------------------------------------- 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",
factory.getClass().getName()); factory.getClass().getName());
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 {
// Serialize and deserialize the instance // Serialize and deserialize the instance
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos); final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(log); oos.writeObject(log);
oos.close(); oos.close();
final ByteArrayInputStream bais = final ByteArrayInputStream bais =
new ByteArrayInputStream(baos.toByteArray()); new ByteArrayInputStream(baos.toByteArray());
final ObjectInputStream ois = new ObjectInputStream(bais); final ObjectInputStream ois = new ObjectInputStream(bais);
log = (Log) ois.readObject(); log = (Log) ois.readObject();
ois.close(); ois.close();
// Check the characteristics of the resulting object // Check the characteristics of the resulting object
checkStandard(); checkStandard();
} }
// -------------------------------------------------------- Support Methods // -------------------------------------------------------- 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",
log.getClass().getName()); log.getClass().getName());
// Can we call level checkers with no exceptions? // Can we call level checkers with no exceptions?
assertFalse(log.isDebugEnabled()); assertFalse(log.isDebugEnabled());
assertTrue(log.isErrorEnabled()); assertTrue(log.isErrorEnabled());
assertTrue(log.isFatalEnabled()); assertTrue(log.isFatalEnabled());
assertTrue(log.isInfoEnabled()); assertTrue(log.isInfoEnabled());
assertFalse(log.isTraceEnabled()); assertFalse(log.isTraceEnabled());
assertTrue(log.isWarnEnabled()); assertTrue(log.isWarnEnabled());
// 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());
// Can we validate the extra exposed properties? // Can we validate the extra exposed properties?
assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz", assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz",
((DecoratedSimpleLog) log).getDateTimeFormat()); ((DecoratedSimpleLog) log).getDateTimeFormat());
assertEquals("DecoratedLogger", assertEquals("DecoratedLogger",
((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",
log.getClass().getName()); log.getClass().getName());
// Can we call level checkers with no exceptions? // Can we call level checkers with no exceptions?
assertFalse(log.isDebugEnabled()); assertFalse(log.isDebugEnabled());
assertTrue(log.isErrorEnabled()); assertTrue(log.isErrorEnabled());
assertTrue(log.isFatalEnabled()); assertTrue(log.isFatalEnabled());
assertTrue(log.isInfoEnabled()); assertTrue(log.isInfoEnabled());
assertFalse(log.isTraceEnabled()); assertFalse(log.isTraceEnabled());
assertTrue(log.isWarnEnabled()); assertTrue(log.isWarnEnabled());
// 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());
} }
// Set up decorated log instance // Set up decorated log instance
protected void setUpDecorated(final String name) { protected void setUpDecorated(final String name) {
log = new DecoratedSimpleLog(name); log = new DecoratedSimpleLog(name);
} }
// 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);
} }
} }