Source Code Cross Referenced for FirstPriorityConfigTestCase.java in  » Library » apache-common-Logging » org » apache » commons » logging » config » 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.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 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.config;
018:
019:        import java.net.URL;
020:
021:        import junit.framework.Test;
022:        import junit.framework.TestCase;
023:
024:        import org.apache.commons.logging.LogFactory;
025:        import org.apache.commons.logging.PathableClassLoader;
026:        import org.apache.commons.logging.PathableTestSuite;
027:
028:        /**
029:         * Tests that verify that the process of configuring logging on startup
030:         * works correctly by selecting the file with the highest priority.
031:         * <p>
032:         * This test sets up a classpath where:
033:         * <ul>
034:         * <li> first file found has priority=20
035:         * <li> second file found has priority=10
036:         * </ul>
037:         * The result should be that the first file is used.
038:         */
039:        public class FirstPriorityConfigTestCase extends TestCase {
040:
041:            // ------------------------------------------- JUnit Infrastructure Methods
042:
043:            /**
044:             * Return the tests included in this test suite.
045:             */
046:            public static Test suite() throws Exception {
047:                Class this Class = FirstPriorityConfigTestCase.class;
048:
049:                // Determine the URL to this .class file, so that we can then
050:                // append the priority dirs to it. For tidiness, load this
051:                // class through a dummy loader though this is not absolutely
052:                // necessary...
053:                PathableClassLoader dummy = new PathableClassLoader(null);
054:                dummy.useSystemLoader("junit.");
055:                dummy.addLogicalLib("testclasses");
056:                dummy.addLogicalLib("commons-logging");
057:
058:                String this ClassPath = this Class.getName().replace('.', '/')
059:                        + ".class";
060:                URL baseUrl = dummy.findResource(this ClassPath);
061:
062:                // Now set up the desired classloader hierarchy. We'll put a config
063:                // file of priority=10 in the container path, and ones of both
064:                // "no priority" and priority=20 in the webapp path.
065:                //
066:                // A second properties file with priority=20 is also added,
067:                // so we can check that the first one in the classpath is
068:                // used.
069:                PathableClassLoader containerLoader = new PathableClassLoader(
070:                        null);
071:                containerLoader.useSystemLoader("junit.");
072:                containerLoader.addLogicalLib("commons-logging");
073:
074:                PathableClassLoader webappLoader = new PathableClassLoader(
075:                        containerLoader);
076:                webappLoader.addLogicalLib("testclasses");
077:
078:                URL pri20URL = new URL(baseUrl, "priority20/");
079:                webappLoader.addURL(pri20URL);
080:
081:                URL pri10URL = new URL(baseUrl, "priority10/");
082:                webappLoader.addURL(pri10URL);
083:
084:                // load the test class via webapp loader, and use the webapp loader
085:                // as the tccl loader too.
086:                Class testClass = webappLoader.loadClass(this Class.getName());
087:                return new PathableTestSuite(testClass, webappLoader);
088:            }
089:
090:            /**
091:             * Set up instance variables required by this test case.
092:             */
093:            public void setUp() throws Exception {
094:                LogFactory.releaseAll();
095:            }
096:
097:            /**
098:             * Tear down instance variables required by this test case.
099:             */
100:            public void tearDown() {
101:                LogFactory.releaseAll();
102:            }
103:
104:            // ----------------------------------------------------------- Test Methods
105:
106:            /**
107:             * Verify that the config file being used is the one containing
108:             * the desired configId value.
109:             */
110:            public void testPriority() throws Exception {
111:                LogFactory instance = LogFactory.getFactory();
112:                String id = (String) instance.getAttribute("configId");
113:                assertEquals("Correct config file loaded", "priority20", id);
114:            }
115:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.