Remove obsolete unit test files; see StandardTests class and its concrete subclasses.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@209731 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -1,23 +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.
|
|
||||||
|
|
||||||
|
|
||||||
# This is the custom configuration properties for the Log4J logger tests
|
|
||||||
# in CustomConfigTestCase.
|
|
||||||
|
|
||||||
# Configure the root logger's level and appender
|
|
||||||
log4j.rootLogger = INFO, A1
|
|
||||||
|
|
||||||
# Configure the default appender
|
|
||||||
log4j.appender.A1 = org.apache.commons.logging.log4j.TestAppender
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2005 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.log4j;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.PathableTestSuite;
|
|
||||||
import org.apache.commons.logging.PathableClassLoader;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TestCase for Log4J logging when the commons-logging-api jar file is in
|
|
||||||
* the parent classpath and commons-logging.jar is in the child.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class CustomConfigAPITestCase extends CustomConfigTestCase {
|
|
||||||
|
|
||||||
|
|
||||||
public CustomConfigAPITestCase(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the tests included in this test suite.
|
|
||||||
*/
|
|
||||||
public static Test suite() throws Exception {
|
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
|
||||||
parent.useSystemLoader("junit.");
|
|
||||||
parent.addLogicalLib("commons-logging-api");
|
|
||||||
|
|
||||||
PathableClassLoader child = new PathableClassLoader(parent);
|
|
||||||
child.addLogicalLib("testclasses");
|
|
||||||
child.addLogicalLib("log4j12");
|
|
||||||
child.addLogicalLib("commons-logging");
|
|
||||||
|
|
||||||
Class testClass = child.loadClass(CustomConfigAPITestCase.class.getName());
|
|
||||||
return new PathableTestSuite(testClass, child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2005 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.log4j;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.PathableTestSuite;
|
|
||||||
import org.apache.commons.logging.PathableClassLoader;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TestCase for Log4J logging when the commons-logging jar file is in
|
|
||||||
* the parent classpath.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class CustomConfigFullTestCase extends CustomConfigTestCase {
|
|
||||||
|
|
||||||
|
|
||||||
public CustomConfigFullTestCase(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the tests included in this test suite.
|
|
||||||
*/
|
|
||||||
public static Test suite() throws Exception {
|
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
|
||||||
parent.useSystemLoader("junit.");
|
|
||||||
parent.addLogicalLib("commons-logging");
|
|
||||||
parent.addLogicalLib("log4j12");
|
|
||||||
|
|
||||||
PathableClassLoader child = new PathableClassLoader(parent);
|
|
||||||
child.addLogicalLib("testclasses");
|
|
||||||
|
|
||||||
Class testClass = child.loadClass(CustomConfigFullTestCase.class.getName());
|
|
||||||
return new PathableTestSuite(testClass, child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,293 +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.log4j;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
|
|
||||||
import org.apache.log4j.Level;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.apache.log4j.PropertyConfigurator;
|
|
||||||
import org.apache.log4j.spi.LoggingEvent;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.PathableTestSuite;
|
|
||||||
import org.apache.commons.logging.PathableClassLoader;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>TestCase for Log4J logging when running on a system with Log4J present,
|
|
||||||
* so that Log4J 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 {
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------- Constructors
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Construct a new instance of this test case.</p>
|
|
||||||
*
|
|
||||||
* @param name Name of the test case
|
|
||||||
*/
|
|
||||||
public CustomConfigTestCase(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------- Instance Variables
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>The <code>Appender</code> we are utilizing.</p>
|
|
||||||
*/
|
|
||||||
protected TestAppender appender = null;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>The <code>Logger</code> we are utilizing.</p>
|
|
||||||
*/
|
|
||||||
protected Logger logger = null;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>The message levels that should have been logged.</p>
|
|
||||||
*/
|
|
||||||
protected Level testLevels[] =
|
|
||||||
{ Level.INFO, Level.WARN, Level.ERROR, Level.FATAL };
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>The message strings that should have been logged.</p>
|
|
||||||
*/
|
|
||||||
protected String testMessages[] =
|
|
||||||
{ "info", "warn", "error", "fatal" };
|
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------- JUnit Infrastructure Methods
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up instance variables required by this test case.
|
|
||||||
*/
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
setUpAppender
|
|
||||||
("org/apache/commons/logging/log4j/CustomConfig.properties");
|
|
||||||
setUpLogger("TestLogger");
|
|
||||||
setUpFactory();
|
|
||||||
setUpLog("TestLogger");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the tests included in this test suite.
|
|
||||||
*/
|
|
||||||
public static Test suite() throws Exception {
|
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
|
||||||
parent.useSystemLoader("junit.");
|
|
||||||
|
|
||||||
PathableClassLoader child = new PathableClassLoader(parent);
|
|
||||||
child.addLogicalLib("testclasses");
|
|
||||||
child.addLogicalLib("log4j12");
|
|
||||||
child.addLogicalLib("commons-logging");
|
|
||||||
|
|
||||||
Class testClass = child.loadClass(CustomConfigTestCase.class.getName());
|
|
||||||
return new PathableTestSuite(testClass, child);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tear down instance variables required by this test case.
|
|
||||||
*/
|
|
||||||
public void tearDown() {
|
|
||||||
super.tearDown();
|
|
||||||
Logger.getRootLogger().removeAppender(appender);
|
|
||||||
appender = null;
|
|
||||||
logger = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------- Test Methods
|
|
||||||
|
|
||||||
|
|
||||||
// Test logging message strings with exceptions
|
|
||||||
public void testExceptionMessages() throws Exception {
|
|
||||||
logExceptionMessages();
|
|
||||||
checkLoggingEvents(true);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Test logging plain message strings
|
|
||||||
public void testPlainMessages() throws Exception {
|
|
||||||
|
|
||||||
logPlainMessages();
|
|
||||||
checkLoggingEvents(false);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Test pristine Appender instance
|
|
||||||
public void testPristineAppender() {
|
|
||||||
|
|
||||||
assertNotNull("Appender exists", appender);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Test pristine Log instance
|
|
||||||
public void testPristineLog() {
|
|
||||||
|
|
||||||
super.testPristineLog();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Test pristine Logger instance
|
|
||||||
public void testPristineLogger() {
|
|
||||||
|
|
||||||
assertNotNull("Logger exists", logger);
|
|
||||||
assertEquals("Logger level", Level.INFO, logger.getEffectiveLevel());
|
|
||||||
assertEquals("Logger name", "TestLogger", logger.getName());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Test Serializability of Log instance
|
|
||||||
public void testSerializable() throws Exception {
|
|
||||||
|
|
||||||
super.testSerializable();
|
|
||||||
testExceptionMessages();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------- Support Methods
|
|
||||||
|
|
||||||
|
|
||||||
// Check the log instance
|
|
||||||
protected void checkLog() {
|
|
||||||
|
|
||||||
assertNotNull("Log exists", log);
|
|
||||||
assertEquals("Log class",
|
|
||||||
"org.apache.commons.logging.impl.Log4J12Logger",
|
|
||||||
log.getClass().getName());
|
|
||||||
|
|
||||||
// Assert which logging levels have been enabled
|
|
||||||
assertTrue(log.isErrorEnabled());
|
|
||||||
assertTrue(log.isWarnEnabled());
|
|
||||||
assertTrue(log.isInfoEnabled());
|
|
||||||
assertTrue(!log.isDebugEnabled());
|
|
||||||
assertTrue(!log.isTraceEnabled());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Check the recorded messages
|
|
||||||
protected void checkLoggingEvents(boolean thrown) {
|
|
||||||
Iterator events = appender.events();
|
|
||||||
for (int i = 0; i < testMessages.length; i++) {
|
|
||||||
assertTrue("Logged event " + i + " exists",events.hasNext());
|
|
||||||
LoggingEvent event = (LoggingEvent) events.next();
|
|
||||||
assertEquals("LoggingEvent level",
|
|
||||||
testLevels[i], event.getLevel());
|
|
||||||
assertEquals("LoggingEvent message",
|
|
||||||
testMessages[i], event.getMessage());
|
|
||||||
/* Does not appear to be logged correctly?
|
|
||||||
assertEquals("LoggingEvent class",
|
|
||||||
this.getClass().getName(),
|
|
||||||
event.getLocationInformation().getClassName());
|
|
||||||
*/
|
|
||||||
/* Does not appear to be logged correctly?
|
|
||||||
if (thrown) {
|
|
||||||
assertEquals("LoggingEvent method",
|
|
||||||
"logExceptionMessages",
|
|
||||||
event.getLocationInformation().getMethodName());
|
|
||||||
} else {
|
|
||||||
assertEquals("LoggingEvent method",
|
|
||||||
"logPlainMessages",
|
|
||||||
event.getLocationInformation().getMethodName());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (thrown) {
|
|
||||||
assertNotNull("LoggingEvent thrown",
|
|
||||||
event.getThrowableInformation().getThrowableStrRep());
|
|
||||||
assertTrue("LoggingEvent thrown type",
|
|
||||||
event.getThrowableInformation()
|
|
||||||
.getThrowableStrRep()[0]
|
|
||||||
.indexOf("IndexOutOfBoundsException")>0);
|
|
||||||
} else {
|
|
||||||
assertNull("LoggingEvent thrown",
|
|
||||||
event.getThrowableInformation());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertTrue(!events.hasNext());
|
|
||||||
appender.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Log the messages with exceptions
|
|
||||||
protected void logExceptionMessages() {
|
|
||||||
Throwable t = new IndexOutOfBoundsException();
|
|
||||||
log.trace("trace", t); // Should not actually get logged
|
|
||||||
log.debug("debug", t); // Should not actually get logged
|
|
||||||
log.info("info", t);
|
|
||||||
log.warn("warn", t);
|
|
||||||
log.error("error", t);
|
|
||||||
log.fatal("fatal", t);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Log the plain messages
|
|
||||||
protected void logPlainMessages() {
|
|
||||||
log.trace("trace"); // Should not actually get logged
|
|
||||||
log.debug("debug"); // Should not actually get logged
|
|
||||||
log.info("info");
|
|
||||||
log.warn("warn");
|
|
||||||
log.error("error");
|
|
||||||
log.fatal("fatal");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Set up our custom Appender
|
|
||||||
protected void setUpAppender(String config) throws Exception {
|
|
||||||
Properties props = new Properties();
|
|
||||||
InputStream is =
|
|
||||||
this.getClass().getClassLoader().getResourceAsStream(config);
|
|
||||||
props.load(is);
|
|
||||||
is.close();
|
|
||||||
PropertyConfigurator.configure(props);
|
|
||||||
Enumeration appenders = Logger.getRootLogger().getAllAppenders();
|
|
||||||
appender = (TestAppender) appenders.nextElement();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Set up our custom Logger
|
|
||||||
protected void setUpLogger(String name) throws Exception {
|
|
||||||
logger = Logger.getLogger(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,194 +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.log4j;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.apache.commons.logging.PathableTestSuite;
|
|
||||||
import org.apache.commons.logging.PathableClassLoader;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>TestCase for Log4J logging when running on a system with
|
|
||||||
* zero configuration, and with Log4J present (so Log4J 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>
|
|
||||||
*
|
|
||||||
* @param name Name of the test case
|
|
||||||
*/
|
|
||||||
public DefaultConfigTestCase(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------- Instance Variables
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>The {@link LogFactory} implementation we have selected.</p>
|
|
||||||
*/
|
|
||||||
protected LogFactory factory = null;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>The {@link Log} implementation we have selected.</p>
|
|
||||||
*/
|
|
||||||
protected Log log = null;
|
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------- JUnit Infrastructure Methods
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up instance variables required by this test case.
|
|
||||||
*/
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
setUpFactory();
|
|
||||||
setUpLog("TestLogger");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the tests included in this test suite.
|
|
||||||
*/
|
|
||||||
public static Test suite() throws Exception {
|
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
|
||||||
parent.useSystemLoader("junit.");
|
|
||||||
|
|
||||||
PathableClassLoader child = new PathableClassLoader(parent);
|
|
||||||
child.addLogicalLib("testclasses");
|
|
||||||
child.addLogicalLib("log4j12");
|
|
||||||
child.addLogicalLib("commons-logging");
|
|
||||||
|
|
||||||
Class testClass = child.loadClass(DefaultConfigTestCase.class.getName());
|
|
||||||
return new PathableTestSuite(testClass, child);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tear down instance variables required by this test case.
|
|
||||||
*/
|
|
||||||
public void tearDown() {
|
|
||||||
log = null;
|
|
||||||
factory = null;
|
|
||||||
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",
|
|
||||||
factory.getClass().getName());
|
|
||||||
|
|
||||||
String names[] = factory.getAttributeNames();
|
|
||||||
assertNotNull("Names exists", names);
|
|
||||||
assertEquals("Names empty", 0, names.length);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Test Serializability of Log instance
|
|
||||||
public void testSerializable() throws Exception {
|
|
||||||
|
|
||||||
// Serialize and deserialize the instance
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
|
||||||
oos.writeObject(log);
|
|
||||||
oos.close();
|
|
||||||
ByteArrayInputStream bais =
|
|
||||||
new ByteArrayInputStream(baos.toByteArray());
|
|
||||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
|
||||||
log = (Log) ois.readObject();
|
|
||||||
ois.close();
|
|
||||||
|
|
||||||
// Check the characteristics of the resulting object
|
|
||||||
checkLog();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------- Support Methods
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Check the log instance
|
|
||||||
protected void checkLog() {
|
|
||||||
|
|
||||||
assertNotNull("Log exists", log);
|
|
||||||
assertEquals("Log class",
|
|
||||||
"org.apache.commons.logging.impl.Log4J12Logger",
|
|
||||||
log.getClass().getName());
|
|
||||||
|
|
||||||
// Can we call level checkers with no exceptions?
|
|
||||||
log.isDebugEnabled();
|
|
||||||
log.isErrorEnabled();
|
|
||||||
log.isFatalEnabled();
|
|
||||||
log.isInfoEnabled();
|
|
||||||
log.isTraceEnabled();
|
|
||||||
log.isWarnEnabled();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Set up factory instance
|
|
||||||
protected void setUpFactory() throws Exception {
|
|
||||||
factory = LogFactory.getFactory();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Set up log instance
|
|
||||||
protected void setUpLog(String name) throws Exception {
|
|
||||||
log = LogFactory.getLog(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user