1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.logging.jdk14;
19
20
21 import java.io.ByteArrayInputStream;
22 import java.io.ByteArrayOutputStream;
23 import java.io.ObjectInputStream;
24 import java.io.ObjectOutputStream;
25
26 import junit.framework.Test;
27 import junit.framework.TestCase;
28 import junit.framework.TestSuite;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.apache.commons.logging.PathableClassLoader;
33 import org.apache.commons.logging.PathableTestSuite;
34
35
36
37
38
39
40
41
42
43
44
45 public class DefaultConfigTestCase extends TestCase {
46
47
48
49
50
51
52
53
54
55
56 public DefaultConfigTestCase(String name) {
57 super(name);
58 }
59
60
61
62
63
64
65
66
67 protected LogFactory factory = null;
68
69
70
71
72
73 protected Log log = null;
74
75
76
77
78
79
80
81
82 public void setUp() throws Exception {
83 setUpFactory();
84 setUpLog("TestLogger");
85 }
86
87
88
89
90
91 public static Test suite() throws Exception {
92 PathableClassLoader loader = new PathableClassLoader(null);
93 loader.useExplicitLoader("junit.", Test.class.getClassLoader());
94 loader.addLogicalLib("testclasses");
95 loader.addLogicalLib("commons-logging");
96
97 Class testClass = loader.loadClass(DefaultConfigTestCase.class.getName());
98 return new PathableTestSuite(testClass, loader);
99 }
100
101
102
103
104 public void tearDown() {
105 log = null;
106 factory = null;
107 LogFactory.releaseAll();
108 }
109
110
111
112
113
114
115 public void testPristineLog() {
116
117 checkLog();
118
119 }
120
121
122
123 public void testPristineFactory() {
124
125 assertNotNull("LogFactory exists", factory);
126 assertEquals("LogFactory class",
127 "org.apache.commons.logging.impl.LogFactoryImpl",
128 factory.getClass().getName());
129
130 String names[] = factory.getAttributeNames();
131 assertNotNull("Names exists", names);
132 assertEquals("Names empty", 0, names.length);
133
134 }
135
136
137
138 public void testSerializable() throws Exception {
139
140
141 ByteArrayOutputStream baos = new ByteArrayOutputStream();
142 ObjectOutputStream oos = new ObjectOutputStream(baos);
143 oos.writeObject(log);
144 oos.close();
145 ByteArrayInputStream bais =
146 new ByteArrayInputStream(baos.toByteArray());
147 ObjectInputStream ois = new ObjectInputStream(bais);
148 log = (Log) ois.readObject();
149 ois.close();
150
151
152 checkLog();
153
154 }
155
156
157
158
159
160
161
162 protected void checkLog() {
163
164 assertNotNull("Log exists", log);
165 assertEquals("Log class",
166 "org.apache.commons.logging.impl.Jdk14Logger",
167 log.getClass().getName());
168
169
170 log.isDebugEnabled();
171 log.isErrorEnabled();
172 log.isFatalEnabled();
173 log.isInfoEnabled();
174 log.isTraceEnabled();
175 log.isWarnEnabled();
176
177 }
178
179
180
181 protected void setUpFactory() throws Exception {
182 factory = LogFactory.getFactory();
183 }
184
185
186
187 protected void setUpLog(String name) throws Exception {
188 log = LogFactory.getLog(name);
189 }
190
191
192 }