01: package org.jzonic.jlo.formatter;
02:
03: import junit.framework.TestCase;
04: import junit.framework.Test;
05: import junit.framework.TestSuite;
06: import org.jzonic.jlo.LogRecord;
07: import org.jzonic.jlo.Target;
08: import org.jzonic.jlo.NDC;
09:
10: import java.util.HashMap;
11: import java.util.Map;
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 testName) {
21: super (testName);
22: }
23:
24: public static void main(java.lang.String[] 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 params = new HashMap();
36: params.put("format", "---- ${text} ----");
37: DefinedFormatter df = new DefinedFormatter("Test");
38: df.setParameter(params);
39: String 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 params = new HashMap();
47: params
48: .put("format",
49: "---- ${class} ${shortclass} ${text} ----");
50: DefinedFormatter df = new DefinedFormatter("Test");
51: df.setParameter(params);
52: String test = df.formatMessage(lr);
53: assertEquals(
54: "---- org.jzonic.jlo.formatter.DefinedFormatterTest DefinedFormatterTest Testmessage ----",
55: test);
56: }
57:
58: public void testFormatter3() {
59: LogRecord lr = new LogRecord("Testmessage", Target.trace);
60: lr.setSourceClassName(getClass().getName());
61: Map params = new HashMap();
62: params.put("format", "[${target}] : ${text}");
63: DefinedFormatter df = new DefinedFormatter("Test");
64: df.setParameter(params);
65: String test = df.formatMessage(lr);
66: assertEquals("[TRACE] : Testmessage", test);
67: }
68:
69: public void testFormatter4() {
70: LogRecord lr = new LogRecord("Testmessage", Target.trace);
71: lr.setSourceClassName(getClass().getName());
72: Map params = new HashMap();
73: params.put("format", "${date:yyyy/MM} [${target}] : ${text}");
74: DefinedFormatter df = new DefinedFormatter("Test");
75: df.setParameter(params);
76: String test = df.formatMessage(lr);
77: assertEquals("2005/07 [TRACE] : Testmessage", test);
78: }
79:
80: public void testFormatter5() {
81: LogRecord lr = new LogRecord("Testmessage", Target.trace);
82: lr.setSourceClassName(getClass().getName());
83: NDC.put("hello", "world");
84: Map params = new HashMap();
85: params.put("format", "${ndc} [${target}] : ${text}");
86: DefinedFormatter df = new DefinedFormatter("Test");
87: df.setParameter(params);
88: String test = df.formatMessage(lr);
89: assertEquals("[hello=world] [TRACE] : Testmessage", test);
90: }
91: }
|