Source code: com/lutris/classloader/tests/ClassLoaderTests.java
1 /*
2 * Enhydra Java Application Server Project
3 *
4 * The contents of this file are subject to the Enhydra Public License
5 * Version 1.1 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License on
7 * the Enhydra web site ( http://www.enhydra.org/ ).
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11 * the License for the specific terms governing rights and limitations
12 * under the License.
13 *
14 * The Initial Developer of the Enhydra Application Server is Lutris
15 * Technologies, Inc. The Enhydra Application Server and portions created
16 * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17 * All Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 * $Id: ClassLoaderTests.java,v 1.10.8.1 2000/10/19 17:58:53 jasona Exp $
22 */
23
24
25
26
27
28 package com.lutris.classloader.tests;
29
30 import com.lutris.classloader.*;
31 import java.io.File;
32 import java.io.IOException;
33 import java.net.URL;
34 import java.net.MalformedURLException;
35
36 public class ClassLoaderTests {
37 public static void main(String[] args) {
38 // String class path entries
39 System.err.println("\nTesting Strings");
40 String string = ".";
41 System.err.println("\nTrying: " + string);
42 ClassPathEntry cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
43 System.err.println("cpe.toString(): " + cpe.toString());
44 System.err.println("cpe.getName(): " + cpe.getName());
45 System.err.println("cpe.getLocation(): " + cpe.getLocation());
46 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
47 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
48 System.err.println("cpe.isRemote(): " + cpe.isRemote());
49 string = "./";
50 System.err.println("\nTrying: " + string);
51 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
52 System.err.println("\ncpe.toString(): " + cpe.toString());
53 System.err.println("cpe.getName(): " + cpe.getName());
54 System.err.println("cpe.getLocation(): " + cpe.getLocation());
55 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
56 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
57 System.err.println("cpe.isRemote(): " + cpe.isRemote());
58 string = "./lutris.jar";
59 System.err.println("\nTrying: " + string);
60 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
61 System.err.println("\ncpe.toString(): " + cpe.toString());
62 System.err.println("cpe.getName(): " + cpe.getName());
63 System.err.println("cpe.getLocation(): " + cpe.getLocation());
64 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
65 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
66 System.err.println("cpe.isRemote(): " + cpe.isRemote());
67 string = "/usr/local/bin";
68 System.err.println("\nTrying: " + string);
69 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
70 System.err.println("\ncpe.toString(): " + cpe.toString());
71 System.err.println("cpe.getName(): " + cpe.getName());
72 System.err.println("cpe.getLocation(): " + cpe.getLocation());
73 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
74 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
75 System.err.println("cpe.isRemote(): " + cpe.isRemote());
76 string = "/usr/local/bin/";
77 System.err.println("\nTrying: " + string);
78 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
79 System.err.println("\ncpe.toString(): " + cpe.toString());
80 System.err.println("cpe.getName(): " + cpe.getName());
81 System.err.println("cpe.getLocation(): " + cpe.getLocation());
82 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
83 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
84 System.err.println("cpe.isRemote(): " + cpe.isRemote());
85 string = "/usr/local/lutris.jar";
86 System.err.println("\nTrying: " + string);
87 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
88 System.err.println("\ncpe.toString(): " + cpe.toString());
89 System.err.println("cpe.getName(): " + cpe.getName());
90 System.err.println("cpe.getLocation(): " + cpe.getLocation());
91 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
92 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
93 System.err.println("cpe.isRemote(): " + cpe.isRemote());
94 string = "file:///pub";
95 System.err.println("\nTrying: " + string);
96 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
97 System.err.println("\ncpe.toString(): " + cpe.toString());
98 System.err.println("cpe.getName(): " + cpe.getName());
99 System.err.println("cpe.getLocation(): " + cpe.getLocation());
100 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
101 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
102 System.err.println("cpe.isRemote(): " + cpe.isRemote());
103 string = "file:///pub/";
104 System.err.println("\nTrying: " + string);
105 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
106 System.err.println("\ncpe.toString(): " + cpe.toString());
107 System.err.println("cpe.getName(): " + cpe.getName());
108 System.err.println("cpe.getLocation(): " + cpe.getLocation());
109 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
110 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
111 System.err.println("cpe.isRemote(): " + cpe.isRemote());
112 string = "file://localhost/pub";
113 System.err.println("\nTrying: " + string);
114 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
115 System.err.println("\ncpe.toString(): " + cpe.toString());
116 System.err.println("cpe.getName(): " + cpe.getName());
117 System.err.println("cpe.getLocation(): " + cpe.getLocation());
118 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
119 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
120 System.err.println("cpe.isRemote(): " + cpe.isRemote());
121 string = "file://localhost/pub/";
122 System.err.println("\nTrying: " + string);
123 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
124 System.err.println("\ncpe.toString(): " + cpe.toString());
125 System.err.println("cpe.getName(): " + cpe.getName());
126 System.err.println("cpe.getLocation(): " + cpe.getLocation());
127 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
128 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
129 System.err.println("cpe.isRemote(): " + cpe.isRemote());
130 string = "file://localhost:8080/pub";
131 System.err.println("\nTrying: " + string);
132 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
133 System.err.println("\ncpe.toString(): " + cpe.toString());
134 System.err.println("cpe.getName(): " + cpe.getName());
135 System.err.println("cpe.getLocation(): " + cpe.getLocation());
136 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
137 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
138 System.err.println("cpe.isRemote(): " + cpe.isRemote());
139 string = "file://localhost:8080/pub/";
140 System.err.println("\nTrying: " + string);
141 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
142 System.err.println("\ncpe.toString(): " + cpe.toString());
143 System.err.println("cpe.getName(): " + cpe.getName());
144 System.err.println("cpe.getLocation(): " + cpe.getLocation());
145 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
146 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
147 System.err.println("cpe.isRemote(): " + cpe.isRemote());
148 // FIXME: should add 127.0.0.1 ?
149 string = "http://foo.com/pub";
150 System.err.println("\nTrying: " + string);
151 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
152 System.err.println("\ncpe.toString(): " + cpe.toString());
153 System.err.println("cpe.getName(): " + cpe.getName());
154 System.err.println("cpe.getLocation(): " + cpe.getLocation());
155 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
156 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
157 System.err.println("cpe.isRemote(): " + cpe.isRemote());
158 string = "http://foo.com/pub/";
159 System.err.println("\nTrying: " + string);
160 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
161 System.err.println("\ncpe.toString(): " + cpe.toString());
162 System.err.println("cpe.getName(): " + cpe.getName());
163 System.err.println("cpe.getLocation(): " + cpe.getLocation());
164 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
165 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
166 System.err.println("cpe.isRemote(): " + cpe.isRemote());
167 string = "http://foo.com:90/pub";
168 System.err.println("\nTrying: " + string);
169 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
170 System.err.println("\ncpe.toString(): " + cpe.toString());
171 System.err.println("cpe.getName(): " + cpe.getName());
172 System.err.println("cpe.getLocation(): " + cpe.getLocation());
173 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
174 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
175 System.err.println("cpe.isRemote(): " + cpe.isRemote());
176 string = "http://foo.com:90/pub/";
177 System.err.println("\nTrying: " + string);
178 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
179 System.err.println("\ncpe.toString(): " + cpe.toString());
180 System.err.println("cpe.getName(): " + cpe.getName());
181 System.err.println("cpe.getLocation(): " + cpe.getLocation());
182 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
183 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
184 System.err.println("cpe.isRemote(): " + cpe.isRemote());
185 string = "http://foo.com/pub/blah.jar";
186 System.err.println("\nTrying: " + string);
187 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
188 System.err.println("\ncpe.toString(): " + cpe.toString());
189 System.err.println("cpe.getName(): " + cpe.getName());
190 System.err.println("cpe.getLocation(): " + cpe.getLocation());
191 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
192 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
193 System.err.println("cpe.isRemote(): " + cpe.isRemote());
194 string = "http://foo.com:9999/pub/blah.jar";
195 System.err.println("\nTrying: " + string);
196 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
197 System.err.println("\ncpe.toString(): " + cpe.toString());
198 System.err.println("cpe.getName(): " + cpe.getName());
199 System.err.println("cpe.getLocation(): " + cpe.getLocation());
200 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
201 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
202 System.err.println("cpe.isRemote(): " + cpe.isRemote());
203 // File class path entries
204 System.err.println("\nTesting Files");
205 File file = new File(".");
206 System.err.println("\nTrying: " + file);
207 cpe = new ClassPathEntry(file, MultiClassLoaderTests.getLogChannel());
208 System.err.println("\ncpe.toString(): " + cpe.toString());
209 System.err.println("cpe.getName(): " + cpe.getName());
210 System.err.println("cpe.getLocation(): " + cpe.getLocation());
211 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
212 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
213 System.err.println("cpe.isRemote(): " + cpe.isRemote());
214 file = new File("/usr/local/lutris.jar");
215 System.err.println("\nTrying: " + file);
216 cpe = new ClassPathEntry(file, MultiClassLoaderTests.getLogChannel());
217 System.err.println("\ncpe.toString(): " + cpe.toString());
218 System.err.println("cpe.getName(): " + cpe.getName());
219 System.err.println("cpe.getLocation(): " + cpe.getLocation());
220 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
221 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
222 System.err.println("cpe.isRemote(): " + cpe.isRemote());
223 // URL class path entries
224 System.err.println("\nTesting URLs");
225 try {
226 URL url = new URL("file:///pub/");
227 System.err.println("\nTrying: " + url);
228 cpe = new ClassPathEntry(url, MultiClassLoaderTests.getLogChannel());
229 System.err.println("\ncpe.toString(): " + cpe.toString());
230 System.err.println("cpe.getName(): " + cpe.getName());
231 System.err.println("cpe.getLocation(): " + cpe.getLocation());
232 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
233 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
234 System.err.println("cpe.isRemote(): " + cpe.isRemote());
235 url = new URL("file:///pub");
236 System.err.println("\nTrying: " + url);
237 cpe = new ClassPathEntry(url, MultiClassLoaderTests.getLogChannel());
238 System.err.println("\ncpe.toString(): " + cpe.toString());
239 System.err.println("cpe.getName(): " + cpe.getName());
240 System.err.println("cpe.getLocation(): " + cpe.getLocation());
241 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
242 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
243 System.err.println("cpe.isRemote(): " + cpe.isRemote());
244 url = new URL("file:///pub/lutris.jar");
245 System.err.println("\nTrying: " + url);
246 cpe = new ClassPathEntry(url, MultiClassLoaderTests.getLogChannel());
247 System.err.println("\ncpe.toString(): " + cpe.toString());
248 System.err.println("cpe.getName(): " + cpe.getName());
249 System.err.println("cpe.getLocation(): " + cpe.getLocation());
250 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
251 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
252 System.err.println("cpe.isRemote(): " + cpe.isRemote());
253 url = new URL("http://foo.com/pub");
254 System.err.println("\nTrying: " + url);
255 cpe = new ClassPathEntry(url, MultiClassLoaderTests.getLogChannel());
256 System.err.println("\ncpe.toString(): " + cpe.toString());
257 System.err.println("cpe.getName(): " + cpe.getName());
258 System.err.println("cpe.getLocation(): " + cpe.getLocation());
259 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
260 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
261 System.err.println("cpe.isRemote(): " + cpe.isRemote());
262 url = new URL("http://foo.com/pub/");
263 System.err.println("\nTrying: " + url);
264 cpe = new ClassPathEntry(url, MultiClassLoaderTests.getLogChannel());
265 System.err.println("\ncpe.toString(): " + cpe.toString());
266 System.err.println("cpe.getName(): " + cpe.getName());
267 System.err.println("cpe.getLocation(): " + cpe.getLocation());
268 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
269 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
270 System.err.println("cpe.isRemote(): " + cpe.isRemote());
271 url = new URL("http://foo.com:84/pub");
272 System.err.println("\nTrying: " + url);
273 cpe = new ClassPathEntry(url, MultiClassLoaderTests.getLogChannel());
274 System.err.println("\ncpe.toString(): " + cpe.toString());
275 System.err.println("cpe.getName(): " + cpe.getName());
276 System.err.println("cpe.getLocation(): " + cpe.getLocation());
277 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
278 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
279 System.err.println("cpe.isRemote(): " + cpe.isRemote());
280 url = new URL("http://foo.com:84/pub/");
281 System.err.println("\nTrying: " + url);
282 cpe = new ClassPathEntry(url, MultiClassLoaderTests.getLogChannel());
283 System.err.println("\ncpe.toString(): " + cpe.toString());
284 System.err.println("cpe.getName(): " + cpe.getName());
285 System.err.println("cpe.getLocation(): " + cpe.getLocation());
286 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
287 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
288 System.err.println("cpe.isRemote(): " + cpe.isRemote());
289 url = new URL("http://foo.com/pub/blah.jar");
290 System.err.println("\nTrying: " + url);
291 cpe = new ClassPathEntry(url, MultiClassLoaderTests.getLogChannel());
292 System.err.println("\ncpe.toString(): " + cpe.toString());
293 System.err.println("cpe.getName(): " + cpe.getName());
294 System.err.println("cpe.getLocation(): " + cpe.getLocation());
295 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
296 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
297 System.err.println("cpe.isRemote(): " + cpe.isRemote());
298 url = new URL("http://foo.com:8484/pub/blah.jar");
299 System.err.println("\nTrying: " + url);
300 cpe = new ClassPathEntry(url, MultiClassLoaderTests.getLogChannel());
301 System.err.println("\ncpe.toString(): " + cpe.toString());
302 System.err.println("cpe.getName(): " + cpe.getName());
303 System.err.println("cpe.getLocation(): " + cpe.getLocation());
304 System.err.println("cpe.isDirectory(): " + cpe.isDirectory());
305 System.err.println("cpe.isZipFile(): " + cpe.isZipFile());
306 System.err.println("cpe.isRemote(): " + cpe.isRemote());
307
308 // Test resources
309 System.err.println("\nTesting Resources");
310 string = ".";
311 System.err.println("\nTrying: " + string);
312 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
313 System.err.println("\ncpe.toString(): " + cpe.toString());
314 string = "com/lutris/classloader/tests/TestClass.class";
315 System.err.println("\nTrying: " + string);
316 Resource res = cpe.getResource(string);
317 if (res != null) {
318 System.err.println("res.toString(): " + res.toString());
319 System.err.println("res.getName(): " + res.getName());
320 System.err.println("res.getLocation(): " + res.getLocation());
321 System.err.println("res.getSize(): " + res.getSize());
322 System.err.println("res.getTime(): " + res.getTime());
323 System.err.println("res.getInputStream(): " + res.getInputStream());
324 System.err.println("res.getBytes().length: "+res.getBytes().length);
325 } else {
326 System.err.println("\n\"" + string + "\" not found");
327 }
328
329 string = "com/lutris/classloader/tests/bogus.txt";
330 System.err.println("\nTrying: " + string);
331 res = cpe.getResource(string);
332 if (res != null) {
333 System.err.println("res.toString(): " + res.toString());
334 System.err.println("res.getName(): " + res.getName());
335 System.err.println("res.getLocation(): " + res.getLocation());
336 System.err.println("res.getSize(): " + res.getSize());
337 System.err.println("res.getTime(): " + res.getTime());
338 System.err.println("res.getInputStream(): " + res.getInputStream());
339 System.err.println("res.getBytes().length: "+res.getBytes().length);
340 } else {
341 System.err.println("\n\"" + string + "\" not found");
342 }
343
344 string = "com/lutris/classloader/tests/TestClass.jar";
345 System.err.println("\nTrying: " + string);
346 cpe = new ClassPathEntry(string, MultiClassLoaderTests.getLogChannel());
347 System.err.println("\ncpe.toString(): " + cpe.toString());
348 string = "com/lutris/classloader/tests/TestClass.class";
349 System.err.println("\nTrying: " + string);
350 res = cpe.getResource(string);
351 if (res != null) {
352 System.err.println("res.toString(): " + res.toString());
353 System.err.println("res.getName(): " + res.getName());
354 System.err.println("res.getLocation(): " + res.getLocation());
355 System.err.println("res.getSize(): " + res.getSize());
356 System.err.println("res.getTime(): " + res.getTime());
357 System.err.println("res.getInputStream(): " + res.getInputStream());
358 System.err.println("res.getBytes().length: "+res.getBytes().length);
359 } else {
360 System.err.println("\n\"" + string + "\" not found");
361 }
362
363 string = "com/lutris/util/bogus.class";
364 System.err.println("\nTrying: " + string);
365 res = cpe.getResource(string);
366 if (res != null) {
367 System.err.println("res.toString(): " + res.toString());
368 System.err.println("res.getName(): " + res.getName());
369 System.err.println("res.getLocation(): " + res.getLocation());
370 System.err.println("res.getSize(): " + res.getSize());
371 System.err.println("res.getTime(): " + res.getTime());
372 System.err.println("res.getInputStream(): " + res.getInputStream());
373 System.err.println("res.getBytes().length: "+res.getBytes().length);
374 } else {
375 System.err.println("\n\"" + string + "\" not found");
376 }
377 } catch (MalformedURLException e) {
378 System.err.println("malformed url");
379 } catch (IOException e) {
380 System.err.println("ioexception");
381 }
382 }
383 }