1 16 17 package org.apache.commons.logging.log4j; 18 19 20 import java.io.ByteArrayInputStream ; 21 import java.io.ByteArrayOutputStream ; 22 import java.io.ObjectInputStream ; 23 import java.io.ObjectOutputStream ; 24 25 import junit.framework.Test; 26 import junit.framework.TestCase; 27 import junit.framework.TestSuite; 28 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 33 41 42 public class DefaultConfigTestCase extends TestCase { 43 44 45 47 48 53 public DefaultConfigTestCase(String name) { 54 super(name); 55 } 56 57 58 60 61 64 protected LogFactory factory = null; 65 66 67 70 protected Log log = null; 71 72 73 75 76 79 public void setUp() throws Exception { 80 setUpFactory(); 81 setUpLog("TestLogger"); 82 } 83 84 85 88 public static Test suite() { 89 return (new TestSuite(DefaultConfigTestCase.class)); 90 } 91 92 95 public void tearDown() { 96 log = null; 97 factory = null; 98 LogFactory.releaseAll(); 99 } 100 101 102 104 105 public void testPristineLog() { 107 108 checkLog(); 109 110 } 111 112 113 public void testPristineFactory() { 115 116 assertNotNull("LogFactory exists", factory); 117 assertEquals("LogFactory class", 118 "org.apache.commons.logging.impl.LogFactoryImpl", 119 factory.getClass().getName()); 120 121 String names[] = factory.getAttributeNames(); 122 assertNotNull("Names exists", names); 123 assertEquals("Names empty", 0, names.length); 124 125 } 126 127 128 public void testSerializable() throws Exception { 130 131 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 133 ObjectOutputStream oos = new ObjectOutputStream (baos); 134 oos.writeObject(log); 135 oos.close(); 136 ByteArrayInputStream bais = 137 new ByteArrayInputStream (baos.toByteArray()); 138 ObjectInputStream ois = new ObjectInputStream (bais); 139 log = (Log) ois.readObject(); 140 ois.close(); 141 142 checkLog(); 144 145 } 146 147 148 150 151 152 protected void checkLog() { 154 155 assertNotNull("Log exists", log); 156 assertEquals("Log class", 157 "org.apache.commons.logging.impl.Log4JLogger", 158 log.getClass().getName()); 159 160 log.isDebugEnabled(); 162 log.isErrorEnabled(); 163 log.isFatalEnabled(); 164 log.isInfoEnabled(); 165 log.isTraceEnabled(); 166 log.isWarnEnabled(); 167 168 } 169 170 171 protected void setUpFactory() throws Exception { 173 factory = LogFactory.getFactory(); 174 } 175 176 177 protected void setUpLog(String name) throws Exception { 179 log = LogFactory.getLog(name); 180 } 181 182 183 } 184 | Popular Tags |