jdk/test/javax/management/generified/GenericTest.java
author dbuck
Tue, 18 Aug 2015 04:29:28 -0700
changeset 32417 6859107fc6c3
parent 30376 2ccf2cf7ea48
child 44423 306c020eb154
permissions -rw-r--r--
8133666: OperatingSystemMXBean reports abnormally high machine CPU consumption on Linux Reviewed-by: sla, mgronlun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
     2
 * Copyright (c) 2004, 2015, 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 4847959 6191402
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test newly-generified APIs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Eamonn McManus
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
    29
 * @modules java.management
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run clean GenericTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run build GenericTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main GenericTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.lang.management.ManagementFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.openmbean.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.relation.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.timer.Timer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.timer.TimerMBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class GenericTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static int failures;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        // Check we are really using the generified version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        boolean generic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        Method findmbs = MBeanServerFactory.class.getMethod("findMBeanServer",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                                                            String.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        Type findmbstype = findmbs.getGenericReturnType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (!(findmbstype instanceof ParameterizedType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            System.out.println("FAILURE: API NOT GENERIC!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            System.out.println("  MBeanServerFactory.findMBeanServer -> " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                               findmbstype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            failures++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            generic = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            System.out.println("OK: this API is generic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            generic = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        ArrayList<MBeanServer> mbsList1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            MBeanServerFactory.findMBeanServer(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        checked(mbsList1, MBeanServer.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        ArrayList mbsList2 = MBeanServerFactory.findMBeanServer(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        check("ArrayList<MBeanServer> findMBeanServer", mbsList1.size() == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        check("ArrayList findMBeanServer", mbsList1.equals(mbsList2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        Set<ObjectName> names1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            checked(mbs.queryNames(null, null), ObjectName.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        Set names2 = mbs.queryNames(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        Set<ObjectName> names3 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            checked(((MBeanServerConnection) mbs).queryNames(null, null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                    ObjectName.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        check("Set<ObjectName> MBeanServer.queryNames", names1.size() >= 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        check("Set MBeanServer.queryNames", names2.size() >= 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        check("Set<ObjectName> MBeanServerConnection.queryNames",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
              names3.size() >= 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        check("queryNames sets same",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
              names1.equals(names2) && names2.equals(names3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        Set<ObjectInstance> mbeans1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            checked(mbs.queryMBeans(null, null), ObjectInstance.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        Set mbeans2 = mbs.queryMBeans(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        Set<ObjectInstance> mbeans3 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            checked(((MBeanServerConnection) mbs).queryMBeans(null, null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    ObjectInstance.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        check("Set<ObjectInstsance> MBeanServer.queryMBeans",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
              mbeans1.size() >= 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        check("Set MBeanServer.queryMBeans", mbeans2.size() >= 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        check("Set<ObjectInstsance> MBeanServerConnection.queryMBeans",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
              mbeans3.size() >= 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        check("queryMBeans sets same",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
              mbeans1.equals(mbeans2) && mbeans2.equals(mbeans3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        AttributeChangeNotificationFilter acnf =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            new AttributeChangeNotificationFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        acnf.enableAttribute("foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        Vector<String> acnfs = acnf.getEnabledAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        checked(acnfs, String.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        check("Vector<String> AttributeChangeNotificationFilter.getEnabled" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
              "Attributes", acnfs.equals(Arrays.asList(new String[] {"foo"})));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (generic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            Attribute a = new Attribute("foo", "bar");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            AttributeList al1 = new AttributeList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            al1.add(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            AttributeList al2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                new AttributeList(Arrays.asList(new Attribute[] {a}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            check("new AttributeList(List<Attribute>)", al1.equals(al2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            List<Attribute> al3 = checked(al1.asList(), Attribute.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            al3.remove(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            check("List<Attribute> AttributeList.asList()",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                  al1.equals(al3) && al1.isEmpty());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        List<ObjectName> namelist1 = new ArrayList<ObjectName>(names1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        Role role = new Role("rolename", namelist1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        List<ObjectName> namelist2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            checked(role.getRoleValue(), ObjectName.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        check("new Role(String,List<ObjectName>).getRoleValue() -> " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
              "List<ObjectName>", namelist1.equals(namelist2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        RoleList rl1 = new RoleList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        rl1.add(role);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        RoleList rl2 = new RoleList(Arrays.asList(new Role[] {role}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        check("new RoleList(List<Role>)", rl1.equals(rl2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (generic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            List<Role> rl3 = checked(rl1.asList(), Role.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            rl3.remove(role);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            check("List<Role> RoleList.asList()",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                  rl1.equals(rl3) && rl1.isEmpty());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        RoleUnresolved ru =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            new RoleUnresolved("rolename", namelist1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                               RoleStatus.LESS_THAN_MIN_ROLE_DEGREE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        List<ObjectName> namelist3 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            checked(ru.getRoleValue(), ObjectName.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        check("new RoleUnresolved(...List<ObjectName>...).getRoleValue() -> " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
              "List<ObjectName>", namelist1.equals(namelist3));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        RoleUnresolvedList rul1 = new RoleUnresolvedList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        rul1.add(ru);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        RoleUnresolvedList rul2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            new RoleUnresolvedList(Arrays.asList(new RoleUnresolved[] {ru}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        check("new RoleUnresolvedList(List<RoleUnresolved>", rul1.equals(rul2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (generic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            List<RoleUnresolved> rul3 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                checked(rul1.asList(), RoleUnresolved.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            rul3.remove(ru);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            check("List<RoleUnresolved> RoleUnresolvedList.asList()",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                  rul1.equals(rul3) && rul1.isEmpty());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        // This case basically just tests that we can compile this sort of thing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        OpenMBeanAttributeInfo ombai1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            new OpenMBeanAttributeInfoSupport("a", "a descr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                                SimpleType.INTEGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                                true, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        CompositeType ct =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            new CompositeType("ct", "ct descr", new String[] {"item1"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                              new String[] {"item1 descr"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                              new OpenType[] {SimpleType.INTEGER});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        OpenMBeanAttributeInfo ombai2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            new OpenMBeanAttributeInfoSupport("a", "a descr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                                      ct, true, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        TabularType tt =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            new TabularType("tt", "tt descr", ct, new String[] {"item1"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        OpenMBeanAttributeInfo ombai3 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            new OpenMBeanAttributeInfoSupport("a", "a descr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                                    tt, true, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        ArrayType<String[][]> at =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            new ArrayType<String[][]>(2, SimpleType.STRING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        OpenMBeanAttributeInfo ombai4 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            new OpenMBeanAttributeInfoSupport("a", "a descr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                                   at, true, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        OpenMBeanAttributeInfo ombai4a =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            new OpenMBeanAttributeInfoSupport("a", "a descr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                              (ArrayType) at,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                              true, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        OpenMBeanAttributeInfo ombai5 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            new OpenMBeanAttributeInfoSupport("a", "a descr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                                       SimpleType.INTEGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                                       true, true, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                                       5, 1, 9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        OpenMBeanAttributeInfo ombai6 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            new OpenMBeanAttributeInfoSupport("a", "a descr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                                       SimpleType.INTEGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                                       true, true, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                                       5, new Integer[] {1, 5});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        OpenMBeanInfo ombi =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            new OpenMBeanInfoSupport("a.a", "a.a descr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                     new OpenMBeanAttributeInfo[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                         ombai1, ombai2, ombai3, ombai4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                                         ombai5, ombai6,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                     },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                     null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        Map<String,Integer> itemMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            checked(singletonMap("item1", 5),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    String.class, Integer.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        CompositeData cd =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            new CompositeDataSupport(ct, itemMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        check("CompositeDataSupport(CompositeType, Map<String,?>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
              cd.get("item1").equals(5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        Set<String> ctkeys = checked(ct.keySet(), String.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        check("Set<String> CompositeType.keySet()",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
              ctkeys.equals(singleton("item1")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        List<String> ttindex = checked(tt.getIndexNames(), String.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        check("Set<String> TabularType.getIndexNames()",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
              ttindex.equals(singletonList("item1")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        TabularData td = new TabularDataSupport(tt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        td.putAll(new CompositeData[] {cd});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        List<Integer> tdkey = checked(singletonList(5), Integer.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        Set<List<Integer>> tdkeys = checked(singleton(tdkey),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            (Class<List<Integer>>) tdkey.getClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        Collection<CompositeData> tdvalues = checked(singleton(cd),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            CompositeData.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        check("Set<List<?>> TabularDataSupport.keySet()",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
              td.keySet().equals(tdkeys));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        check("Collection<CompositeData> TabularDataSupport.values()",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
              td.values().iterator().next().equals(tdvalues.iterator().next()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        ObjectName stupidName = new ObjectName("stupid:a=b");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        mbs.registerMBean(new Stupid(), stupidName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        StupidMBean proxy =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            MBeanServerInvocationHandler.newProxyInstance(mbs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                                          stupidName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                                          StupidMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                                          false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        check("MBeanServerInvocationHandler.newProxyInstance",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
              proxy.getFive() == 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        mbs.unregisterMBean(stupidName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        mbs.registerMBean(new StandardMBean(new Stupid(), StupidMBean.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                          stupidName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        check("<T> StandardMBean(T impl, Class<T> intf)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
              proxy.getFive() == 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        // Following is based on the package.html for javax.management.relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        // Create the Relation Service MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        ObjectName relSvcName = new ObjectName(":type=RelationService");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        RelationService relSvcObject = new RelationService(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        mbs.registerMBean(relSvcObject, relSvcName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        // Create an MBean proxy for easier access to the Relation Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        RelationServiceMBean relSvc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        MBeanServerInvocationHandler.newProxyInstance(mbs, relSvcName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                                      RelationServiceMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                                      false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        // Define the DependsOn relation type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        RoleInfo[] dependsOnRoles = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            new RoleInfo("dependent", Module.class.getName()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            new RoleInfo("dependedOn", Module.class.getName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        relSvc.createRelationType("DependsOn", dependsOnRoles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        // Now define a relation instance "moduleA DependsOn moduleB"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        ObjectName moduleA = new ObjectName(":type=Module,name=A");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        ObjectName moduleB = new ObjectName(":type=Module,name=B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        // Following two lines added to example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        mbs.registerMBean(new Module(), moduleA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        mbs.registerMBean(new Module(), moduleB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        Role dependent = new Role("dependent", singletonList(moduleA));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        Role dependedOn = new Role("dependedOn", singletonList(moduleB));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        Role[] roleArray = {dependent, dependedOn};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        RoleList roles = new RoleList(Arrays.asList(roleArray));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        relSvc.createRelation("A-DependsOn-B", "DependsOn", roles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        // Query the Relation Service to find what modules moduleA depends on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        Map<ObjectName,List<String>> dependentAMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        relSvc.findAssociatedMBeans(moduleA, "DependsOn", "dependent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        Set<ObjectName> dependentASet = dependentAMap.keySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        dependentASet = checked(dependentASet, ObjectName.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // Set of ObjectName containing moduleB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        check("Map<ObjectName,List<String>> RelationService.findAssociatedMBeans",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
              dependentAMap.size() == 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
              dependentASet.equals(singleton(moduleB)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        Map<String,List<String>> refRels =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            relSvc.findReferencingRelations(moduleA, "DependsOn", "dependent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        List<String> refRoles =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            checked(refRels.get("A-DependsOn-B"), String.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        check("Map<String,List<String>> RelationService.findReferencingRelations",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
              refRoles.equals(singletonList("dependent")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        List<String> relsOfType = relSvc.findRelationsOfType("DependsOn");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        relsOfType = checked(relsOfType, String.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        check("List<String> RelationService.findRelationsOfType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
              relsOfType.equals(singletonList("A-DependsOn-B")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        List<String> allRelIds = relSvc.getAllRelationIds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        allRelIds = checked(allRelIds, String.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        check("List<String> RelationService.getAllRelationIds()",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
              allRelIds.equals(singletonList("A-DependsOn-B")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        List<String> allRelTypes = relSvc.getAllRelationTypeNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        allRelTypes = checked(allRelTypes, String.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        check("List<String> RelationService.getAllRelationTypeNames",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
              allRelTypes.equals(singletonList("DependsOn")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        Map<ObjectName,List<String>> refdMBeans =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            relSvc.getReferencedMBeans("A-DependsOn-B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        check("Map<ObjectName,List<String>> RelationService.getReferencedMBeans",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
              refdMBeans.get(moduleA).equals(singletonList("dependent")) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
              refdMBeans.get(moduleB).equals(singletonList("dependedOn")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        List<ObjectName> roleContents =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            checked(relSvc.getRole("A-DependsOn-B", "dependent"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    ObjectName.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        check("List<ObjectName> RelationService.getRole",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
              roleContents.equals(singletonList(moduleA)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        RoleInfo roleInfoDependent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            relSvc.getRoleInfo("DependsOn", "dependent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        RoleInfo roleInfoDependedOn =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            relSvc.getRoleInfo("DependsOn", "dependedOn");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        List<RoleInfo> expectedRoleInfos =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            Arrays.asList(new RoleInfo[] {roleInfoDependent, roleInfoDependedOn});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        List<RoleInfo> roleInfos =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            checked(relSvc.getRoleInfos("DependsOn"), RoleInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        check("List<RoleInfo> RelationService.getRoleInfos",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
              equalListContents(expectedRoleInfos, roleInfos));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        RelationType relType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            new RelationTypeSupport("DependsOn", dependsOnRoles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        List<RoleInfo> relTypeRoleInfos =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            checked(relType.getRoleInfos(), RoleInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        // Since there's no RoleInfo.equals and since the RelationTypeSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        // constructor clones the RoleInfos passed to it, it's tricky to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        // test equality here so we check type and size and have done with it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        check("List<RoleInfo> RelationType.getRoleInfos",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
              relTypeRoleInfos.size() == 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        MBeanServerNotificationFilter mbsnf =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            new MBeanServerNotificationFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        mbsnf.enableObjectName(moduleA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        check("Vector<ObjectName> MBeanServerNotificationFilter." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
              "getEnabledObjectNames",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
              mbsnf.getEnabledObjectNames().equals(Arrays.asList(moduleA)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        mbsnf.enableAllObjectNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        mbsnf.disableObjectName(moduleB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        check("Vector<ObjectName> MBeanServerNotificationFilter." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
              "getDisabledObjectNames",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
              mbsnf.getDisabledObjectNames().equals(Arrays.asList(moduleB)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        RelationService unusedRelSvc = new RelationService(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        RelationNotification rn1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            new RelationNotification(RelationNotification.RELATION_MBEAN_REMOVAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                                     unusedRelSvc, 0L, 0L, "yo!",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                     "A-DependsOn-B", "DependsOn", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                     singletonList(moduleA));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        List<ObjectName> toUnreg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            checked(rn1.getMBeansToUnregister(), ObjectName.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        check("List<ObjectName> RelationNotification.getMBeansToUnregister",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
              toUnreg.equals(singletonList(moduleA)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        RelationNotification rn2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            new RelationNotification(RelationNotification.RELATION_MBEAN_UPDATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                                     unusedRelSvc, 0L, 0L, "yo!",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                                     "A-DependsOn-B", "DependsOn", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                                     "dependent", singletonList(moduleA),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                                     singletonList(moduleB));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        check("List<ObjectName> RelationNotification.getOldRoleValue",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
              checked(rn2.getOldRoleValue(), ObjectName.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
              .equals(singletonList(moduleB)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        check("List<ObjectName> RelationNotification.getNewRoleValue",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
              checked(rn2.getNewRoleValue(), ObjectName.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
              .equals(singletonList(moduleA)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        ObjectName timerName = new ObjectName(":type=timer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        mbs.registerMBean(new Timer(), timerName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        TimerMBean timer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            MBeanServerInvocationHandler.newProxyInstance(mbs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                                                          timerName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                                          TimerMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                                                          false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        Date doomsday = new Date(Long.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        int timer1 = timer.addNotification("one", "one", null, doomsday);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        int timer2 = timer.addNotification("two", "two", null, doomsday);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        Vector<Integer> idsOne = timer.getNotificationIDs("one");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        check("Vector<Integer> TimerMBean.getNotificationIDs",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
              idsOne.equals(singletonList(timer1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        Vector<Integer> allIds = timer.getAllNotificationIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        check("Vector<Integer> TimerMBean.getAllNotificationIDs",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
              equalListContents(allIds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                                Arrays.asList(new Integer[]{timer1, timer2})));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        // ADD NEW TEST CASES ABOVE THIS COMMENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if (failures == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            System.out.println("All tests passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            System.out.println("TEST FAILURES: " + failures);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        // DO NOT ADD NEW TEST CASES HERE, ADD THEM ABOVE THE PREVIOUS COMMENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    public static interface StupidMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        public int getFive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public static class Stupid implements StupidMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        public int getFive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            return 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public static class Module extends StandardMBean implements StupidMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        public Module() throws NotCompliantMBeanException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            super(StupidMBean.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        public int getFive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            return 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    private static <E> List<E> singletonList(E value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return Collections.singletonList(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    private static <E> Set<E> singleton(E value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        return Collections.singleton(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    private static <K,V> Map<K,V> singletonMap(K key, V value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        return Collections.singletonMap(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    private static <E> List<E> checked(List<E> c, Class<E> type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        List<E> unchecked = new ArrayList<E>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        List<E> checked = Collections.checkedList(unchecked, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        checked.addAll(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        return Collections.checkedList(c, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    private static <E> Set<E> checked(Set<E> c, Class<E> type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        Set<E> unchecked = new HashSet<E>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        Set<E> checked = Collections.checkedSet(unchecked, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        checked.addAll(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        return Collections.checkedSet(c, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    private static <K,V> Map<K,V> checked(Map<K,V> m,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                          Class<K> keyType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                          Class<V> valueType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        Map<K,V> unchecked = new HashMap<K,V>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        Map<K,V> checked = Collections.checkedMap(unchecked, keyType, valueType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        checked.putAll(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        return Collections.checkedMap(m, keyType, valueType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /* The fact that we have to call this method is a clear signal that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * the API says List where it means Set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    private static <E> boolean equalListContents(List<E> l1, List<E> l2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        return new HashSet<E>(l1).equals(new HashSet<E>(l2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    private static void check(String what, boolean cond) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if (cond)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            System.out.println("OK: " + what);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            System.out.println("FAILED: " + what);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            failures++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
}