2
|
1 |
/*
|
|
2 |
* Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/* @test
|
|
25 |
* @bug 4482455
|
|
26 |
* @summary URI.toURL() implementation needs to be improved
|
|
27 |
*
|
|
28 |
*/
|
|
29 |
|
|
30 |
import java.net.*;
|
|
31 |
|
|
32 |
public class URIToURLTest {
|
|
33 |
public static void main(String args[]) throws Exception {
|
|
34 |
String[] uris = {
|
|
35 |
"http://jag:cafebabe@java.sun.com:94/b/c/d?q#g",
|
|
36 |
"http://[1080:0:0:0:8:800:200C:417A]/index.html",
|
|
37 |
"http://a/b/c/d;p?q",
|
|
38 |
"ftp://ftp.is.co.za/rfc/rfc1808.txt",
|
|
39 |
"mailto:mduerst@ifi.unizh.ch", // opaque url
|
|
40 |
"http:comp.infosystems.www.servers.unix" //opaque url
|
|
41 |
};
|
|
42 |
|
|
43 |
for (int i = 0; i < uris.length; i++) {
|
|
44 |
URI uri = new URI(uris[i]);
|
|
45 |
URL url = uri.toURL();
|
|
46 |
String scheme = uri.getScheme();
|
|
47 |
boolean schemeCheck = scheme == null? url.getProtocol() == null :
|
|
48 |
scheme.equals(url.getProtocol());
|
|
49 |
if (!schemeCheck)
|
|
50 |
throw new RuntimeException("uri.scheme is " + scheme +
|
|
51 |
" url.protocol is " +
|
|
52 |
url.getProtocol());
|
|
53 |
|
|
54 |
if (uri.isOpaque()) {
|
|
55 |
String ssp = uri.getSchemeSpecificPart();
|
|
56 |
boolean sspCheck = ssp == null? uri.getPath() == null :
|
|
57 |
ssp.equals(url.getPath());
|
|
58 |
if (!sspCheck) {
|
|
59 |
throw new RuntimeException("uri.ssp is " + ssp +
|
|
60 |
" url.path is " + url.getPath());
|
|
61 |
}
|
|
62 |
} else {
|
|
63 |
String authority = uri.getAuthority();
|
|
64 |
boolean authorityCheck = authority == null?
|
|
65 |
url.getAuthority() == null :
|
|
66 |
authority.equals(url.getAuthority());
|
|
67 |
if (!authorityCheck) {
|
|
68 |
throw new RuntimeException("uri.authority is " +
|
|
69 |
authority + " url's is " +
|
|
70 |
url.getAuthority());
|
|
71 |
}
|
|
72 |
String host = uri.getHost();
|
|
73 |
boolean hostCheck = host == null ? url.getHost() == null :
|
|
74 |
host.equals(url.getHost());
|
|
75 |
if (!hostCheck)
|
|
76 |
throw new RuntimeException("uri.host is " +
|
|
77 |
host + " url's is " +
|
|
78 |
url.getHost());
|
|
79 |
if (host != null) {
|
|
80 |
String userInfo = uri.getUserInfo();
|
|
81 |
boolean userInfoCheck = userInfo == null?
|
|
82 |
url.getUserInfo() == null :
|
|
83 |
userInfo.equals(url.getUserInfo());
|
|
84 |
if (uri.getPort() != url.getPort())
|
|
85 |
throw new RuntimeException("uri.port is " +
|
|
86 |
uri.getPort() + " url's is " +
|
|
87 |
url.getPort());
|
|
88 |
}
|
|
89 |
|
|
90 |
String path = uri.getPath();
|
|
91 |
boolean pathCheck = path == null? url.getPath() == null :
|
|
92 |
path.equals(url.getPath());
|
|
93 |
if (!pathCheck)
|
|
94 |
throw new RuntimeException("uri.path is " + path +
|
|
95 |
" url.path is " +
|
|
96 |
url.getPath());
|
|
97 |
String query = uri.getQuery();
|
|
98 |
boolean queryCheck = query == null? url.getQuery() == null :
|
|
99 |
query.equals(url.getQuery());
|
|
100 |
if (!queryCheck)
|
|
101 |
throw new RuntimeException("uri.query is " + query +
|
|
102 |
" url.query is " +
|
|
103 |
url.getQuery());
|
|
104 |
}
|
|
105 |
String frag = uri.getFragment();
|
|
106 |
boolean fragCheck = frag == null? url.getRef() == null :
|
|
107 |
frag.equals(url.getRef());
|
|
108 |
if (!fragCheck)
|
|
109 |
throw new RuntimeException("uri.frag is " + frag +
|
|
110 |
" url.ref is " +
|
|
111 |
url.getRef());
|
|
112 |
}
|
|
113 |
}
|
|
114 |
}
|