Source Code Cross Referenced for DefaultConfigTestCase.java in  » Library » apache-common-Logging » org » apache » commons » logging » simple » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » apache common Logging » org.apache.commons.logging.simple 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2004 The Apache Software Foundation.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.apache.commons.logging.simple;
018:
019:        import java.io.ByteArrayInputStream;
020:        import java.io.ByteArrayOutputStream;
021:        import java.io.ObjectInputStream;
022:        import java.io.ObjectOutputStream;
023:
024:        import junit.framework.Test;
025:        import junit.framework.TestCase;
026:
027:        import org.apache.commons.logging.Log;
028:        import org.apache.commons.logging.LogFactory;
029:        import org.apache.commons.logging.PathableClassLoader;
030:        import org.apache.commons.logging.PathableTestSuite;
031:        import org.apache.commons.logging.impl.SimpleLog;
032:
033:        /**
034:         * <p>TestCase for simple logging when running with zero configuration
035:         * other than selecting the SimpleLog implementation.</p>
036:         *
037:         * @author Craig R. McClanahan
038:         * @version $Revision: 370012 $ $Date: 2006-01-18 02:34:05 +0000 (Wed, 18 Jan 2006) $
039:         */
040:
041:        public class DefaultConfigTestCase extends TestCase {
042:
043:            // ----------------------------------------------------- Instance Variables
044:
045:            /**
046:             * <p>The {@link LogFactory} implementation we have selected.</p>
047:             */
048:            protected LogFactory factory = null;
049:
050:            /**
051:             * <p>The {@link Log} implementation we have selected.</p>
052:             */
053:            protected Log log = null;
054:
055:            // ------------------------------------------- JUnit Infrastructure Methods
056:
057:            /**
058:             * Return the tests included in this test suite.
059:             * <p>
060:             * We need to use a PathableClassLoader here because the SimpleLog class
061:             * is a pile of junk and chock-full of static variables. Any other test
062:             * (like simple.CustomConfigTestCase) that has used the SimpleLog class
063:             * will already have caused it to do once-only initialisation that we
064:             * can't reset, even by calling LogFactory.releaseAll, because of those
065:             * ugly statics. The only clean solution is to load a clean copy of
066:             * commons-logging including SimpleLog via a nice clean classloader.
067:             * Or we could fix SimpleLog to be sane...
068:             */
069:            public static Test suite() throws Exception {
070:                Class this Class = DefaultConfigTestCase.class;
071:
072:                PathableClassLoader loader = new PathableClassLoader(null);
073:                loader.useSystemLoader("junit.");
074:                loader.addLogicalLib("testclasses");
075:                loader.addLogicalLib("commons-logging");
076:
077:                Class testClass = loader.loadClass(this Class.getName());
078:                return new PathableTestSuite(testClass, loader);
079:            }
080:
081:            /**
082:             * Set system properties that will control the LogFactory/Log objects
083:             * when they are created. Subclasses can override this method to
084:             * define properties that suit them.
085:             */
086:            public void setProperties() {
087:                System.setProperty("org.apache.commons.logging.Log",
088:                        "org.apache.commons.logging.impl.SimpleLog");
089:            }
090:
091:            /**
092:             * Set up instance variables required by this test case.
093:             */
094:            public void setUp() throws Exception {
095:                LogFactory.releaseAll();
096:                setProperties();
097:                setUpFactory();
098:                setUpLog("TestLogger");
099:            }
100:
101:            /**
102:             * Tear down instance variables required by this test case.
103:             */
104:            public void tearDown() {
105:                log = null;
106:                factory = null;
107:                LogFactory.releaseAll();
108:            }
109:
110:            // ----------------------------------------------------------- Test Methods
111:
112:            // Test pristine DecoratedSimpleLog instance
113:            public void testPristineDecorated() {
114:
115:                setUpDecorated("DecoratedLogger");
116:                checkDecorated();
117:
118:            }
119:
120:            // Test pristine Log instance
121:            public void testPristineLog() {
122:
123:                checkStandard();
124:
125:            }
126:
127:            // Test pristine LogFactory instance
128:            public void testPristineFactory() {
129:
130:                assertNotNull("LogFactory exists", factory);
131:                assertEquals("LogFactory class",
132:                        "org.apache.commons.logging.impl.LogFactoryImpl",
133:                        factory.getClass().getName());
134:
135:                String names[] = factory.getAttributeNames();
136:                assertNotNull("Names exists", names);
137:                assertEquals("Names empty", 0, names.length);
138:
139:            }
140:
141:            // Test Serializability of standard instance
142:            public void testSerializable() throws Exception {
143:
144:                // Serialize and deserialize the instance
145:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
146:                ObjectOutputStream oos = new ObjectOutputStream(baos);
147:                oos.writeObject(log);
148:                oos.close();
149:                ByteArrayInputStream bais = new ByteArrayInputStream(baos
150:                        .toByteArray());
151:                ObjectInputStream ois = new ObjectInputStream(bais);
152:                log = (Log) ois.readObject();
153:                ois.close();
154:
155:                // Check the characteristics of the resulting object
156:                checkStandard();
157:
158:            }
159:
160:            // -------------------------------------------------------- Support Methods
161:
162:            // Check the decorated log instance
163:            protected void checkDecorated() {
164:
165:                assertNotNull("Log exists", log);
166:                assertEquals("Log class",
167:                        "org.apache.commons.logging.simple.DecoratedSimpleLog",
168:                        log.getClass().getName());
169:
170:                // Can we call level checkers with no exceptions?
171:                assertTrue(!log.isDebugEnabled());
172:                assertTrue(log.isErrorEnabled());
173:                assertTrue(log.isFatalEnabled());
174:                assertTrue(log.isInfoEnabled());
175:                assertTrue(!log.isTraceEnabled());
176:                assertTrue(log.isWarnEnabled());
177:
178:                // Can we retrieve the current log level?
179:                assertEquals(SimpleLog.LOG_LEVEL_INFO, ((SimpleLog) log)
180:                        .getLevel());
181:
182:                // Can we validate the extra exposed properties?
183:                assertEquals("yyyy/MM/dd HH:mm:ss:SSS zzz",
184:                        ((DecoratedSimpleLog) log).getDateTimeFormat());
185:                assertEquals("DecoratedLogger", ((DecoratedSimpleLog) log)
186:                        .getLogName());
187:                assertTrue(!((DecoratedSimpleLog) log).getShowDateTime());
188:                assertTrue(((DecoratedSimpleLog) log).getShowShortName());
189:
190:            }
191:
192:            // Check the standard log instance
193:            protected void checkStandard() {
194:
195:                assertNotNull("Log exists", log);
196:                assertEquals("Log class",
197:                        "org.apache.commons.logging.impl.SimpleLog", log
198:                                .getClass().getName());
199:
200:                // Can we call level checkers with no exceptions?
201:                assertTrue(!log.isDebugEnabled());
202:                assertTrue(log.isErrorEnabled());
203:                assertTrue(log.isFatalEnabled());
204:                assertTrue(log.isInfoEnabled());
205:                assertTrue(!log.isTraceEnabled());
206:                assertTrue(log.isWarnEnabled());
207:
208:                // Can we retrieve the current log level?
209:                assertEquals(SimpleLog.LOG_LEVEL_INFO, ((SimpleLog) log)
210:                        .getLevel());
211:
212:            }
213:
214:            // Set up decorated log instance
215:            protected void setUpDecorated(String name) {
216:                log = new DecoratedSimpleLog(name);
217:            }
218:
219:            // Set up factory instance
220:            protected void setUpFactory() throws Exception {
221:                factory = LogFactory.getFactory();
222:            }
223:
224:            // Set up log instance
225:            protected void setUpLog(String name) throws Exception {
226:                log = LogFactory.getLog(name);
227:            }
228:
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.