Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/relation/NonArrayListTest.java
38839 views
/*1* Copyright (c) 2003, 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* @run clean NonArrayListTest29* @run build NonArrayListTest30* @run main NonArrayListTest31*/3233import java.util.*;34import javax.management.*;35import javax.management.relation.*;36import javax.management.loading.MLet;3738public class NonArrayListTest {39public static void main(String[] args) throws Exception {40MBeanServer mbs = MBeanServerFactory.createMBeanServer();41RelationService rs = new RelationService(true);42ObjectName rsName = new ObjectName("r:type=RelationService");43mbs.registerMBean(rs, rsName);44RelationServiceMBean rsProxy = (RelationServiceMBean)45MBeanServerInvocationHandler.newProxyInstance(mbs,46rsName,47RelationServiceMBean.class,48false);4950ObjectName mlet1Name = new ObjectName("r:type=MLet,instance=1");51ObjectName mlet2Name = new ObjectName("r:type=MLet,instance=2");52mbs.createMBean(MLet.class.getName(), mlet1Name);53mbs.createMBean(MLet.class.getName(), mlet2Name);5455RoleInfo leftRoleInfo = new RoleInfo("left", MLet.class.getName());56RoleInfo rightRoleInfo = new RoleInfo("right", MLet.class.getName());5758ArrayList leftRoleValues =59new ArrayList(Arrays.asList(new ObjectName[] {mlet1Name}));60ArrayList rightRoleValues =61new ArrayList(Arrays.asList(new ObjectName[] {mlet2Name}));62Role leftRole = new Role("left", leftRoleValues);63Role rightRole = new Role("right", rightRoleValues);6465RelationType leftRightType =66new RelationTypeSupport("leftRight",67new RoleInfo[] {leftRoleInfo,68rightRoleInfo});69RoleList roleList =70new RoleList(new ArrayList(Arrays.asList(new Role[] {71leftRole, rightRole,72})));73rsProxy.addRelationType(leftRightType);74rsProxy.createRelation("relId", "leftRight", roleList);7576boolean ok = true;77ObjectName oname = new ObjectName("a:b=c");78List onameList =79new Vector(Arrays.asList(new ObjectName[] {oname}));8081String testName;8283testName = "RelationNotification constructor with only 9 arguments";84try {85RelationNotification notif =86new RelationNotification(RelationNotification.RELATION_BASIC_CREATION,87rs, // theSrcObj880L, // TheSeqNbr890L, // theTimeStamp90"theMsg",91"theRelId",92"theRelTypeName",93oname,94onameList);95System.out.println("OK: " + testName);96} catch (Exception e) {97System.err.println("Exception for " + testName);98e.printStackTrace();99ok = false;100}101102testName = "RelationNotification constructor with 11 arguments";103try {104RelationNotification notif =105new RelationNotification(RelationNotification.RELATION_BASIC_UPDATE,106rs, // theSrcObj1070L, // TheSeqNbr1080L, // theTimeStamp109"theMsg",110"theRelId",111"theRelTypeName",112oname,113"theRoleName",114onameList,115onameList);116System.out.println("OK: " + testName);117} catch (Exception e) {118System.err.println("Exception for " + testName);119e.printStackTrace();120ok = false;121}122123testName = "RelationService.sendNotification";124try {125rsProxy.sendRoleUpdateNotification("relId", leftRole, onameList);126System.out.println("OK: " + testName);127} catch (Exception e) {128System.err.println("Exception for " + testName);129e.printStackTrace();130ok = false;131}132133testName = "RelationService.updateRoleMap";134try {135rsProxy.updateRoleMap("relId", leftRole, onameList);136System.out.println("OK: " + testName);137} catch (Exception e) {138System.err.println("Exception for " + testName);139e.printStackTrace();140ok = false;141}142143if (ok)144System.out.println("Tests passed");145else146System.err.println("SOME TESTS FAILED");147}148}149150151