001: /**
002: * Copyright (C) 2002
003: */package org.objectweb.util.monolog.log4j;
004:
005: import org.objectweb.util.monolog.wrapper.log4j.PatternConverter;
006: import org.objectweb.util.monolog.TestHelper;
007: import org.objectweb.util.monolog.TestSuite;
008:
009: /**
010: *
011: * @author Sebastien Chassande-Barrioz
012: */
013: public class TestPattern extends TestHelper {
014:
015: /**
016: * For running the TestLogger suite standalone.
017: */
018: public static void main(String args[]) {
019: if (args.length < 1) {
020: System.out.println("Syntax error !");
021: System.out
022: .println("java TestIntermediateLevel <logger factory class name>");
023: System.exit(1);
024: }
025: TestHelper.run(TestPattern.class, new String[0], new String[0],
026: args[0]);
027: }
028:
029: /**
030: * Return the test suite associated to this class.
031: */
032: public static TestSuite getTestSuite(String lfcn) {
033: return TestHelper.getTestSuite(TestPattern.class,
034: new String[0], new String[0], lfcn);
035: }
036:
037: public void testConvertMonolog2Log4j() {
038: assertEquals("level pattern", "%p", PatternConverter
039: .monolog2log4j("%l"));
040: assertEquals("message pattern", "%m", PatternConverter
041: .monolog2log4j("%m"));
042: assertEquals("topic pattern", "%c", PatternConverter
043: .monolog2log4j("%t"));
044: assertEquals("thread pattern", "%t", PatternConverter
045: .monolog2log4j("%h"));
046: assertEquals("date pattern", "%d", PatternConverter
047: .monolog2log4j("%d"));
048: assertEquals("method pattern", "%M", PatternConverter
049: .monolog2log4j("%M"));
050: assertEquals("object pattern", "%C", PatternConverter
051: .monolog2log4j("%O"));
052: assertEquals("line number pattern", "%L", PatternConverter
053: .monolog2log4j("%L"));
054: assertEquals("percent pattern", "%%", PatternConverter
055: .monolog2log4j("%%"));
056:
057: assertEquals("Usual case", "%p %M %m%n", PatternConverter
058: .monolog2log4j("%l %M %m%n"));
059:
060: assertEquals("two elements", "%p%m", PatternConverter
061: .monolog2log4j("%l%m"));
062:
063: assertEquals("two elements with a space character", "%p %m",
064: PatternConverter.monolog2log4j("%l %m"));
065:
066: assertEquals("left fixed minimal pattern size", "%20c",
067: PatternConverter.monolog2log4j("%20t"));
068:
069: assertEquals("right fixed minimal pattern size", "%-20c",
070: PatternConverter.monolog2log4j("%-20t"));
071:
072: assertEquals("truncate pattern", "%.20c", PatternConverter
073: .monolog2log4j("%.20t"));
074:
075: assertEquals("complex 1", "%20.30c", PatternConverter
076: .monolog2log4j("%20.30t"));
077:
078: assertEquals("complex 1", "%-20.30c", PatternConverter
079: .monolog2log4j("%-20.30t"));
080:
081: }
082:
083: public void testConvertLog4j2Monolog() {
084: assertEquals("level pattern", "%l", PatternConverter
085: .log4j2monolog("%p"));
086: assertEquals("message pattern", "%m", PatternConverter
087: .log4j2monolog("%m"));
088: assertEquals("topic pattern", "%t", PatternConverter
089: .log4j2monolog("%c"));
090: assertEquals("thread pattern", "%h", PatternConverter
091: .log4j2monolog("%t"));
092: assertEquals("date pattern", "%d", PatternConverter
093: .log4j2monolog("%d"));
094: assertEquals("method pattern", "%M", PatternConverter
095: .log4j2monolog("%M"));
096: assertEquals("object pattern", "%O", PatternConverter
097: .log4j2monolog("%C"));
098: assertEquals("line number pattern", "%L", PatternConverter
099: .log4j2monolog("%L"));
100: assertEquals("percent pattern", "%%", PatternConverter
101: .log4j2monolog("%%"));
102:
103: assertEquals("Usual case", "%l %M %m%n", PatternConverter
104: .log4j2monolog("%p %M %m%n"));
105:
106: assertEquals("two elements", "%l%m", PatternConverter
107: .log4j2monolog("%p%m"));
108:
109: assertEquals("two elements with a space character", "%l %m",
110: PatternConverter.log4j2monolog("%p %m"));
111:
112: assertEquals("left fixed minimal pattern size", "%20t",
113: PatternConverter.log4j2monolog("%20c"));
114:
115: assertEquals("right fixed minimal pattern size", "%-20t",
116: PatternConverter.log4j2monolog("%-20c"));
117:
118: assertEquals("truncate pattern", "%.20t", PatternConverter
119: .log4j2monolog("%.20c"));
120:
121: assertEquals("complex 1", "%20.30t", PatternConverter
122: .log4j2monolog("%20.30c"));
123:
124: assertEquals("complex 1", "%-20.30t", PatternConverter
125: .log4j2monolog("%-20.30c"));
126:
127: }
128: }
|