KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > logging > log4j > AbstractLog4jLogTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.system.logging.log4j;
18
19 import junit.framework.TestCase;
20 import org.apache.log4j.Priority;
21 import org.apache.log4j.Level;
22 import org.apache.commons.logging.Log;
23
24 /**
25  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
26  */

27 public class AbstractLog4jLogTest extends TestCase {
28     protected final static Object JavaDoc MESSAGE = new Object JavaDoc();
29     protected final static Throwable JavaDoc THROWABLE = new Throwable JavaDoc();
30     protected MockLogger mockLogger;
31     protected Log log;
32     protected String JavaDoc logFQCN;
33
34     protected void doTestDelegatedToLog(Priority priority, Object JavaDoc object, Throwable JavaDoc throwable) {
35         assertTrue("Method delegates to Logger.log",
36                 mockLogger.logCalled
37                 & mockLogger.calledWithString == logFQCN
38                 & mockLogger.calledWithPriority == priority
39                 & mockLogger.calledWithObject == object
40                 & mockLogger.calledWithThrowable == throwable);
41     }
42
43     /**
44      * Tests {@link org.apache.commons.logging.Log#isWarnEnabled()} method.
45      * Tests that it delegates to {@link org.apache.log4j.Category#isEnabledFor(Priority)}
46      * with {@link org.apache.log4j.Level#WARN} as an argument.
47      */

48     public void testIsWarnEnabled() {
49         log.isWarnEnabled();
50         assertTrue("Method delegates to Logger.isEnabledFor",
51                 mockLogger.isEnabledForCalled
52                 & mockLogger.calledWithPriority==Level.WARN);
53     }
54
55     /**
56      * Tests {@link org.apache.commons.logging.Log#warn(Object) method.
57      * Tests that it delegates to
58      * {@link org.apache.log4j.Category#log(String, Priority, Object, Throwable)}
59      * with {@link org.apache.log4j.Level#WARN} level, specified message and <code>null</code> throwable.
60      */

61     public void testWarnNull() {
62         log.warn(MESSAGE);
63         doTestDelegatedToLog(Level.WARN, MESSAGE, null);
64     }
65
66     /**
67      * Tests {@link org.apache.commons.logging.Log#warn(Object,java.lang.Throwable throwable) method.
68      * Tests that it delegates to
69      * {@link org.apache.log4j.Category#log(String, Priority, Object, Throwable)}
70      * with {@link org.apache.log4j.Level#WARN} level, specified message and throwable.
71      */

72     public void testWarnThrowable() {
73         log.warn(MESSAGE, THROWABLE);
74         doTestDelegatedToLog(Level.WARN, MESSAGE, THROWABLE);
75     }
76
77     /**
78      * Tests {@link org.apache.commons.logging.Log#isErrorEnabled()} method.
79      * Tests that it delegates to {@link org.apache.log4j.Category#isEnabledFor(Priority)}
80      * with {@link org.apache.log4j.Level#ERROR} as an argument.
81      */

82     public void testIsErrorEnabled() {
83         log.isErrorEnabled();
84         assertTrue("Method delegates to Logger.isEnabledFor",
85                 mockLogger.isEnabledForCalled
86                 & mockLogger.calledWithPriority==Level.ERROR);
87     }
88
89     /**
90      * Tests {@link org.apache.commons.logging.Log#error(Object) method.
91      * Tests that it delegates to
92      * {@link org.apache.log4j.Category#log(String, Priority, Object, Throwable)}
93      * with {@link org.apache.log4j.Level#ERROR} level, specified message and <code>null</code> throwable.
94      */

95     public void testErrorNull() {
96         log.error(MESSAGE);
97         doTestDelegatedToLog(Level.ERROR, MESSAGE, null);
98     }
99
100     /**
101      * Tests {@link org.apache.commons.logging.Log#error(Object,java.lang.Throwable throwable) method.
102      * Tests that it delegates to
103      * {@link org.apache.log4j.Category#log(String, Priority, Object, Throwable)}
104      * with {@link org.apache.log4j.Level#ERROR} level, specified message and throwable.
105      */

106     public void testErrorThrowable() {
107         log.error(MESSAGE, THROWABLE);
108         doTestDelegatedToLog(Level.ERROR, MESSAGE, THROWABLE);
109     }
110
111     /**
112      * Tests {@link org.apache.commons.logging.Log#isFatalEnabled()} method.
113      * Tests that it delegates to {@link org.apache.log4j.Category#isEnabledFor(Priority)}
114      * with {@link org.apache.log4j.Level#FATAL} as an argument.
115      */

116     public void testIsFatalEnabled() {
117         log.isFatalEnabled();
118         assertTrue("Method delegates to Logger.isEnabledFor",
119                 mockLogger.isEnabledForCalled
120                 & mockLogger.calledWithPriority==Level.FATAL);
121     }
122
123     /**
124      * Tests {@link org.apache.commons.logging.Log#fatal(Object) method.
125      * Tests that it delegates to
126      * {@link org.apache.log4j.Category#log(String, Priority, Object, Throwable)}
127      * with {@link org.apache.log4j.Level#FATAL} level, specified message and <code>null</code> throwable.
128      */

129     public void testFatalNull() {
130         log.fatal(MESSAGE);
131         doTestDelegatedToLog(Level.FATAL, MESSAGE, null);
132     }
133
134     /**
135      * Tests {@link org.apache.commons.logging.Log#fatal(Object,java.lang.Throwable throwable) method.
136      * Tests that it delegates to
137      * {@link org.apache.log4j.Category#log(String, Priority, Object, Throwable)}
138      * with {@link org.apache.log4j.Level#FATAL} level, specified message and throwable.
139      */

140     public void testFatalThrowable() {
141         log.fatal(MESSAGE, THROWABLE);
142         doTestDelegatedToLog(Level.FATAL, MESSAGE, THROWABLE);
143     }
144 }
145
Popular Tags