01: /*
02: * LoggerTest.java
03: * JUnit based test
04: *
05: * Created on 19. Januar 2003, 18:09
06: */
07:
08: package org.jzonic.jlo;
09:
10: import junit.framework.Test;
11: import junit.framework.TestCase;
12: import junit.framework.TestSuite;
13: import org.jzonic.jlo.handler.MockHandler;
14:
15: import java.util.Vector;
16:
17: /**
18: *
19: * @author Administrator
20: */
21: public class LogPipeTest extends TestCase {
22:
23: private static final LogManager manager = LogManager.getInstance();
24:
25: public LogPipeTest(java.lang.String testName) {
26: super (testName);
27: }
28:
29: public void setUp() throws Exception {
30: }
31:
32: public static void main(java.lang.String[] args) {
33: junit.textui.TestRunner.run(suite());
34: }
35:
36: public static Test suite() {
37: TestSuite suite = new TestSuite(LogPipeTest.class);
38: return suite;
39: }
40:
41: public void testSimpleLogging() {
42: MockHandler mockHandler = getFreshHandler("TestGenerator");
43: MockHandler pipeHandler = getFreshHandler("PipeGenerator");
44: Logger logger = LogManager.getLogger("org.jzonic.jlo");
45: logger.info("debug message");
46: Vector entries = mockHandler.getMessages();
47: assertEquals(1, entries.size());
48: entries = pipeHandler.getMessages();
49: assertEquals(1, entries.size());
50: logger.info("Exception is coming here");
51: entries = mockHandler.getMessages();
52: assertEquals(2, entries.size());
53: entries = pipeHandler.getMessages();
54: assertEquals(3, entries.size());
55: }
56:
57: private MockHandler getFreshHandler(String handlerName) {
58: LogConfiguration config = manager.getLogConfiguration();
59: assertNotNull(config);
60: LogGenerator lg = config.getLogGenerator(handlerName);
61: assertNotNull(lg);
62: MockHandler mockHandler = (MockHandler) lg.getHandler();
63: mockHandler.clear();
64: return mockHandler;
65: }
66:
67: }
|