KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > util > LogKitLoggerFactoryTest


1 package org.jacorb.test.util;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2001 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import java.util.Properties JavaDoc;
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 /**
33  * Unit Test for class LogKitLoggerFactory
34  * @jacorb-since 2.2
35  * @author Alphonse Bendt
36  * @version $Id: LogKitLoggerFactoryTest.java,v 1.6 2005/05/16 17:38:36 andre.spiegel Exp $
37  */

38
39 public class LogKitLoggerFactoryTest
40     extends JacORBTestCase
41 {
42     ////////////////////////////////////////
43

44     private Configuration config;
45     private int defaultPriority = 0;
46
47     ////////////////////////////////////////
48

49     public LogKitLoggerFactoryTest(String JavaDoc name)
50     {
51         super(name);
52     }
53
54     ////////////////////////////////////////
55

56     public void setUp()
57         throws Exception JavaDoc
58     {
59         Properties JavaDoc props = new Properties JavaDoc();
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 JavaDoc
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