KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > logging > BasicOperationsTest


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

16  
17 package org.apache.commons.logging;
18
19 import junit.framework.TestCase;
20
21 /**
22  * Tests the basic logging operations to ensure that they all function
23  * without exception failure. In other words, that they do no fail by
24  * throwing exceptions.
25  * This is the minimum requirement for any well behaved logger
26  * and so this test should be run for each kind.
27  */

28 public class BasicOperationsTest extends TestCase
29 {
30     public BasicOperationsTest(String JavaDoc testName)
31     {
32         super(testName);
33     }
34     
35     public void testIsEnabledClassLog()
36     {
37         Log log = LogFactory.getLog(BasicOperationsTest.class);
38         executeIsEnabledTest(log);
39     }
40     
41     public void testIsEnabledNamedLog()
42     {
43         Log log = LogFactory.getLog(BasicOperationsTest.class.getName());
44         executeIsEnabledTest(log);
45     }
46     
47     public void executeIsEnabledTest(Log log)
48     {
49         try
50         {
51             log.isTraceEnabled();
52             log.isDebugEnabled();
53             log.isInfoEnabled();
54             log.isWarnEnabled();
55             log.isErrorEnabled();
56             log.isFatalEnabled();
57         }
58         catch (Throwable JavaDoc t)
59         {
60             t.printStackTrace();
61             fail("Exception thrown: " + t);
62         }
63     }
64     
65     
66     public void testMessageWithoutExceptionClassLog()
67     {
68         Log log = LogFactory.getLog(BasicOperationsTest.class);
69         executeMessageWithoutExceptionTest(log);
70     }
71     
72     public void testMessageWithoutExceptionNamedLog()
73     {
74         Log log = LogFactory.getLog(BasicOperationsTest.class.getName());
75         executeMessageWithoutExceptionTest(log);
76     }
77     
78     public void executeMessageWithoutExceptionTest(Log log)
79     {
80         try
81         {
82             log.trace("Hello, Mum");
83             log.debug("Hello, Mum");
84             log.info("Hello, Mum");
85             log.warn("Hello, Mum");
86             log.error("Hello, Mum");
87             log.fatal("Hello, Mum");
88         }
89         catch (Throwable JavaDoc t)
90         {
91             t.printStackTrace();
92             fail("Exception thrown: " + t);
93         }
94     }
95     
96     public void testMessageWithExceptionClassLog()
97     {
98         Log log = LogFactory.getLog(BasicOperationsTest.class);
99         executeMessageWithExceptionTest(log);
100     }
101     
102     public void testMessageWithExceptionNamedLog()
103     {
104         Log log = LogFactory.getLog(BasicOperationsTest.class.getName());
105         executeMessageWithExceptionTest(log);
106     }
107     
108     public void executeMessageWithExceptionTest(Log log)
109     {
110         try
111         {
112             log.trace("Hello, Mum", new ArithmeticException JavaDoc());
113             log.debug("Hello, Mum", new ArithmeticException JavaDoc());
114             log.info("Hello, Mum", new ArithmeticException JavaDoc());
115             log.warn("Hello, Mum", new ArithmeticException JavaDoc());
116             log.error("Hello, Mum", new ArithmeticException JavaDoc());
117             log.fatal("Hello, Mum", new ArithmeticException JavaDoc());
118         }
119         catch (Throwable JavaDoc t)
120         {
121             t.printStackTrace();
122             fail("Exception thrown: " + t);
123         }
124     }
125 }
126
Popular Tags