test/jdk/sun/net/www/protocol/https/HttpsURLConnection/CheckMethods.java
author xuelei
Fri, 01 Mar 2019 08:35:14 -0800
changeset 53972 43c2ab1bdfd3
parent 47216 71c04702a3d5
permissions -rw-r--r--
8215430: Remove the internal package com.sun.net.ssl Reviewed-by: chegar, mullan, wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4423074
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Need to rebase all the duplicated classes from Merlin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.net.www.protocol.https.HttpsURLConnectionImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class CheckMethods {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    static boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    static class MethodSignature {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        Class[] paramTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        MethodSignature(String name, Class[] paramTypes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
            this.paramTypes = paramTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                System.out.println("comparing "+this +" against: "+obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            if (!(obj instanceof MethodSignature)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                    System.out.println(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            MethodSignature ms = (MethodSignature) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            Class[] types = ms.paramTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                for (int i = 0; i < types.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                    if (!types[i].equals(paramTypes[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                        if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                            System.out.println(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                    System.out.println(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            boolean result = this.name.equals(ms.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                System.out.println(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            StringBuffer sb = new StringBuffer(name+"(");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            for (int i = 0; i < paramTypes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                sb.append(paramTypes[i].getName()+",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                if (i == (paramTypes.length -1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                    sb.deleteCharAt(sb.length()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            sb.append(")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        ArrayList allMethods = new ArrayList(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            Arrays.asList(HttpURLConnection.class.getDeclaredMethods()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        allMethods.addAll(Arrays.asList(URLConnection.class.getDeclaredMethods()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        ArrayList allMethodSignatures = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        for (Iterator itr = allMethods.iterator(); itr.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            Method m = (Method)itr.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            // don't include static and private methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            if (!Modifier.isStatic(m.getModifiers()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                (Modifier.isPublic(m.getModifiers()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                 Modifier.isProtected(m.getModifiers()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                allMethodSignatures.add(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    new MethodSignature(m.getName(), m.getParameterTypes()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // testing HttpsURLConnectionImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        List httpsMethods =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            Arrays.asList(HttpsURLConnectionImpl.class.getDeclaredMethods());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        ArrayList httpsMethodSignatures = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        for (Iterator itr = httpsMethods.iterator(); itr.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            Method m = (Method)itr.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            if (!Modifier.isStatic(m.getModifiers())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                httpsMethodSignatures.add(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                 new MethodSignature(m.getName(), m.getParameterTypes()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (!httpsMethodSignatures.containsAll(allMethodSignatures)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            throw new RuntimeException("Method definition test failed on HttpsURLConnectionImpl");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // testing for non static public field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        ArrayList allFields = new ArrayList(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            Arrays.asList(URLConnection.class.getFields()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        allFields.addAll(Arrays.asList(HttpURLConnection.class.getFields()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        for (Iterator itr = allFields.iterator(); itr.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            Field f = (Field) itr.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            if (!Modifier.isStatic(f.getModifiers())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                throw new RuntimeException("Non static Public fields" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                           " declared in superclasses");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}