869N/A/*
869N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
869N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
869N/A *
869N/A * This code is free software; you can redistribute it and/or modify it
869N/A * under the terms of the GNU General Public License version 2 only, as
869N/A * published by the Free Software Foundation.
869N/A *
869N/A * This code is distributed in the hope that it will be useful, but WITHOUT
869N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
869N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
869N/A * version 2 for more details (a copy is included in the LICENSE file that
869N/A * accompanied this code).
869N/A *
869N/A * You should have received a copy of the GNU General Public License version
869N/A * 2 along with this work; if not, write to the Free Software Foundation,
869N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
873N/A *
869N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
869N/A * or visit www.oracle.com if you need additional information or have any
869N/A * questions.
869N/A */
869N/A
869N/A/*
869N/A * @test
0N/A * @bug 4848474
0N/A * @summary Test that relation service doesn't require List params to be ArrayList
0N/A * @author Eamonn McManus
0N/A * @run clean NonArrayListTest
869N/A * @run build NonArrayListTest
0N/A * @run main NonArrayListTest
0N/A */
0N/A
869N/Aimport java.util.*;
0N/Aimport javax.management.*;
869N/Aimport javax.management.relation.*;
0N/Aimport javax.management.loading.MLet;
869N/A
869N/Apublic class NonArrayListTest {
869N/A public static void main(String[] args) throws Exception {
0N/A MBeanServer mbs = MBeanServerFactory.createMBeanServer();
869N/A RelationService rs = new RelationService(true);
48N/A ObjectName rsName = new ObjectName("r:type=RelationService");
869N/A mbs.registerMBean(rs, rsName);
0N/A RelationServiceMBean rsProxy = (RelationServiceMBean)
869N/A MBeanServerInvocationHandler.newProxyInstance(mbs,
716N/A rsName,
869N/A RelationServiceMBean.class,
0N/A false);
0N/A
869N/A ObjectName mlet1Name = new ObjectName("r:type=MLet,instance=1");
868N/A ObjectName mlet2Name = new ObjectName("r:type=MLet,instance=2");
983N/A mbs.createMBean(MLet.class.getName(), mlet1Name);
1004N/A mbs.createMBean(MLet.class.getName(), mlet2Name);
1007N/A
1378N/A RoleInfo leftRoleInfo = new RoleInfo("left", MLet.class.getName());
1411N/A RoleInfo rightRoleInfo = new RoleInfo("right", MLet.class.getName());
1503N/A
869N/A ArrayList leftRoleValues =
1774N/A new ArrayList(Arrays.asList(new ObjectName[] {mlet1Name}));
1004N/A ArrayList rightRoleValues =
0N/A new ArrayList(Arrays.asList(new ObjectName[] {mlet2Name}));
0N/A Role leftRole = new Role("left", leftRoleValues);
869N/A Role rightRole = new Role("right", rightRoleValues);
868N/A
0N/A RelationType leftRightType =
0N/A new RelationTypeSupport("leftRight",
65N/A new RoleInfo[] {leftRoleInfo,
869N/A rightRoleInfo});
868N/A RoleList roleList =
65N/A new RoleList(new ArrayList(Arrays.asList(new Role[] {
869N/A leftRole, rightRole,
65N/A })));
65N/A rsProxy.addRelationType(leftRightType);
65N/A rsProxy.createRelation("relId", "leftRight", roleList);
65N/A
65N/A boolean ok = true;
65N/A ObjectName oname = new ObjectName("a:b=c");
65N/A List onameList =
65N/A new Vector(Arrays.asList(new ObjectName[] {oname}));
65N/A
65N/A String testName;
65N/A
65N/A testName = "RelationNotification constructor with only 9 arguments";
65N/A try {
65N/A RelationNotification notif =
65N/A new RelationNotification(RelationNotification.RELATION_BASIC_CREATION,
0N/A rs, // theSrcObj
869N/A 0L, // TheSeqNbr
868N/A 0L, // theTimeStamp
0N/A "theMsg",
0N/A "theRelId",
0N/A "theRelTypeName",
0N/A oname,
0N/A onameList);
0N/A System.out.println("OK: " + testName);
0N/A } catch (Exception e) {
1501N/A System.err.println("Exception for " + testName);
0N/A e.printStackTrace();
0N/A ok = false;
869N/A }
868N/A
0N/A testName = "RelationNotification constructor with 11 arguments";
0N/A try {
869N/A RelationNotification notif =
0N/A new RelationNotification(RelationNotification.RELATION_BASIC_UPDATE,
0N/A rs, // theSrcObj
869N/A 0L, // TheSeqNbr
868N/A 0L, // theTimeStamp
869N/A "theMsg",
869N/A "theRelId",
868N/A "theRelTypeName",
868N/A oname,
869N/A "theRoleName",
869N/A onameList,
0N/A onameList);
0N/A System.out.println("OK: " + testName);
1790N/A } catch (Exception e) {
48N/A System.err.println("Exception for " + testName);
869N/A e.printStackTrace();
869N/A ok = false;
869N/A }
868N/A
869N/A testName = "RelationService.sendNotification";
868N/A try {
869N/A rsProxy.sendRoleUpdateNotification("relId", leftRole, onameList);
1155N/A System.out.println("OK: " + testName);
1155N/A } catch (Exception e) {
1155N/A System.err.println("Exception for " + testName);
1155N/A e.printStackTrace();
1155N/A ok = false;
1155N/A }
1155N/A
1155N/A testName = "RelationService.updateRoleMap";
1155N/A try {
1155N/A rsProxy.updateRoleMap("relId", leftRole, onameList);
1155N/A System.out.println("OK: " + testName);
1155N/A } catch (Exception e) {
1155N/A System.err.println("Exception for " + testName);
1155N/A e.printStackTrace();
1155N/A ok = false;
0N/A }
0N/A
869N/A if (ok)
868N/A System.out.println("Tests passed");
0N/A else
0N/A System.err.println("SOME TESTS FAILED");
848N/A }
848N/A}
848N/A