1 /* 2 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4848474 27 * @summary Test that relation service doesn't require List params to be ArrayList 28 * @author Eamonn McManus 29 * @run clean NonArrayListTest 30 * @run build NonArrayListTest 31 * @run main NonArrayListTest 32 */ 33 34 import java.util.*; 35 import javax.management.*; 36 import javax.management.relation.*; 37 import javax.management.loading.MLet; 38 39 public class NonArrayListTest { 40 public static void main(String[] args) throws Exception { 41 MBeanServer mbs = MBeanServerFactory.createMBeanServer(); 42 RelationService rs = new RelationService(true); 43 ObjectName rsName = new ObjectName("r:type=RelationService"); 44 mbs.registerMBean(rs, rsName); 45 RelationServiceMBean rsProxy = (RelationServiceMBean) 46 MBeanServerInvocationHandler.newProxyInstance(mbs, 47 rsName, 48 RelationServiceMBean.class, 49 false); 50 51 ObjectName mlet1Name = new ObjectName("r:type=MLet,instance=1"); 52 ObjectName mlet2Name = new ObjectName("r:type=MLet,instance=2"); 53 mbs.createMBean(MLet.class.getName(), mlet1Name); 54 mbs.createMBean(MLet.class.getName(), mlet2Name); 55 56 RoleInfo leftRoleInfo = new RoleInfo("left", MLet.class.getName()); 57 RoleInfo rightRoleInfo = new RoleInfo("right", MLet.class.getName()); 58 59 ArrayList leftRoleValues = 60 new ArrayList(Arrays.asList(new ObjectName[] {mlet1Name})); 61 ArrayList rightRoleValues = 62 new ArrayList(Arrays.asList(new ObjectName[] {mlet2Name})); 63 Role leftRole = new Role("left", leftRoleValues); 64 Role rightRole = new Role("right", rightRoleValues); 65 66 RelationType leftRightType = 67 new RelationTypeSupport("leftRight", 68 new RoleInfo[] {leftRoleInfo, 69 rightRoleInfo}); 70 RoleList roleList = 71 new RoleList(new ArrayList(Arrays.asList(new Role[] { 72 leftRole, rightRole, 73 }))); 74 rsProxy.addRelationType(leftRightType); 75 rsProxy.createRelation("relId", "leftRight", roleList); 76 77 boolean ok = true; 78 ObjectName oname = new ObjectName("a:b=c"); 79 List onameList = 80 new Vector(Arrays.asList(new ObjectName[] {oname})); 81 82 String testName; 83 84 testName = "RelationNotification constructor with only 9 arguments"; 85 try { 86 RelationNotification notif = 87 new RelationNotification(RelationNotification.RELATION_BASIC_CREATION, 88 rs, // theSrcObj 89 0L, // TheSeqNbr 90 0L, // theTimeStamp 91 "theMsg", 92 "theRelId", 93 "theRelTypeName", 94 oname, 95 onameList); 96 System.out.println("OK: " + testName); 97 } catch (Exception e) { 98 System.err.println("Exception for " + testName); 99 e.printStackTrace(); 100 ok = false; 101 } 102 103 testName = "RelationNotification constructor with 11 arguments"; 104 try { 105 RelationNotification notif = 106 new RelationNotification(RelationNotification.RELATION_BASIC_UPDATE, 107 rs, // theSrcObj 108 0L, // TheSeqNbr 109 0L, // theTimeStamp 110 "theMsg", 111 "theRelId", 112 "theRelTypeName", 113 oname, 114 "theRoleName", 115 onameList, 116 onameList); 117 System.out.println("OK: " + testName); 118 } catch (Exception e) { 119 System.err.println("Exception for " + testName); 120 e.printStackTrace(); 121 ok = false; 122 } 123 124 testName = "RelationService.sendNotification"; 125 try { 126 rsProxy.sendRoleUpdateNotification("relId", leftRole, onameList); 127 System.out.println("OK: " + testName); 128 } catch (Exception e) { 129 System.err.println("Exception for " + testName); 130 e.printStackTrace(); 131 ok = false; 132 } 133 134 testName = "RelationService.updateRoleMap"; 135 try { 136 rsProxy.updateRoleMap("relId", leftRole, onameList); 137 System.out.println("OK: " + testName); 138 } catch (Exception e) { 139 System.err.println("Exception for " + testName); 140 e.printStackTrace(); 141 ok = false; 142 } 143 144 if (ok) 145 System.out.println("Tests passed"); 146 else 147 System.err.println("SOME TESTS FAILED"); 148 } 149 }