KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jzonic > jlo > LogPipeTest


1 /*
2  * LoggerTest.java
3  * JUnit based test
4  *
5  * Created on 19. Januar 2003, 18:09
6  */

7
8 package org.jzonic.jlo;
9
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 JavaDoc;
16 /**
17  *
18  * @author Administrator
19  */

20 public class LogPipeTest extends TestCase {
21         
22     private static final LogManager manager = LogManager.getInstance();
23     
24     public LogPipeTest(java.lang.String JavaDoc testName) {
25         super(testName);
26     }
27     
28     public void setUp() throws Exception JavaDoc {
29     }
30     
31     public static void main(java.lang.String JavaDoc[] args) {
32         junit.textui.TestRunner.run(suite());
33     }
34     
35     public static Test suite() {
36         TestSuite suite = new TestSuite(LogPipeTest.class);
37         return suite;
38     }
39     
40     public void testSimpleLogging() {
41         MockHandler mockHandler = getFreshHandler("TestGenerator");
42         MockHandler pipeHandler = getFreshHandler("PipeGenerator");
43         Logger logger = LogManager.getLogger("org.jzonic.jlo");
44         logger.info("debug message");
45         Vector JavaDoc entries = mockHandler.getMessages();
46         assertEquals(1,entries.size());
47         entries = pipeHandler.getMessages();
48         assertEquals(1,entries.size());
49         logger.info("Exception is coming here");
50         entries = mockHandler.getMessages();
51         assertEquals(2,entries.size());
52         entries = pipeHandler.getMessages();
53         assertEquals(3,entries.size());
54     }
55         
56     private MockHandler getFreshHandler(String JavaDoc handlerName) {
57         LogConfiguration config = manager.getLogConfiguration();
58         assertNotNull(config);
59         LogGenerator lg = config.getLogGenerator(handlerName);
60         assertNotNull(lg);
61         MockHandler mockHandler = (MockHandler)lg.getHandler();
62         mockHandler.clear();
63         return mockHandler;
64     }
65     
66 }
67
Popular Tags