1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.apache.commons.logging.impl;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.ByteArrayOutputStream;
29 import java.io.IOException;
30 import java.io.ObjectInputStream;
31 import java.io.ObjectOutputStream;
32
33 import junit.framework.TestCase;
34
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37 import org.slf4j.impl.JDK14LoggerFactory;
38 import org.slf4j.spi.LocationAwareLogger;
39
40 public class SerializationTest extends TestCase {
41
42 ObjectInputStream ois;
43 ByteArrayOutputStream baos = new ByteArrayOutputStream();
44 ObjectOutputStream oos;
45
46 public SerializationTest(String name) {
47 super(name);
48 }
49
50 protected void setUp() throws Exception {
51 oos = new ObjectOutputStream(baos);
52 super.setUp();
53 }
54
55 protected void tearDown() throws Exception {
56 super.tearDown();
57 oos.close();
58 }
59
60 public void verify() throws IOException, ClassNotFoundException {
61 ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
62 ois = new ObjectInputStream(bis);
63
64 Log resuscitatedLog = (Log) ois.readObject();
65
66 resuscitatedLog.debug("");
67 resuscitatedLog.isDebugEnabled();
68 }
69
70 public void testSLF4JLog() throws Exception {
71 JDK14LoggerFactory factory = new JDK14LoggerFactory();
72 SLF4JLog log = new SLF4JLog(factory.getLogger("x"));
73 oos.writeObject(log);
74 verify();
75 }
76
77 public void testSmoke() throws Exception {
78 Log log = LogFactory.getLog("testing");
79 oos.writeObject(log);
80 verify();
81 }
82
83 public void testLocationAware() throws Exception {
84 JDK14LoggerFactory factory = new JDK14LoggerFactory();
85 SLF4JLocationAwareLog log = new SLF4JLocationAwareLog(
86 (LocationAwareLogger) factory.getLogger("x"));
87 oos.writeObject(log);
88 verify();
89 }
90 }