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


001:        /*
002:         * Copyright 2005 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:        package org.apache.commons.logging.pathable;
017:
018:        import java.net.URL;
019:        import java.net.URLClassLoader;
020:
021:        import junit.framework.Test;
022:        import junit.framework.TestCase;
023:
024:        import org.apache.commons.logging.PathableClassLoader;
025:        import org.apache.commons.logging.PathableTestSuite;
026:
027:        /**
028:         * Tests for the PathableTestSuite class.
029:         */
030:
031:        public class GeneralTestCase extends TestCase {
032:
033:            /**
034:             * Set up a custom classloader hierarchy for this test case.
035:             */
036:            public static Test suite() throws Exception {
037:                Class this Class = GeneralTestCase.class;
038:                ClassLoader this ClassLoader = this Class.getClassLoader();
039:
040:                PathableClassLoader loader = new PathableClassLoader(null);
041:                loader.useExplicitLoader("junit.", this ClassLoader);
042:                loader.addLogicalLib("testclasses");
043:
044:                // reload this class via the child classloader
045:                Class testClass = loader.loadClass(this Class.getName());
046:
047:                // and return our custom TestSuite class
048:                return new PathableTestSuite(testClass, loader);
049:            }
050:
051:            /**
052:             * Verify that a certain system property is not set, then set it.
053:             */
054:            private static void checkAndSetProperties() {
055:                String prop = System.getProperty("no.such.property");
056:                assertNull("no.such.property is unexpectedly defined", prop);
057:                System.setProperty("no.such.property", "dummy value");
058:                prop = System.getProperty("no.such.property");
059:                assertNotNull("no.such.property is unexpectedly undefined",
060:                        prop);
061:            }
062:
063:            /**
064:             * Verify that when a test method modifies the system properties they are
065:             * reset before the next test is run.
066:             * <p>
067:             * This method works in conjunction with testResetProps2. There is no
068:             * way of knowing which test method junit will run first, but it doesn't
069:             * matter; whichever one of them runs first will modify the system properties.
070:             * If the PathableTestSuite isn't resetting the system properties then whichever
071:             * of them runs second will fail. Of course if other methods are run in-between
072:             * then those methods might also fail...
073:             */
074:            public void testResetProps1() {
075:                checkAndSetProperties();
076:            }
077:
078:            /**
079:             * See testResetProps1.
080:             */
081:            public void testResetProps2() {
082:                checkAndSetProperties();
083:            }
084:
085:            /**
086:             * Verify that the context classloader is a custom one, then reset it to
087:             * a non-custom one.
088:             */
089:            private static void checkAndSetContext() {
090:                ClassLoader contextLoader = Thread.currentThread()
091:                        .getContextClassLoader();
092:                assertEquals("ContextLoader is of unexpected type",
093:                        contextLoader.getClass().getName(),
094:                        PathableClassLoader.class.getName());
095:
096:                URL[] noUrls = new URL[0];
097:                Thread.currentThread().setContextClassLoader(
098:                        new URLClassLoader(noUrls));
099:            }
100:
101:            /**
102:             * Verify that when a test method modifies the context classloader it is
103:             * reset before the next test is run.
104:             * <p>
105:             * This method works in conjunction with testResetContext2. There is no
106:             * way of knowing which test method junit will run first, but it doesn't
107:             * matter; whichever one of them runs first will modify the contextClassloader.
108:             * If the PathableTestSuite isn't resetting the contextClassLoader then whichever
109:             * of them runs second will fail. Of course if other methods are run in-between
110:             * then those methods might also fail...
111:             */
112:            public void testResetContext1() {
113:                checkAndSetContext();
114:            }
115:
116:            /**
117:             * See testResetContext1.
118:             */
119:            public void testResetContext2() {
120:                checkAndSetContext();
121:            }
122:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.