1 package org.jacorb.test.util; 2 3 22 23 import java.util.Properties ; 24 25 import junit.framework.TestSuite; 26 27 import org.apache.avalon.framework.logger.Logger; 28 import org.jacorb.config.Configuration; 29 30 import org.jacorb.test.common.*; 31 32 38 39 public class LogKitLoggerFactoryTest 40 extends JacORBTestCase 41 { 42 44 private Configuration config; 45 private int defaultPriority = 0; 46 47 49 public LogKitLoggerFactoryTest(String name) 50 { 51 super(name); 52 } 53 54 56 public void setUp() 57 throws Exception 58 { 59 Properties props = new Properties (); 60 61 props.setProperty("jacorb.log.verbosity", "2"); 62 props.setProperty("jacorb.component.log.verbosity", "3"); 63 props.setProperty("jacorb.component.subcomponent.log.verbosity", "4"); 64 65 props.setProperty("jacorb.trailingspace.test1", "INFO "); 66 props.setProperty("jacorb.trailingspace.test2", "INFO"); 67 68 config = Configuration.getConfiguration(props, null, false); 69 70 defaultPriority = config.getAttributeAsInteger("jacorb.log.default.verbosity",0); 71 } 72 73 private int priorityFor(Logger l) 74 { 75 if (l.isDebugEnabled()) 76 return 4; 77 else if (l.isInfoEnabled()) 78 return 3; 79 else if (l.isWarnEnabled()) 80 return 2; 81 else if (l.isErrorEnabled()) 82 return 1; 83 return 0; 84 } 85 86 public void testGetPriorityForNamedLogger() 87 throws Exception 88 { 89 assertEquals(defaultPriority, priorityFor(config.getNamedLogger("foologger"))); 90 91 assertEquals(2, priorityFor(config.getNamedLogger("jacorb"))); 92 93 assertEquals(2, priorityFor(config.getNamedLogger("jacorb.other_component"))); 94 95 assertEquals(2, priorityFor(config.getNamedLogger("jacorb.other_component.sub"))); 96 97 98 assertEquals(3, priorityFor(config.getNamedLogger("jacorb.component"))); 99 100 assertEquals(3, priorityFor(config.getNamedLogger("jacorb.component.subcomponent2"))); 101 102 assertEquals(4, priorityFor(config.getNamedLogger("jacorb.component.subcomponent"))); 103 104 assertEquals(4, priorityFor(config.getNamedLogger("jacorb.component.subcomponent.sub"))); 105 106 assertEquals(priorityFor(config.getNamedLogger("jacorb.trailingspace.test1")), 107 priorityFor(config.getNamedLogger("jacorb.trailingspace.test2"))); 108 } 109 110 111 public static TestSuite suite() 112 { 113 TestSuite suite = new TestSuite(LogKitLoggerFactoryTest.class); 114 115 return suite; 116 } 117 } 118 | Popular Tags |