jdk/test/javax/management/relation/NonArrayListTest.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 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 4848474
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that relation service doesn't require List params to be ArrayList
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Eamonn McManus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @run clean NonArrayListTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run build NonArrayListTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run main NonArrayListTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.relation.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.loading.MLet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class NonArrayListTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        RelationService rs = new RelationService(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        ObjectName rsName = new ObjectName("r:type=RelationService");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        mbs.registerMBean(rs, rsName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        RelationServiceMBean rsProxy = (RelationServiceMBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
            MBeanServerInvocationHandler.newProxyInstance(mbs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                                                          rsName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                                                          RelationServiceMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                                                          false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        ObjectName mlet1Name = new ObjectName("r:type=MLet,instance=1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        ObjectName mlet2Name = new ObjectName("r:type=MLet,instance=2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        mbs.createMBean(MLet.class.getName(), mlet1Name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        mbs.createMBean(MLet.class.getName(), mlet2Name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        RoleInfo leftRoleInfo = new RoleInfo("left", MLet.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        RoleInfo rightRoleInfo = new RoleInfo("right", MLet.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        ArrayList leftRoleValues =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            new ArrayList(Arrays.asList(new ObjectName[] {mlet1Name}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        ArrayList rightRoleValues =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            new ArrayList(Arrays.asList(new ObjectName[] {mlet2Name}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        Role leftRole = new Role("left", leftRoleValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        Role rightRole = new Role("right", rightRoleValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        RelationType leftRightType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            new RelationTypeSupport("leftRight",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                    new RoleInfo[] {leftRoleInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                                    rightRoleInfo});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        RoleList roleList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            new RoleList(new ArrayList(Arrays.asList(new Role[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                leftRole, rightRole,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            })));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        rsProxy.addRelationType(leftRightType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        rsProxy.createRelation("relId", "leftRight", roleList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        ObjectName oname = new ObjectName("a:b=c");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        List onameList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            new Vector(Arrays.asList(new ObjectName[] {oname}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        String testName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        testName = "RelationNotification constructor with only 9 arguments";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            RelationNotification notif =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                new RelationNotification(RelationNotification.RELATION_BASIC_CREATION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                         rs, // theSrcObj
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                         0L, // TheSeqNbr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                         0L, // theTimeStamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                         "theMsg",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                         "theRelId",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                         "theRelTypeName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                         oname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                         onameList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            System.out.println("OK: " + testName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            System.err.println("Exception for " + testName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        testName = "RelationNotification constructor with 11 arguments";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            RelationNotification notif =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                new RelationNotification(RelationNotification.RELATION_BASIC_UPDATE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                                         rs, // theSrcObj
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                         0L, // TheSeqNbr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                         0L, // theTimeStamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                         "theMsg",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                         "theRelId",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                         "theRelTypeName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                         oname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                         "theRoleName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                         onameList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                         onameList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            System.out.println("OK: " + testName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            System.err.println("Exception for " + testName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        testName = "RelationService.sendNotification";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            rsProxy.sendRoleUpdateNotification("relId", leftRole, onameList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            System.out.println("OK: " + testName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            System.err.println("Exception for " + testName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        testName = "RelationService.updateRoleMap";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            rsProxy.updateRoleMap("relId", leftRole, onameList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            System.out.println("OK: " + testName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            System.err.println("Exception for " + testName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (ok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            System.out.println("Tests passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            System.err.println("SOME TESTS FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
}