1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.logging.jdk14;
18
19
20 import java.io.ByteArrayInputStream;
21 import java.io.ByteArrayOutputStream;
22 import java.io.ObjectInputStream;
23 import java.io.ObjectOutputStream;
24
25 import junit.framework.Test;
26 import junit.framework.TestCase;
27 import junit.framework.TestSuite;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32
33 /***
34 * <p>TestCase for JDK 1.4 logging when running on a JDK 1.4 system with
35 * zero configuration, and with Log4J not present (so JDK 1.4 logging
36 * should be automatically configured.</p>
37 *
38 * @author Craig R. McClanahan
39 * @version $Revision: 202471 $ $Date: 2005-06-30 04:21:03 +0100 (Thu, 30 Jun 2005) $
40 */
41
42 public class DefaultConfigTestCase extends TestCase {
43
44
45
46
47
48 /***
49 * <p>Construct a new instance of this test case.</p>
50 *
51 * @param name Name of the test case
52 */
53 public DefaultConfigTestCase(String name) {
54 super(name);
55 }
56
57
58
59
60
61 /***
62 * <p>The {@link LogFactory} implementation we have selected.</p>
63 */
64 protected LogFactory factory = null;
65
66
67 /***
68 * <p>The {@link Log} implementation we have selected.</p>
69 */
70 protected Log log = null;
71
72
73
74
75
76 /***
77 * Set up instance variables required by this test case.
78 */
79 public void setUp() throws Exception {
80 setUpFactory();
81 setUpLog("TestLogger");
82 }
83
84
85 /***
86 * Return the tests included in this test suite.
87 */
88 public static Test suite() throws Exception {
89 return (new TestSuite(DefaultConfigTestCase.class));
90 }
91
92 /***
93 * Tear down instance variables required by this test case.
94 */
95 public void tearDown() {
96 log = null;
97 factory = null;
98 LogFactory.releaseAll();
99 }
100
101
102
103
104
105
106 public void testPristineLog() {
107
108 checkLog();
109
110 }
111
112
113
114 public void testPristineFactory() {
115
116 assertNotNull("LogFactory exists", factory);
117 assertEquals("LogFactory class",
118 "org.apache.commons.logging.impl.LogFactoryImpl",
119 factory.getClass().getName());
120
121 String names[] = factory.getAttributeNames();
122 assertNotNull("Names exists", names);
123 assertEquals("Names empty", 0, names.length);
124
125 }
126
127
128
129 public void testSerializable() throws Exception {
130
131
132 ByteArrayOutputStream baos = new ByteArrayOutputStream();
133 ObjectOutputStream oos = new ObjectOutputStream(baos);
134 oos.writeObject(log);
135 oos.close();
136 ByteArrayInputStream bais =
137 new ByteArrayInputStream(baos.toByteArray());
138 ObjectInputStream ois = new ObjectInputStream(bais);
139 log = (Log) ois.readObject();
140 ois.close();
141
142
143 checkLog();
144
145 }
146
147
148
149
150
151
152
153 protected void checkLog() {
154
155 assertNotNull("Log exists", log);
156 assertEquals("Log class",
157 "org.apache.commons.logging.impl.Jdk14Logger",
158 log.getClass().getName());
159
160
161 log.isDebugEnabled();
162 log.isErrorEnabled();
163 log.isFatalEnabled();
164 log.isInfoEnabled();
165 log.isTraceEnabled();
166 log.isWarnEnabled();
167
168 }
169
170
171
172 protected void setUpFactory() throws Exception {
173 factory = LogFactory.getFactory();
174 }
175
176
177
178 protected void setUpLog(String name) throws Exception {
179 log = LogFactory.getLog(name);
180 }
181
182
183 }