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 org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35 import org.junit.After;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.slf4j.impl.JDK14LoggerFactory;
39 import org.slf4j.spi.LocationAwareLogger;
40
41 public class SerializationTest {
42
43 ObjectInputStream ois;
44 ByteArrayOutputStream baos = new ByteArrayOutputStream();
45 ObjectOutputStream oos;
46
47 @Before
48 public void setUp() throws Exception {
49 oos = new ObjectOutputStream(baos);
50 }
51
52 @After
53 public void tearDown() throws Exception {
54 oos.close();
55 }
56
57 public void verify() throws IOException, ClassNotFoundException {
58 ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
59 ois = new ObjectInputStream(bis);
60
61 Log resuscitatedLog = (Log) ois.readObject();
62
63 resuscitatedLog.debug("");
64 resuscitatedLog.isDebugEnabled();
65 }
66
67 @Test
68 public void testSLF4JLog() throws Exception {
69 JDK14LoggerFactory factory = new JDK14LoggerFactory();
70 SLF4JLog log = new SLF4JLog(factory.getLogger("x"));
71 oos.writeObject(log);
72 verify();
73 }
74
75 @Test
76 public void testSmoke() throws Exception {
77 Log log = LogFactory.getLog("testing");
78 oos.writeObject(log);
79 verify();
80 }
81
82 @Test
83 public void testLocationAware() throws Exception {
84 JDK14LoggerFactory factory = new JDK14LoggerFactory();
85 SLF4JLocationAwareLog log = new SLF4JLocationAwareLog((LocationAwareLogger) factory.getLogger("x"));
86 oos.writeObject(log);
87 verify();
88 }
89 }