Source Code Cross Referenced for ClassLoaderTest.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » jetty6 » 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 » EJB Server geronimo » plugins » org.apache.geronimo.jetty6 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.jetty6;
017:
018:        import java.io.File;
019:        import java.net.URL;
020:
021:        import org.apache.geronimo.testsupport.TestSupport;
022:
023:        import org.apache.geronimo.kernel.config.MultiParentClassLoader;
024:        import org.apache.geronimo.kernel.repository.Artifact;
025:
026:        /**
027:         * Tests loading various classes (as classes and URL resources) with different
028:         * settings for contextPriorityClassLoader to make sure the restrictions on
029:         * javax.* class loading are honored.
030:         *
031:         * @version $Rev: 513131 $ $Date: 2007-02-28 20:31:29 -0800 (Wed, 28 Feb 2007) $
032:         */
033:        public class ClassLoaderTest extends TestSupport {
034:            Artifact configId = new Artifact("foo", "bar", "1", "car");
035:            ClassLoader cl;
036:            URL[] urls;
037:            private static final String[] HIDDEN = { "org.apache.geronimo",
038:                    "org.mortbay", "org.xml", "org.w3c" };
039:            private static final String[] NON_OVERRIDABLE = { "java.", "javax." };
040:
041:            public void setUp() throws Exception {
042:                super .setUp();
043:                URL url = new File(BASEDIR,
044:                        "src/test/resources/deployables/cltest/").toURL();
045:                urls = new URL[] { url };
046:            }
047:
048:            //todo: try more restricted prefixed besides javax.*
049:
050:            /**
051:             * Tries to load a javax.* class that's not available from the
052:             * parent ClassLoader.  This should work.
053:             */
054:            public void testFalseNonexistantJavaxClass() {
055:                cl = new MultiParentClassLoader(configId, urls, getClass()
056:                        .getClassLoader(), false, HIDDEN, NON_OVERRIDABLE);
057:                try {
058:                    cl.loadClass("javax.foo.Foo");
059:                } catch (ClassNotFoundException e) {
060:                    fail("Should be able to load a javax.* class that is not defined by my parent CL");
061:                }
062:            }
063:
064:            /**
065:             * Tries to load a javax.* class that's not available from the
066:             * parent ClassLoader.  This should work.
067:             */
068:            public void testTrueNonexistantJavaxClass() {
069:                cl = new MultiParentClassLoader(configId, urls, getClass()
070:                        .getClassLoader(), true, HIDDEN, NON_OVERRIDABLE);
071:                try {
072:                    cl.loadClass("javax.foo.Foo");
073:                } catch (ClassNotFoundException e) {
074:                    fail("Should be able to load a javax.* class that is not defined by my parent CL");
075:                }
076:            }
077:
078:            /**
079:             * Tries to load a javax.* class that is avialable from the parent ClassLoader,
080:             * when there's a different definition available from this ClassLoader too.
081:             * This should always load the parent's copy.
082:             */
083:            public void testFalseExistantJavaxClass() {
084:                cl = new MultiParentClassLoader(configId, urls, getClass()
085:                        .getClassLoader(), false, HIDDEN, NON_OVERRIDABLE);
086:                try {
087:                    Class cls = cl.loadClass("javax.servlet.Servlet");
088:                    assertTrue(
089:                            "Loaded wrong class first; expected to find parent CL's copy of javax.servlet.Servlet",
090:                            cls.getDeclaredMethods().length > 0);
091:                } catch (ClassNotFoundException e) {
092:                    fail("Problem with test; expecting to have javax.servlet.* on the ClassPath");
093:                }
094:            }
095:
096:            /**
097:             * Tries to load a javax.* class that is avialable from the parent ClassLoader,
098:             * when there's a different definition available from this ClassLoader too.
099:             * This should always load the parent's copy.
100:             */
101:            public void testTrueExistantJavaxClass() {
102:                cl = new MultiParentClassLoader(configId, urls, getClass()
103:                        .getClassLoader(), true, HIDDEN, NON_OVERRIDABLE);
104:                try {
105:                    Class cls = cl.loadClass("javax.servlet.Servlet");
106:                    assertTrue(
107:                            "Loaded wrong class first; expected to find parent CL's copy of javax.servlet.Servlet",
108:                            cls.getDeclaredMethods().length > 0);
109:                } catch (ClassNotFoundException e) {
110:                    fail("Problem with test; expecting to have javax.servlet.* on the ClassPath");
111:                }
112:            }
113:
114:            /**
115:             * Tries to load a non-javax.* class that is aailable form the parent
116:             * ClassLoader, when there's a different definition available from this
117:             * ClassLoader.  This should load the parent's copy when
118:             * contextPriorityClassLoader is set to false (as here) and the child's
119:             * copy when the contextPriorityClassLoader is set to true.
120:             */
121:            public void xtestFalseExistantNonJavaxClass() {
122:                cl = new MultiParentClassLoader(configId, urls, getClass()
123:                        .getClassLoader(), false, HIDDEN, NON_OVERRIDABLE);
124:                try {
125:                    Class cls = cl.loadClass("mx4j.MBeanDescription");
126:                    assertTrue(
127:                            "Should not have overriden parent CL definition of class mx4j.MBeanDescription",
128:                            cls.getDeclaredMethods().length > 0);
129:                } catch (ClassNotFoundException e) {
130:                    fail("Problem with test; expecting to have mx4j.* on the ClassPath");
131:                }
132:            }
133:
134:            /**
135:             * Tries to load a non-javax.* class that is aailable form the parent
136:             * ClassLoader, when there's a different definition available from this
137:             * ClassLoader.  This should load the parent's copy when
138:             * contextPriorityClassLoader is set to false and the child's copy when
139:             * the contextPriorityClassLoader is set to true (as here).
140:             */
141:            public void xtestTrueExistantNonJavaxClass() {
142:                cl = new MultiParentClassLoader(configId, urls, getClass()
143:                        .getClassLoader(), true, HIDDEN, NON_OVERRIDABLE);
144:                try {
145:                    Class cls = cl.loadClass("mx4j.MBeanDescription");
146:                    assertTrue(
147:                            "Should be able to override a class that is not in java.*, javax.*, etc.",
148:                            cls.getDeclaredMethods().length == 0);
149:                } catch (ClassNotFoundException e) {
150:                    fail("Problem with test; expecting to have mx4j.* on the ClassPath");
151:                }
152:            }
153:
154:            /**
155:             * Tries to load a javax.* class that's not available from the
156:             * parent ClassLoader.  This should work.
157:             */
158:            public void testFalseNonexistantJavaxResource() {
159:                cl = new MultiParentClassLoader(configId, urls, getClass()
160:                        .getClassLoader(), false, HIDDEN, NON_OVERRIDABLE);
161:                URL url = cl.getResource("javax/foo/Foo.class");
162:                if (url == null) {
163:                    fail("Should be able to load a javax.* class that is not defined by my parent CL");
164:                }
165:                assertEquals(url.getProtocol(), "file");
166:            }
167:
168:            /**
169:             * Tries to load a javax.* class that's not available from the
170:             * parent ClassLoader.  This should work.
171:             */
172:            public void testTrueNonexistantJavaxResource() {
173:                cl = new MultiParentClassLoader(configId, urls, getClass()
174:                        .getClassLoader(), true, HIDDEN, NON_OVERRIDABLE);
175:                URL url = cl.getResource("javax/foo/Foo.class");
176:                if (url == null) {
177:                    fail("Should be able to load a javax.* class that is not defined by my parent CL");
178:                }
179:                assertEquals(url.getProtocol(), "file");
180:            }
181:
182:            /**
183:             * Tries to load a javax.* class that is avialable from the parent ClassLoader,
184:             * when there's a different definition available from this ClassLoader too.
185:             * This should always load the parent's copy.
186:             */
187:            public void testFalseExistantJavaxResource() {
188:                cl = new MultiParentClassLoader(configId, urls, getClass()
189:                        .getClassLoader(), false, HIDDEN, NON_OVERRIDABLE);
190:                URL url = cl.getResource("javax/servlet/Servlet.class");
191:                if (url == null) {
192:                    fail("Problem with test; expecting to have javax.servlet.* on the ClassPath");
193:                }
194:                assertEquals(
195:                        "Loaded wrong class first; expected to find parent CL's copy of javax.servlet.Servlet",
196:                        url.getProtocol(), "jar");
197:            }
198:
199:            /**
200:             * Tries to load a javax.* class that is avialable from the parent ClassLoader,
201:             * when there's a different definition available from this ClassLoader too.
202:             * This should always load the parent's copy.
203:             */
204:            public void testTrueExistantJavaxResource() {
205:                cl = new MultiParentClassLoader(configId, urls, getClass()
206:                        .getClassLoader(), true, HIDDEN, NON_OVERRIDABLE);
207:                URL url = cl.getResource("javax/servlet/Servlet.class");
208:                if (url == null) {
209:                    fail("Problem with test; expecting to have javax.servlet.* on the ClassPath");
210:                }
211:                assertEquals(
212:                        "Loaded wrong class first; expected to find parent CL's copy of javax.servlet.Servlet",
213:                        url.getProtocol(), "jar");
214:            }
215:
216:            /**
217:             * Tries to load a non-javax.* class that is aailable form the parent
218:             * ClassLoader, when there's a different definition available from this
219:             * ClassLoader.  This should load the parent's copy when
220:             * contextPriorityClassLoader is set to false (as here) and the child's
221:             * copy when the contextPriorityClassLoader is set to true.
222:             */
223:            public void xtestFalseExistantNonJavaxResource() {
224:                cl = new MultiParentClassLoader(configId, urls, getClass()
225:                        .getClassLoader(), false, HIDDEN, NON_OVERRIDABLE);
226:                URL url = cl.getResource("mx4j/MBeanDescription.class");
227:                if (url == null) {
228:                    fail("Problem with test; expecting to have mx4j.* on the ClassPath");
229:                }
230:                assertEquals(
231:                        "Should not have overriden parent CL definition of class mx4j.MBeanDescription",
232:                        url.getProtocol(), "jar");
233:            }
234:
235:            /**
236:             * Tries to load a non-javax.* class that is aailable form the parent
237:             * ClassLoader, when there's a different definition available from this
238:             * ClassLoader.  This should load the parent's copy when
239:             * contextPriorityClassLoader is set to false and the child's copy when
240:             * the contextPriorityClassLoader is set to true (as here).
241:             */
242:            public void testTrueExistantNonJavaxResource() {
243:                cl = new MultiParentClassLoader(configId, urls, getClass()
244:                        .getClassLoader(), true, new String[] {},
245:                        NON_OVERRIDABLE);
246:                URL url = cl.getResource("mx4j/MBeanDescription.class");
247:                if (url == null) {
248:                    fail("Problem with test; expecting to have mx4j.* on the ClassPath");
249:                }
250:                assertEquals(
251:                        "Should be able to override a class that is not in java.*, javax.*, etc.",
252:                        url.getProtocol(), "file");
253:            }
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.