author | xuelei |
Fri, 01 Mar 2019 08:35:14 -0800 | |
changeset 53972 | 43c2ab1bdfd3 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53972
43c2ab1bdfd3
8215430: Remove the internal package com.sun.net.ssl
xuelei
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4423074 |
|
27 |
* @summary Need to rebase all the duplicated classes from Merlin. |
|
28 |
* This test will check out http POST |
|
53972
43c2ab1bdfd3
8215430: Remove the internal package com.sun.net.ssl
xuelei
parents:
47216
diff
changeset
|
29 |
* @modules java.base/sun.net.www.protocol.https |
2 | 30 |
*/ |
31 |
import java.net.*; |
|
32 |
import java.util.*; |
|
33 |
import java.lang.reflect.*; |
|
34 |
import sun.net.www.protocol.https.HttpsURLConnectionImpl; |
|
35 |
||
36 |
public class CheckMethods { |
|
37 |
static boolean debug = false; |
|
38 |
static class MethodSignature { |
|
39 |
String name; |
|
40 |
Class[] paramTypes; |
|
41 |
MethodSignature(String name, Class[] paramTypes) { |
|
42 |
this.name = name; |
|
43 |
this.paramTypes = paramTypes; |
|
44 |
} |
|
45 |
||
46 |
public boolean equals(Object obj) { |
|
47 |
if (debug) |
|
48 |
System.out.println("comparing "+this +" against: "+obj); |
|
49 |
if (!(obj instanceof MethodSignature)) { |
|
50 |
if (debug) |
|
51 |
System.out.println(false); |
|
52 |
return false; |
|
53 |
} |
|
54 |
MethodSignature ms = (MethodSignature) obj; |
|
55 |
Class[] types = ms.paramTypes; |
|
56 |
try { |
|
57 |
for (int i = 0; i < types.length; i++) { |
|
58 |
if (!types[i].equals(paramTypes[i])) { |
|
59 |
if (debug) |
|
60 |
System.out.println(false); |
|
61 |
return false; |
|
62 |
} |
|
63 |
} |
|
64 |
} catch (Exception e) { |
|
65 |
if (debug) |
|
66 |
System.out.println(false); |
|
67 |
return false; |
|
68 |
} |
|
69 |
boolean result = this.name.equals(ms.name); |
|
70 |
if (debug) |
|
71 |
System.out.println(result); |
|
72 |
return result; |
|
73 |
} |
|
74 |
||
75 |
public String toString() { |
|
76 |
StringBuffer sb = new StringBuffer(name+"("); |
|
77 |
for (int i = 0; i < paramTypes.length; i++) { |
|
78 |
sb.append(paramTypes[i].getName()+","); |
|
79 |
if (i == (paramTypes.length -1)) |
|
80 |
sb.deleteCharAt(sb.length()-1); |
|
81 |
} |
|
82 |
sb.append(")"); |
|
83 |
return sb.toString(); |
|
84 |
} |
|
85 |
} |
|
86 |
||
53972
43c2ab1bdfd3
8215430: Remove the internal package com.sun.net.ssl
xuelei
parents:
47216
diff
changeset
|
87 |
// check HttpsURLConnectionImpl contain all public and protected methods |
43c2ab1bdfd3
8215430: Remove the internal package com.sun.net.ssl
xuelei
parents:
47216
diff
changeset
|
88 |
// defined in HttpURLConnection and URLConnection |
2 | 89 |
public static void main(String[] args) { |
90 |
ArrayList allMethods = new ArrayList( |
|
91 |
Arrays.asList(HttpURLConnection.class.getDeclaredMethods())); |
|
92 |
allMethods.addAll(Arrays.asList(URLConnection.class.getDeclaredMethods())); |
|
93 |
ArrayList allMethodSignatures = new ArrayList(); |
|
94 |
for (Iterator itr = allMethods.iterator(); itr.hasNext(); ) { |
|
95 |
Method m = (Method)itr.next(); |
|
96 |
// don't include static and private methods |
|
97 |
if (!Modifier.isStatic(m.getModifiers()) && |
|
98 |
(Modifier.isPublic(m.getModifiers()) || |
|
99 |
Modifier.isProtected(m.getModifiers()))) { |
|
100 |
allMethodSignatures.add( |
|
101 |
new MethodSignature(m.getName(), m.getParameterTypes())); |
|
102 |
} |
|
103 |
} |
|
104 |
||
105 |
// testing HttpsURLConnectionImpl |
|
106 |
List httpsMethods = |
|
107 |
Arrays.asList(HttpsURLConnectionImpl.class.getDeclaredMethods()); |
|
108 |
||
109 |
ArrayList httpsMethodSignatures = new ArrayList(); |
|
110 |
for (Iterator itr = httpsMethods.iterator(); itr.hasNext(); ) { |
|
111 |
Method m = (Method)itr.next(); |
|
112 |
if (!Modifier.isStatic(m.getModifiers())) { |
|
113 |
httpsMethodSignatures.add( |
|
114 |
new MethodSignature(m.getName(), m.getParameterTypes())); |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
if (!httpsMethodSignatures.containsAll(allMethodSignatures)) { |
|
119 |
throw new RuntimeException("Method definition test failed on HttpsURLConnectionImpl"); |
|
120 |
} |
|
121 |
||
122 |
// testing for non static public field |
|
123 |
ArrayList allFields = new ArrayList( |
|
124 |
Arrays.asList(URLConnection.class.getFields())); |
|
125 |
allFields.addAll(Arrays.asList(HttpURLConnection.class.getFields())); |
|
126 |
||
127 |
for (Iterator itr = allFields.iterator(); itr.hasNext(); ) { |
|
128 |
Field f = (Field) itr.next(); |
|
129 |
if (!Modifier.isStatic(f.getModifiers())) { |
|
130 |
throw new RuntimeException("Non static Public fields" + |
|
131 |
" declared in superclasses"); |
|
132 |
} |
|
133 |
} |
|
134 |
} |
|
135 |
} |