1 4 5 package org.objectweb.util.monolog.log4j; 6 7 import org.objectweb.util.monolog.wrapper.log4j.PatternConverter; 8 import org.objectweb.util.monolog.TestHelper; 9 import org.objectweb.util.monolog.TestSuite; 10 11 15 public class TestPattern extends TestHelper { 16 17 20 public static void main(String args[]) { 21 if (args.length < 1) { 22 System.out.println("Syntax error !"); 23 System.out.println("java TestIntermediateLevel <logger factory class name>"); 24 System.exit(1); 25 } 26 TestHelper.run(TestPattern.class, new String [0], new String [0], args[0]); 27 } 28 29 32 public static TestSuite getTestSuite(String lfcn) { 33 return TestHelper.getTestSuite(TestPattern.class, new String [0], 34 new String [0], lfcn); 35 } 36 37 public void testConvertMonolog2Log4j() { 38 assertEquals("level pattern", 39 "%p", PatternConverter.monolog2log4j("%l")); 40 assertEquals("message pattern", 41 "%m", PatternConverter.monolog2log4j("%m")); 42 assertEquals("topic pattern", 43 "%c", PatternConverter.monolog2log4j("%t")); 44 assertEquals("thread pattern", 45 "%t", PatternConverter.monolog2log4j("%h")); 46 assertEquals("date pattern", 47 "%d", PatternConverter.monolog2log4j("%d")); 48 assertEquals("method pattern", 49 "%M", PatternConverter.monolog2log4j("%M")); 50 assertEquals("object pattern", 51 "%C", PatternConverter.monolog2log4j("%O")); 52 assertEquals("line number pattern", 53 "%L", PatternConverter.monolog2log4j("%L")); 54 assertEquals("percent pattern", 55 "%%", PatternConverter.monolog2log4j("%%")); 56 57 assertEquals("Usual case", 58 "%p %M %m%n", PatternConverter.monolog2log4j("%l %M %m%n")); 59 60 assertEquals("two elements", 61 "%p%m", PatternConverter.monolog2log4j("%l%m")); 62 63 assertEquals("two elements with a space character", 64 "%p %m", PatternConverter.monolog2log4j("%l %m")); 65 66 assertEquals("left fixed minimal pattern size", 67 "%20c", PatternConverter.monolog2log4j("%20t")); 68 69 assertEquals("right fixed minimal pattern size", 70 "%-20c", PatternConverter.monolog2log4j("%-20t")); 71 72 assertEquals("truncate pattern", 73 "%.20c", PatternConverter.monolog2log4j("%.20t")); 74 75 assertEquals("complex 1", 76 "%20.30c", PatternConverter.monolog2log4j("%20.30t")); 77 78 assertEquals("complex 1", 79 "%-20.30c", PatternConverter.monolog2log4j("%-20.30t")); 80 81 } 82 public void testConvertLog4j2Monolog() { 83 assertEquals("level pattern", 84 "%l", PatternConverter.log4j2monolog("%p")); 85 assertEquals("message pattern", 86 "%m", PatternConverter.log4j2monolog("%m")); 87 assertEquals("topic pattern", 88 "%t", PatternConverter.log4j2monolog("%c")); 89 assertEquals("thread pattern", 90 "%h", PatternConverter.log4j2monolog("%t")); 91 assertEquals("date pattern", 92 "%d", PatternConverter.log4j2monolog("%d")); 93 assertEquals("method pattern", 94 "%M", PatternConverter.log4j2monolog("%M")); 95 assertEquals("object pattern", 96 "%O", PatternConverter.log4j2monolog("%C")); 97 assertEquals("line number pattern", 98 "%L", PatternConverter.log4j2monolog("%L")); 99 assertEquals("percent pattern", 100 "%%", PatternConverter.log4j2monolog("%%")); 101 102 assertEquals("Usual case", 103 "%l %M %m%n", PatternConverter.log4j2monolog("%p %M %m%n")); 104 105 assertEquals("two elements", 106 "%l%m", PatternConverter.log4j2monolog("%p%m")); 107 108 assertEquals("two elements with a space character", 109 "%l %m", PatternConverter.log4j2monolog("%p %m")); 110 111 assertEquals("left fixed minimal pattern size", 112 "%20t", PatternConverter.log4j2monolog("%20c")); 113 114 assertEquals("right fixed minimal pattern size", 115 "%-20t", PatternConverter.log4j2monolog("%-20c")); 116 117 assertEquals("truncate pattern", 118 "%.20t", PatternConverter.log4j2monolog("%.20c")); 119 120 assertEquals("complex 1", 121 "%20.30t", PatternConverter.log4j2monolog("%20.30c")); 122 123 assertEquals("complex 1", 124 "%-20.30t", PatternConverter.log4j2monolog("%-20.30c")); 125 126 } 127 } 128 | Popular Tags |