jdk/test/javax/management/namespace/NamespaceCreationTest.java
author dfuchs
Wed, 10 Sep 2008 16:27:13 +0200
changeset 1227 4546977d0d66
parent 1156 bbc2d15aaf7a
permissions -rw-r--r--
6746754: jmx namespace: test for leading separator missing 6669137: RFE: InstanceNotFoundException should have a constructor that takes an ObjectName 6746796: jmx namespaces: Several tests are missing an @bug or @run keyword Summary: Note on 6669137: first implementation of 6669137 was actually pushed with 5072476 - here we only have a small update and a test case. Also re-fixes 6737133: Compilation failure of test/javax/management/eventService/LeaseManagerDeadlockTest.java which had failed. Reviewed-by: emcmanus, yjoan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     1
/*
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     4
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     8
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    14
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    18
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    21
 * have any questions.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    22
 */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    23
/*
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    24
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    25
 * @test NamespaceCreationTest.java
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    26
 * @summary General JMXNamespace test.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    27
 * @author Daniel Fuchs
1227
4546977d0d66 6746754: jmx namespace: test for leading separator missing
dfuchs
parents: 1156
diff changeset
    28
 * @bug 5072476
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    29
 * @run clean NamespaceCreationTest Wombat WombatMBean
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    30
 * @run build NamespaceCreationTest Wombat WombatMBean
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    31
 * @run main NamespaceCreationTest
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    32
 */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    33
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    34
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    35
import java.util.Collections;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    36
import java.util.Map;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    37
import javax.management.MBeanRegistration;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    38
import javax.management.MBeanRegistrationException;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    39
import javax.management.MBeanServer;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    40
import javax.management.MBeanServerFactory;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    41
import javax.management.ObjectInstance;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    42
import javax.management.ObjectName;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    43
import javax.management.RuntimeMBeanException;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    44
import javax.management.namespace.JMXNamespace;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    45
import javax.management.namespace.JMXNamespaces;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    46
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    47
/**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    48
 * Test simple creation/registration of namespace.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    49
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    50
 */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    51
public class NamespaceCreationTest {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    52
    private static Map<String,Object> emptyEnvMap() {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    53
        return Collections.emptyMap();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    54
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    55
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    56
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    57
    public static class LocalNamespace extends JMXNamespace {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    58
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    59
        public LocalNamespace() {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    60
            super(MBeanServerFactory.newMBeanServer());
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    61
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    62
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    63
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    64
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    65
    private static MBeanServer newMBeanServer() {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    66
        return MBeanServerFactory.newMBeanServer();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    67
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    68
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    69
    public static interface ThingMBean {}
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    70
    public static class Thing implements ThingMBean, MBeanRegistration {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    71
        public ObjectName preRegister(MBeanServer server, ObjectName name)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    72
                throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    73
            if (name == null) return new ObjectName(":type=Thing");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    74
            else return name;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    75
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    76
        public void postRegister(Boolean registrationDone) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    77
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    78
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    79
        public void preDeregister() throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    80
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    81
        public void postDeregister() {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    82
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    83
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    84
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    85
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    86
     * Test that it is possible to create a dummy MBean with a null
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    87
     * ObjectName - this is just a sanity check - as there are already
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    88
     * other JMX tests that check that.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    89
     *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    90
     * @throws java.lang.Exception
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    91
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    92
    public static void testCreateWithNull() throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    93
        final MBeanServer server = newMBeanServer();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    94
        final ObjectInstance oi = server.registerMBean(new Thing(),null);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    95
        server.unregisterMBean(oi.getObjectName());
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    96
        System.out.println("testCreateWithNull PASSED");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    97
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    98
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    99
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   100
     * Check that we can register a JMXNamespace MBean, using its standard
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   101
     * ObjectName.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   102
     * @throws java.lang.Exception
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   103
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   104
    public static void testGoodObjectName() throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   105
        MBeanServer server = newMBeanServer();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   106
        final ObjectName name =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   107
                JMXNamespaces.getNamespaceObjectName("gloups");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   108
        final ObjectInstance oi =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   109
                server.registerMBean(new LocalNamespace(),name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   110
        System.out.println("Succesfully registered namespace: "+name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   111
        try {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   112
            if (! name.equals(oi.getObjectName()))
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   113
                throw new RuntimeException("testGoodObjectName: TEST failed: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   114
                        "namespace registered as: "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   115
                    oi.getObjectName()+" expected: "+name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   116
        } finally {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   117
            server.unregisterMBean(oi.getObjectName());
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   118
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   119
        System.out.println("Succesfully unregistered namespace: "+name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   120
        System.out.println("testGoodObjectName PASSED");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   121
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   122
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   123
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   124
     * Check that we cannot register a JMXNamespace MBean, if we don't use
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   125
     * its standard ObjectName.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   126
     * @throws java.lang.Exception
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   127
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   128
    public static void testBadObjectName() throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   129
        MBeanServer server = newMBeanServer();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   130
        Throwable exp = null;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   131
        final ObjectName name = new ObjectName("d:k=v");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   132
        try {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   133
            server.registerMBean(new LocalNamespace(),name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   134
            System.out.println("testBadObjectName: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   135
                    "Error: MBean registered, no exception thrown.");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   136
        } catch(RuntimeMBeanException x) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   137
            exp = x.getCause();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   138
        } catch(Exception x) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   139
            throw new RuntimeException("testBadObjectName: TEST failed: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   140
                    "expected RuntimeMBeanException - got "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   141
                    x);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   142
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   143
        if (exp == null)  server.unregisterMBean(name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   144
        if (exp == null)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   145
            throw new RuntimeException("testBadObjectName: TEST failed: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   146
                    "expected IllegalArgumentException - got none");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   147
        if (!(exp instanceof IllegalArgumentException))
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   148
            throw new RuntimeException("testBadObjectName: TEST failed: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   149
                    "expected IllegalArgumentException - got "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   150
                    exp.toString(),exp);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   151
        System.out.println("Got expected exception: "+exp);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   152
        System.out.println("testBadObjectName PASSED");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   153
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   154
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   155
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   156
     * Check that we cannot register a Wombat MBean in a namespace that does
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   157
     * not exists.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   158
     *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   159
     * @throws java.lang.Exception
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   160
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   161
    public static void testBadNamespace() throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   162
        MBeanServer server = newMBeanServer();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   163
        Throwable exp = null;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   164
        final ObjectName name = new ObjectName("glips//d:k=v");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   165
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   166
        try {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   167
            server.registerMBean(new Wombat(),name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   168
            System.out.println("testBadNamespace: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   169
                    "Error: MBean registered, no exception thrown.");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   170
        } catch(MBeanRegistrationException x) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   171
            exp = x.getCause();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   172
        } catch(Exception x) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   173
            throw new RuntimeException("testBadNamespace: TEST failed: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   174
                    "expected MBeanRegistrationException - got "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   175
                    x);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   176
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   177
        if (exp == null)  server.unregisterMBean(name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   178
        if (exp == null)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   179
            throw new RuntimeException("testBadNamespace: TEST failed: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   180
                    "expected IllegalArgumentException - got none");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   181
        if (!(exp instanceof IllegalArgumentException))
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   182
            throw new RuntimeException("testBadNamespace: TEST failed: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   183
                    "expected IllegalArgumentException - got "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   184
                    exp.toString(),exp);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   185
        System.out.println("Got expected exception: "+exp);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   186
        System.out.println("testBadNamespace PASSED");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   187
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   188
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   189
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   190
     * Check that we cannot register a Wombat MBean with a domain name
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   191
     * that ends with //. This is reserved for namespaces.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   192
     *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   193
     * @throws java.lang.Exception
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   194
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   195
    public static void testBadDomain() throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   196
        MBeanServer server = newMBeanServer();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   197
        Throwable exp = null;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   198
        final ObjectName name = new ObjectName("glups//:k=v");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   199
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   200
        try {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   201
            server.registerMBean(new Wombat(),name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   202
            System.out.println("testBadDomain: Error: MBean registered, no exception thrown.");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   203
        } catch(RuntimeMBeanException x) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   204
            exp = x.getCause();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   205
        } catch(Exception x) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   206
            throw new RuntimeException("testBadDomain: TEST failed: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   207
                    "expected RuntimeMBeanException - got "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   208
                    x);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   209
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   210
        if (exp == null)  server.unregisterMBean(name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   211
        if (exp == null)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   212
            throw new RuntimeException("testBadDomain: TEST failed: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   213
                    "expected IllegalArgumentException - got none");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   214
        if (!(exp instanceof IllegalArgumentException))
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   215
            throw new RuntimeException("testBadDomain: TEST failed: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   216
                    "expected IllegalArgumentException - got "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   217
                    exp.toString(),exp);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   218
        System.out.println("Got expected exception: "+exp);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   219
        System.out.println("testBadDomain PASSED");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   220
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   221
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   222
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   223
     * Check that we cannot register a Wombat MBean as if it were a
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   224
     * JMXNamespace. Only JMXNamespace MBeans can have JMX Namespace names.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   225
     * @throws java.lang.Exception
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   226
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   227
    public static void testBadClassName() throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   228
        MBeanServer server = newMBeanServer();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   229
        Throwable exp = null;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   230
        final ObjectName name =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   231
                JMXNamespaces.getNamespaceObjectName("glops");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   232
        try {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   233
            server.registerMBean(new Wombat(),name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   234
            System.out.println("testBadClassName: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   235
                    "Error: MBean registered, no exception thrown.");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   236
        } catch(RuntimeMBeanException x) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   237
            exp = x.getCause();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   238
        } catch(Exception x) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   239
            throw new RuntimeException("testBadClassName: TEST failed: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   240
                    "expected RuntimeMBeanException - got "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   241
                    x);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   242
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   243
        if (exp == null)  server.unregisterMBean(name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   244
        if (exp == null)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   245
            throw new RuntimeException("testBadClassName: TEST failed: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   246
                    "expected IllegalArgumentException - got none");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   247
        if (!(exp instanceof IllegalArgumentException))
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   248
            throw new RuntimeException("testBadClassName: TEST failed: " +
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   249
                    "expected IllegalArgumentException - got "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   250
                    exp.toString(),exp);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   251
        System.out.println("Got expected exception: "+exp);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   252
        System.out.println("testBadClassName PASSED");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   253
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   254
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   255
    public static void main(String... args) throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   256
        testCreateWithNull();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   257
        testGoodObjectName();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   258
        testBadObjectName();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   259
        testBadNamespace();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   260
        testBadDomain();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   261
        testBadClassName();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   262
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   263
}