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