01: /*
02: * Copyright 2001-2006 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.commons.logging.noop;
18:
19: import java.io.ByteArrayInputStream;
20: import java.io.ByteArrayOutputStream;
21: import java.io.ObjectInputStream;
22: import java.io.ObjectOutputStream;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.apache.commons.logging.impl.NoOpLog;
27: import org.apache.commons.logging.AbstractLogTest;
28:
29: /**
30: * Tests for NoOpLog logging adapter.
31: * <p>
32: * This simply applies the tests defined in AbstractLogTest to this class.
33: */
34: public class NoOpLogTestCase extends AbstractLogTest {
35: /**
36: * Set up instance variables required by this test case.
37: */
38: public void setUp() throws Exception {
39: LogFactory.releaseAll();
40:
41: System.setProperty("org.apache.commons.logging.Log",
42: "org.apache.commons.logging.impl.NoOpLog");
43: }
44:
45: /**
46: * Tear down instance variables required by this test case.
47: */
48: public void tearDown() {
49: LogFactory.releaseAll();
50: }
51:
52: /**
53: * Override the abstract method from the parent class so that the
54: * inherited tests can access the right Log object type.
55: */
56: public Log getLogObject() {
57: return (Log) new NoOpLog(this .getClass().getName());
58: }
59:
60: // Test Serializability of standard instance
61: public void testSerializable() throws Exception {
62: Log log = LogFactory.getLog(this .getClass().getName());
63: checkLog(log);
64:
65: // Serialize and deserialize the instance
66: ByteArrayOutputStream baos = new ByteArrayOutputStream();
67: ObjectOutputStream oos = new ObjectOutputStream(baos);
68: oos.writeObject(log);
69: oos.close();
70: ByteArrayInputStream bais = new ByteArrayInputStream(baos
71: .toByteArray());
72: ObjectInputStream ois = new ObjectInputStream(bais);
73: log = (Log) ois.readObject();
74: ois.close();
75:
76: checkLog(log);
77: }
78:
79: // -------------------------------------------------------- Support Methods
80:
81: private void checkLog(Log log) {
82:
83: assertNotNull("Log exists", log);
84: assertEquals("Log class",
85: "org.apache.commons.logging.impl.NoOpLog", log
86: .getClass().getName());
87:
88: // Can we call level checkers with no exceptions?
89: // Note that *everything* is permanently disabled for NoOpLog
90: assertFalse(log.isTraceEnabled());
91: assertFalse(log.isDebugEnabled());
92: assertFalse(log.isInfoEnabled());
93: assertFalse(log.isWarnEnabled());
94: assertFalse(log.isErrorEnabled());
95: assertFalse(log.isFatalEnabled());
96: }
97: }
|