Path: blob/master/test/jdk/javax/management/relation/NonArrayListTest.java
41149 views
/*1* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 484847426* @summary Test that relation service doesn't require List params to be ArrayList27* @author Eamonn McManus28*29* @run clean NonArrayListTest30* @run build NonArrayListTest31* @run main NonArrayListTest32*/3334import java.util.*;35import javax.management.*;36import javax.management.relation.*;37import javax.management.loading.MLet;3839public class NonArrayListTest {40public static void main(String[] args) throws Exception {41MBeanServer mbs = MBeanServerFactory.createMBeanServer();42RelationService rs = new RelationService(true);43ObjectName rsName = new ObjectName("r:type=RelationService");44mbs.registerMBean(rs, rsName);45RelationServiceMBean rsProxy = (RelationServiceMBean)46MBeanServerInvocationHandler.newProxyInstance(mbs,47rsName,48RelationServiceMBean.class,49false);5051ObjectName mlet1Name = new ObjectName("r:type=MLet,instance=1");52ObjectName mlet2Name = new ObjectName("r:type=MLet,instance=2");53mbs.createMBean(MLet.class.getName(), mlet1Name);54mbs.createMBean(MLet.class.getName(), mlet2Name);5556RoleInfo leftRoleInfo = new RoleInfo("left", MLet.class.getName());57RoleInfo rightRoleInfo = new RoleInfo("right", MLet.class.getName());5859ArrayList leftRoleValues =60new ArrayList(Arrays.asList(new ObjectName[] {mlet1Name}));61ArrayList rightRoleValues =62new ArrayList(Arrays.asList(new ObjectName[] {mlet2Name}));63Role leftRole = new Role("left", leftRoleValues);64Role rightRole = new Role("right", rightRoleValues);6566RelationType leftRightType =67new RelationTypeSupport("leftRight",68new RoleInfo[] {leftRoleInfo,69rightRoleInfo});70RoleList roleList =71new RoleList(new ArrayList(Arrays.asList(new Role[] {72leftRole, rightRole,73})));74rsProxy.addRelationType(leftRightType);75rsProxy.createRelation("relId", "leftRight", roleList);7677boolean ok = true;78ObjectName oname = new ObjectName("a:b=c");79List onameList =80new Vector(Arrays.asList(new ObjectName[] {oname}));8182String testName;8384testName = "RelationNotification constructor with only 9 arguments";85try {86RelationNotification notif =87new RelationNotification(RelationNotification.RELATION_BASIC_CREATION,88rs, // theSrcObj890L, // TheSeqNbr900L, // theTimeStamp91"theMsg",92"theRelId",93"theRelTypeName",94oname,95onameList);96System.out.println("OK: " + testName);97} catch (Exception e) {98System.err.println("Exception for " + testName);99e.printStackTrace();100ok = false;101}102103testName = "RelationNotification constructor with 11 arguments";104try {105RelationNotification notif =106new RelationNotification(RelationNotification.RELATION_BASIC_UPDATE,107rs, // theSrcObj1080L, // TheSeqNbr1090L, // theTimeStamp110"theMsg",111"theRelId",112"theRelTypeName",113oname,114"theRoleName",115onameList,116onameList);117System.out.println("OK: " + testName);118} catch (Exception e) {119System.err.println("Exception for " + testName);120e.printStackTrace();121ok = false;122}123124testName = "RelationService.sendNotification";125try {126rsProxy.sendRoleUpdateNotification("relId", leftRole, onameList);127System.out.println("OK: " + testName);128} catch (Exception e) {129System.err.println("Exception for " + testName);130e.printStackTrace();131ok = false;132}133134testName = "RelationService.updateRoleMap";135try {136rsProxy.updateRoleMap("relId", leftRole, onameList);137System.out.println("OK: " + testName);138} catch (Exception e) {139System.err.println("Exception for " + testName);140e.printStackTrace();141ok = false;142}143144if (ok)145System.out.println("Tests passed");146else147System.err.println("SOME TESTS FAILED");148}149}150151152