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