KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jzonic > jlo > formatter > DefinedFormatterTest


1 package org.jzonic.jlo.formatter;
2
3 import junit.framework.TestCase;
4 import junit.framework.Test;
5 import junit.framework.TestSuite;
6 import org.jzonic.jlo.LogRecord;
7 import org.jzonic.jlo.Target;
8 import org.jzonic.jlo.NDC;
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13 /**
14  * User: Mecky
15  * Date: 19.07.2005
16  * Time: 12:57:12
17  */

18 public class DefinedFormatterTest extends TestCase {
19
20     public DefinedFormatterTest(java.lang.String JavaDoc testName) {
21         super(testName);
22     }
23
24     public static void main(java.lang.String JavaDoc[] args) {
25         junit.textui.TestRunner.run(suite());
26     }
27
28     public static Test suite() {
29         TestSuite suite = new TestSuite(DefinedFormatterTest.class);
30         return suite;
31     }
32
33     public void testFormatter() {
34         LogRecord lr = new LogRecord("Testmessage",Target.trace);
35         Map JavaDoc params = new HashMap JavaDoc();
36         params.put("format","---- ${text} ----");
37         DefinedFormatter df = new DefinedFormatter("Test");
38         df.setParameter(params);
39         String JavaDoc test = df.formatMessage(lr);
40         assertEquals("---- Testmessage ----",test);
41     }
42
43     public void testFormatter2() {
44         LogRecord lr = new LogRecord("Testmessage",Target.trace);
45         lr.setSourceClassName(getClass().getName());
46         Map JavaDoc params = new HashMap JavaDoc();
47         params.put("format","---- ${class} ${shortclass} ${text} ----");
48         DefinedFormatter df = new DefinedFormatter("Test");
49         df.setParameter(params);
50         String JavaDoc test = df.formatMessage(lr);
51         assertEquals("---- org.jzonic.jlo.formatter.DefinedFormatterTest DefinedFormatterTest Testmessage ----",test);
52     }
53
54     public void testFormatter3() {
55         LogRecord lr = new LogRecord("Testmessage",Target.trace);
56         lr.setSourceClassName(getClass().getName());
57         Map JavaDoc params = new HashMap JavaDoc();
58         params.put("format","[${target}] : ${text}");
59         DefinedFormatter df = new DefinedFormatter("Test");
60         df.setParameter(params);
61         String JavaDoc test = df.formatMessage(lr);
62         assertEquals("[TRACE] : Testmessage",test);
63     }
64
65     public void testFormatter4() {
66         LogRecord lr = new LogRecord("Testmessage",Target.trace);
67         lr.setSourceClassName(getClass().getName());
68         Map JavaDoc params = new HashMap JavaDoc();
69         params.put("format","${date:yyyy/MM} [${target}] : ${text}");
70         DefinedFormatter df = new DefinedFormatter("Test");
71         df.setParameter(params);
72         String JavaDoc test = df.formatMessage(lr);
73         assertEquals("2005/07 [TRACE] : Testmessage",test);
74     }
75
76     public void testFormatter5() {
77         LogRecord lr = new LogRecord("Testmessage",Target.trace);
78         lr.setSourceClassName(getClass().getName());
79         NDC.put("hello","world");
80         Map JavaDoc params = new HashMap JavaDoc();
81         params.put("format","${ndc} [${target}] : ${text}");
82         DefinedFormatter df = new DefinedFormatter("Test");
83         df.setParameter(params);
84         String JavaDoc test = df.formatMessage(lr);
85         assertEquals("[hello=world] [TRACE] : Testmessage",test);
86     }
87 }
88
Popular Tags