Path: blob/master/test/jdk/sun/net/www/protocol/https/HttpsURLConnection/CheckMethods.java
41161 views
/*1* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 442307426* @summary Need to rebase all the duplicated classes from Merlin.27* This test will check out http POST28* @modules java.base/sun.net.www.protocol.https29*/30import java.net.*;31import java.util.*;32import java.lang.reflect.*;33import sun.net.www.protocol.https.HttpsURLConnectionImpl;3435public class CheckMethods {36static boolean debug = false;37static class MethodSignature {38String name;39Class[] paramTypes;40MethodSignature(String name, Class[] paramTypes) {41this.name = name;42this.paramTypes = paramTypes;43}4445public boolean equals(Object obj) {46if (debug)47System.out.println("comparing "+this +" against: "+obj);48if (!(obj instanceof MethodSignature)) {49if (debug)50System.out.println(false);51return false;52}53MethodSignature ms = (MethodSignature) obj;54Class[] types = ms.paramTypes;55try {56for (int i = 0; i < types.length; i++) {57if (!types[i].equals(paramTypes[i])) {58if (debug)59System.out.println(false);60return false;61}62}63} catch (Exception e) {64if (debug)65System.out.println(false);66return false;67}68boolean result = this.name.equals(ms.name);69if (debug)70System.out.println(result);71return result;72}7374public String toString() {75StringBuffer sb = new StringBuffer(name+"(");76for (int i = 0; i < paramTypes.length; i++) {77sb.append(paramTypes[i].getName()+",");78if (i == (paramTypes.length -1))79sb.deleteCharAt(sb.length()-1);80}81sb.append(")");82return sb.toString();83}84}8586// check HttpsURLConnectionImpl contain all public and protected methods87// defined in HttpURLConnection and URLConnection88public static void main(String[] args) {89ArrayList allMethods = new ArrayList(90Arrays.asList(HttpURLConnection.class.getDeclaredMethods()));91allMethods.addAll(Arrays.asList(URLConnection.class.getDeclaredMethods()));92ArrayList allMethodSignatures = new ArrayList();93for (Iterator itr = allMethods.iterator(); itr.hasNext(); ) {94Method m = (Method)itr.next();95// don't include static and private methods96if (!Modifier.isStatic(m.getModifiers()) &&97(Modifier.isPublic(m.getModifiers()) ||98Modifier.isProtected(m.getModifiers()))) {99allMethodSignatures.add(100new MethodSignature(m.getName(), m.getParameterTypes()));101}102}103104// testing HttpsURLConnectionImpl105List httpsMethods =106Arrays.asList(HttpsURLConnectionImpl.class.getDeclaredMethods());107108ArrayList httpsMethodSignatures = new ArrayList();109for (Iterator itr = httpsMethods.iterator(); itr.hasNext(); ) {110Method m = (Method)itr.next();111if (!Modifier.isStatic(m.getModifiers())) {112httpsMethodSignatures.add(113new MethodSignature(m.getName(), m.getParameterTypes()));114}115}116117if (!httpsMethodSignatures.containsAll(allMethodSignatures)) {118throw new RuntimeException("Method definition test failed on HttpsURLConnectionImpl");119}120121// testing for non static public field122ArrayList allFields = new ArrayList(123Arrays.asList(URLConnection.class.getFields()));124allFields.addAll(Arrays.asList(HttpURLConnection.class.getFields()));125126for (Iterator itr = allFields.iterator(); itr.hasNext(); ) {127Field f = (Field) itr.next();128if (!Modifier.isStatic(f.getModifiers())) {129throw new RuntimeException("Non static Public fields" +130" declared in superclasses");131}132}133}134}135136137