test/jdk/com/sun/jmx/mbeanserver/introspector/SimpleIntrospectorTest.java
author mbaesken
Tue, 03 Sep 2019 16:52:55 +0200
changeset 58000 62926eb5e40e
parent 47216 71c04702a3d5
permissions -rw-r--r--
8230485: add handling of aix tar in configure Reviewed-by: erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32101
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
     1
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
     2
/*
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
     3
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
     5
 *
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
     8
 * published by the Free Software Foundation.  Oracle designates this
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
     9
 * particular file as subject to the "Classpath" exception as provided
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    10
 * by Oracle in the LICENSE file that accompanied this code.
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    11
 *
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    12
 * This code is distributed in the hope that it will be useful, but WITHOUT
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    14
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    15
 * version 2 for more details (a copy is included in the LICENSE file that
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    16
 * accompanied this code).
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    17
 *
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    18
 * You should have received a copy of the GNU General Public License version
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    19
 * 2 along with this work; if not, write to the Free Software Foundation,
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    20
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    21
 *
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    22
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    23
 * or visit www.oracle.com if you need additional information or have any
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    24
 * questions.
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    25
 */
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    26
import java.lang.reflect.Method;
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    27
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    28
/*
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    29
 * @test
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    30
 * @bug 8129215
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    31
 * @summary The test checks whether the SimpleIntrospector is honoring the
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    32
 *          the JavaBeans property naming convention of always starting
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    33
 *          with a lower-case letter
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    34
 *
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    35
 * @author Jaroslav Bachorik
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 35315
diff changeset
    36
 * @modules java.management/com.sun.jmx.mbeanserver:open
32101
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    37
 * @run clean SimpleIntrospectorTest
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    38
 * @run build SimpleIntrospectorTest BeanClass
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    39
 * @run main SimpleIntrospectorTest
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    40
 */
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    41
public class SimpleIntrospectorTest {
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    42
    private static Method INTROSPECT_GETTER;
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    43
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    44
    public static void main(String ... args) throws Exception {
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    45
        Class clz = Class.forName(
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    46
            "com.sun.jmx.mbeanserver.Introspector$SimpleIntrospector"
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    47
        );
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    48
        INTROSPECT_GETTER = clz.getDeclaredMethod(
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    49
            "getReadMethod",
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    50
            Class.class,
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    51
            String.class
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    52
        );
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    53
        INTROSPECT_GETTER.setAccessible(true);
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    54
        boolean result = true;
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    55
        result &= checkNumberValid();
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    56
        result &= checkNumberInvalid();
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    57
        result &= checkAvailableValid();
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    58
        result &= checkAvailableInvalid();
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    59
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    60
        if (!result) {
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    61
            throw new Error();
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    62
        }
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    63
    }
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    64
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    65
    private static boolean checkNumberValid() throws Exception {
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    66
        return checkGetter(false, "number");
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    67
    }
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    68
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    69
    private static boolean checkNumberInvalid() throws Exception {
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    70
        return checkGetter(true, "Number");
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    71
    }
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    72
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    73
    private static boolean checkAvailableValid() throws Exception {
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    74
        return checkGetter(false, "available");
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    75
    }
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    76
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    77
    private static boolean checkAvailableInvalid() throws Exception {
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    78
        return checkGetter(true, "Available");
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    79
    }
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    80
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    81
    private static boolean checkGetter(boolean nullExpected, String name)
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    82
    throws Exception {
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    83
        Method m = getReadMethod(BeanClass.class, name);
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    84
        boolean result = (m != null);
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    85
        if (nullExpected) result = !result;
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    86
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    87
        if (result) {
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    88
            return true;
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    89
        }
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    90
        if (nullExpected) {
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    91
            System.err.println("SimpleIntrospector resolved an unknown getter " +
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    92
                               "for attribute '"+ name +"'");
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    93
        } else {
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    94
            System.err.println("SimpleIntrospector fails to resolve getter " +
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    95
                               "for attribute '"+ name +"'");
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    96
        }
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    97
        return false;
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    98
    }
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
    99
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
   100
    private static Method getReadMethod(Class clz, String attr)
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
   101
    throws Exception {
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
   102
        return (Method)INTROSPECT_GETTER.invoke(null, clz, attr);
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
   103
    }
d7400a695eec 8129215: com.sun.jmx.mbeanserver.Introspector may provide results inconsistent with the JavaBeans Introspector
jbachorik
parents:
diff changeset
   104
}