1 16 17 package org.apache.commons.logging.logkit; 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 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.commons.logging.PathableClassLoader; 31 import org.apache.commons.logging.PathableTestSuite; 32 import org.apache.commons.logging.impl.LogKitLogger; 33 import org.apache.commons.logging.impl.NoOpLog; 34 35 import org.apache.commons.logging.AbstractLogTest; 36 37 40 41 public class StandardTestCase extends AbstractLogTest { 42 43 44 46 47 50 protected LogFactory factory = null; 51 52 53 56 protected Log log = null; 57 58 59 61 62 65 public static Test suite() throws Exception { 66 Class thisClass = StandardTestCase.class; 67 68 PathableClassLoader loader = new PathableClassLoader(null); 69 loader.useSystemLoader("junit."); 70 loader.addLogicalLib("testclasses"); 71 loader.addLogicalLib("commons-logging"); 72 loader.addLogicalLib("logkit"); 73 74 Class testClass = loader.loadClass(thisClass.getName()); 75 return new PathableTestSuite(testClass, loader); 76 } 77 78 81 public void setUp() throws Exception { 82 LogFactory.releaseAll(); 83 84 System.setProperty( 85 "org.apache.commons.logging.Log", 86 "org.apache.commons.logging.impl.LogKitLogger"); 87 88 factory = LogFactory.getFactory(); 89 log = LogFactory.getLog("TestLogger"); 90 } 91 92 95 public void tearDown() { 96 log = null; 97 factory = null; 98 LogFactory.releaseAll(); 99 } 100 101 103 107 public Log getLogObject() 108 { 109 return new LogKitLogger(this.getClass().getName()); 110 } 111 112 public void testPristineFactory() { 114 115 assertNotNull("LogFactory exists", factory); 116 assertEquals("LogFactory class", 117 "org.apache.commons.logging.impl.LogFactoryImpl", 118 factory.getClass().getName()); 119 120 String names[] = factory.getAttributeNames(); 121 assertNotNull("Names exists", names); 122 assertEquals("Names empty", 0, names.length); 123 } 124 125 public void testPristineLog() { 127 checkStandard(); 128 } 129 130 public void testSerializable() throws Exception { 132 checkStandard(); 133 134 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 136 ObjectOutputStream oos = new ObjectOutputStream (baos); 137 oos.writeObject(log); 138 oos.close(); 139 ByteArrayInputStream bais = 140 new ByteArrayInputStream (baos.toByteArray()); 141 ObjectInputStream ois = new ObjectInputStream (bais); 142 log = (Log) ois.readObject(); 143 ois.close(); 144 145 checkStandard(); 146 } 147 148 149 151 protected void checkStandard() { 153 154 assertNotNull("Log exists", log); 155 assertEquals("Log class", 156 "org.apache.commons.logging.impl.LogKitLogger", 157 log.getClass().getName()); 158 159 assertTrue(log.isTraceEnabled()); 162 assertTrue(log.isDebugEnabled()); 163 assertTrue(log.isInfoEnabled()); 164 assertTrue(log.isWarnEnabled()); 165 assertTrue(log.isErrorEnabled()); 166 assertTrue(log.isFatalEnabled()); 167 } 168 } 169 | Popular Tags |