1 /*
2 * Copyright (C) The Spice Group. All rights reserved.
3 *
4 * This software is published under the terms of the Spice
5 * Software License version 1.1, a copy of which has been included
6 * with this distribution in the LICENSE.txt file.
7 */
8 package org.codehaus.spice.loggerstore;
9
10 import java.util.Properties;
11 import org.apache.avalon.excalibur.logger.Log4JLoggerManager;
12 import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
13 import org.apache.avalon.excalibur.logger.LoggerManager;
14 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
15 import org.apache.avalon.framework.context.DefaultContext;
16 import org.apache.avalon.framework.logger.NullLogger;
17 import org.codehaus.spice.loggerstore.stores.ConsoleLoggerStore;
18 import org.codehaus.spice.loggerstore.stores.Jdk14LoggerStore;
19 import org.codehaus.spice.loggerstore.stores.Log4JLoggerStore;
20 import org.codehaus.spice.loggerstore.stores.LogKitLoggerStore;
21 import org.jcontainer.dna.impl.ConsoleLogger;
22
23 /***
24 * Test case for LoggerStore
25 *
26 * @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
27 * @author Peter Donald
28 */
29 public class LoggerStoreTestCase
30 extends AbstractTestCase
31 {
32
33 public LoggerStoreTestCase( final String name )
34 {
35 super( name );
36 }
37
38 public void testNullRootLogger()
39 throws Exception
40 {
41 final LoggerStore store = new MalformedLoggerStore();
42 try
43 {
44 store.getLogger();
45 fail( "Expected to get an exception as no root logger is defined." );
46 }
47 catch( final Exception e )
48 {
49 }
50 }
51
52 // ConsoleLoggerStore tests
53 public void testConsoleLoggerStore()
54 throws Exception
55 {
56 final LoggerStore store =
57 new ConsoleLoggerStore( ConsoleLogger.LEVEL_DEBUG );
58 performConsoleTest( store, ConsoleLogger.LEVEL_DEBUG );
59 }
60
61 public void testConsoleLoggerStoreNoDebug()
62 throws Exception
63 {
64 final LoggerStore store =
65 new ConsoleLoggerStore( ConsoleLogger.LEVEL_DEBUG );
66 performConsoleTest( store, ConsoleLogger.LEVEL_NONE );
67 }
68
69 // LogKitLoggerStore tests
70 public void testLogKitExcaliburConfiguration()
71 throws Exception
72 {
73 final LoggerManager loggerManager = new LogKitLoggerManager();
74 final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
75 final LoggerStore store =
76 new LogKitLoggerStore( loggerManager,
77 null,
78 null,
79 builder.build(
80 getResource( "logkit-excalibur.xml" ) ) );
81 runLoggerTest( "logkit-excalibur", store, ConsoleLogger.LEVEL_DEBUG );
82 }
83
84 public void testLogKitExcaliburConfigurationWithLogger()
85 throws Exception
86 {
87 final LoggerManager loggerManager = new LogKitLoggerManager();
88 final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
89 final LoggerStore store =
90 new LogKitLoggerStore( loggerManager,
91 new NullLogger(),
92 null,
93 builder.build(
94 getResource( "logkit-excalibur.xml" ) ) );
95 runLoggerTest( "logkit-excalibur", store, ConsoleLogger.LEVEL_DEBUG );
96 }
97
98 public void testLogKitExcaliburConfigurationWithContext()
99 throws Exception
100 {
101 final LoggerManager loggerManager = new LogKitLoggerManager();
102 final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
103 final LoggerStore store =
104 new LogKitLoggerStore( loggerManager,
105 null,
106 new DefaultContext(),
107 builder.build(
108 getResource( "logkit-excalibur.xml" ) ) );
109 runLoggerTest( "logkit-excalibur", store, ConsoleLogger.LEVEL_DEBUG );
110 }
111
112 public void testLogKitExcaliburConfigurationNoDebug()
113 throws Exception
114 {
115 final LoggerManager loggerManager = new LogKitLoggerManager();
116 final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
117 final LoggerStore store =
118 new LogKitLoggerStore( loggerManager,
119 null,
120 null,
121 builder.build(
122 getResource( "logkit-excalibur.xml" ) ) );
123 runLoggerTest( "logkit-excalibur", store, ConsoleLogger.LEVEL_NONE );
124 }
125
126 public void testLogKitExcaliburConfigurationNoLog()
127 throws Exception
128 {
129 final LoggerManager loggerManager = new LogKitLoggerManager();
130 final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
131 final LoggerStore store =
132 new LogKitLoggerStore( loggerManager,
133 null,
134 null,
135 builder.build(
136 getResource( "logkit-excalibur.xml" ) ) );
137 runLoggerTest( "logkit-excalibur", store );
138 }
139
140 public void testLogKitExcaliburConfigurationNoManager()
141 throws Exception
142 {
143 try
144 {
145 final LoggerStore store =
146 new LogKitLoggerStore( null, null, null, null );
147 fail( "Expected to get an exception as LoggerManager is null." );
148 }
149 catch( final Exception e )
150 {
151 }
152 }
153
154 public void testLogKitExcaliburConfigurationInvalidManager()
155 throws Exception
156 {
157 try
158 {
159 final LoggerManager loggerManager = new Log4JLoggerManager();
160 final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
161 final LoggerStore store =
162 new LogKitLoggerStore( loggerManager,
163 null,
164 null,
165 builder.build(
166 getResource( "log4j.xml" ) ) );
167 fail( "Expected to get an exception as LoggerManager is invalid." );
168 }
169 catch( final Exception e )
170 {
171 }
172 }
173
174 // Log4JLoggerStore tests
175 public void testLog4JElementConfiguration()
176 throws Exception
177 {
178 final LoggerStore store =
179 new Log4JLoggerStore(
180 buildElement( getResource( "log4j.xml" ),
181 new org.apache.log4j.xml.Log4jEntityResolver(),
182 null ) );
183 runLoggerTest( "log4j-xml", store, ConsoleLogger.LEVEL_DEBUG );
184 }
185
186 public void testLog4JElementConfigurationNoDebug()
187 throws Exception
188 {
189 final LoggerStore store =
190 new Log4JLoggerStore(
191 buildElement( getResource( "log4j.xml" ),
192 new org.apache.log4j.xml.Log4jEntityResolver(),
193 null ) );
194 runLoggerTest( "log4j-xml", store, ConsoleLogger.LEVEL_NONE );
195 }
196
197 public void testLog4JElementConfigurationNoLog()
198 throws Exception
199 {
200 final LoggerStore store =
201 new Log4JLoggerStore(
202 buildElement( getResource( "log4j.xml" ),
203 new org.apache.log4j.xml.Log4jEntityResolver(),
204 null ) );
205 runLoggerTest( "log4j-xml", store );
206 }
207
208 public void testLog4JInputStreamConfiguration()
209 throws Exception
210 {
211 final LoggerStore store =
212 new Log4JLoggerStore( getResource( "log4j.xml" ) );
213 runLoggerTest( "log4j-xml", store, ConsoleLogger.LEVEL_DEBUG );
214 }
215
216 public void testLog4JInputStreamConfigurationNoDebug()
217 throws Exception
218 {
219 final LoggerStore store =
220 new Log4JLoggerStore( getResource( "log4j.xml" ) );
221 runLoggerTest( "log4j-xml", store, ConsoleLogger.LEVEL_NONE );
222 }
223
224 public void testLog4JInputStreamConfigurationNoLog()
225 throws Exception
226 {
227 final LoggerStore store =
228 new Log4JLoggerStore( getResource( "log4j.xml" ) );
229 runLoggerTest( "log4j-xml", store );
230 }
231
232 public void testLog4JPropertiesConfiguration()
233 throws Exception
234 {
235 final Properties properties = new Properties();
236 properties.load( getResource( "log4j.properties" ) );
237 final LoggerStore store =
238 new Log4JLoggerStore( properties );
239 runLoggerTest( "log4j-properties", store, ConsoleLogger.LEVEL_DEBUG );
240 }
241
242 public void testLog4JPropertiesConfigurationNoDebug()
243 throws Exception
244 {
245 final Properties properties = new Properties();
246 properties.load( getResource( "log4j.properties" ) );
247 final LoggerStore store =
248 new Log4JLoggerStore( properties );
249 runLoggerTest( "log4j-properties", store, ConsoleLogger.LEVEL_NONE );
250 }
251
252 public void testLog4JPropertiesConfigurationNoLog()
253 throws Exception
254 {
255 final Properties properties = new Properties();
256 properties.load( getResource( "log4j.properties" ) );
257 final LoggerStore store =
258 new Log4JLoggerStore( properties );
259 runLoggerTest( "log4j-properties", store );
260 }
261
262 // JDK14LoggerStore tests
263 public void testJDK14Configuration()
264 throws Exception
265 {
266 final LoggerStore store =
267 new Jdk14LoggerStore( getResource( "logging.properties" ) );
268 runLoggerTest( "jdk14", store, ConsoleLogger.LEVEL_DEBUG );
269 }
270
271 public void testJDK14ConfigurationNoDebug()
272 throws Exception
273 {
274 final LoggerStore store =
275 new Jdk14LoggerStore( getResource( "logging.properties" ) );
276 runLoggerTest( "jdk14", store, ConsoleLogger.LEVEL_NONE );
277 }
278
279 public void testJDK14ConfigurationNoLog()
280 throws Exception
281 {
282 final LoggerStore store =
283 new Jdk14LoggerStore( getResource( "logging.properties" ) );
284 runLoggerTest( "jdk14", store );
285 }
286
287 }
This page was automatically generated by Maven