Added new optional subcomponent consisting of non-core implementations. Initial contents MemoryLog, a log implementation intended for use when unit testing. Issue #27663. Contributed by Joerg Schaible.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@139055 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
52
optional/src/test/org/apache/commons/logging/TestAll.java
Normal file
52
optional/src/test/org/apache/commons/logging/TestAll.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2004 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.commons.logging;
|
||||
|
||||
import junit.framework.*;
|
||||
import org.apache.commons.logging.impl.MemoryLogTest;
|
||||
|
||||
/**
|
||||
* <p> The build script calls just one <code>TestSuite</code> - this one!
|
||||
* All tests should be written into separate <code>TestSuite</code>'s
|
||||
* and added to this. Don't clutter this class with implementations. </p>
|
||||
*
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
public class TestAll extends TestCase {
|
||||
|
||||
public TestAll(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
|
||||
suite.addTest(MemoryLogTest.suite());
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
/**
|
||||
* This allows the tests to run as a standalone application.
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
String[] testCaseName = { TestAll.class.getName() };
|
||||
junit.textui.TestRunner.main(testCaseName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.impl.MemoryLog;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
/**
|
||||
* Test the MemoryLog.
|
||||
* @author Jörg Schaible
|
||||
*/
|
||||
public class MemoryLogTest
|
||||
extends TestCase {
|
||||
|
||||
public MemoryLogTest(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TestCase#setUp()
|
||||
*/
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
MemoryLog.reset();
|
||||
}
|
||||
|
||||
public Log getLogObject()
|
||||
{
|
||||
return (Log) new MemoryLog(this.getClass().getName());
|
||||
}
|
||||
|
||||
public final void testGetLogEntries()
|
||||
{
|
||||
MemoryLog log = (MemoryLog)getLogObject();
|
||||
log.setLevel(MemoryLog.LOG_LEVEL_DEBUG);
|
||||
log.trace("trace");
|
||||
log.debug("debug");
|
||||
log.info("info");
|
||||
log.warn("warn");
|
||||
log.error("error", new RuntimeException("error"));
|
||||
log.fatal("fatal", new RuntimeException("fatal"));
|
||||
List list = MemoryLog.getLogEntries();
|
||||
assertEquals(5, list.size());
|
||||
assertEquals("debug",((MemoryLog.Entry)list.get(0)).getMessage());
|
||||
assertEquals("info",((MemoryLog.Entry)list.get(1)).getMessage());
|
||||
assertEquals("warn",((MemoryLog.Entry)list.get(2)).getMessage());
|
||||
assertEquals("error",((MemoryLog.Entry)list.get(3)).getMessage());
|
||||
assertEquals("error",((MemoryLog.Entry)list.get(3)).getThrowable().getMessage());
|
||||
assertEquals("fatal",((MemoryLog.Entry)list.get(4)).getMessage());
|
||||
assertEquals("fatal",((MemoryLog.Entry)list.get(4)).getThrowable().getMessage());
|
||||
MemoryLog.reset();
|
||||
assertEquals(0, MemoryLog.getLogEntries().size());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(MemoryLogTest.suite());
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
|
||||
suite.addTestSuite(MemoryLogTest.class);
|
||||
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user