KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > compliance > relation > RelationServiceTestCase


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.jmx.compliance.relation;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import javax.management.InstanceNotFoundException JavaDoc;
32 import javax.management.MBeanNotificationInfo JavaDoc;
33 import javax.management.MBeanServer JavaDoc;
34 import javax.management.MBeanServerFactory JavaDoc;
35 import javax.management.Notification JavaDoc;
36 import javax.management.NotificationListener JavaDoc;
37 import javax.management.ObjectName JavaDoc;
38 import javax.management.relation.InvalidRelationIdException JavaDoc;
39 import javax.management.relation.InvalidRelationServiceException JavaDoc;
40 import javax.management.relation.InvalidRelationTypeException JavaDoc;
41 import javax.management.relation.InvalidRoleValueException JavaDoc;
42 import javax.management.relation.RelationNotFoundException JavaDoc;
43 import javax.management.relation.RelationNotification JavaDoc;
44 import javax.management.relation.RelationService JavaDoc;
45 import javax.management.relation.RelationServiceNotRegisteredException JavaDoc;
46 import javax.management.relation.RelationSupport JavaDoc;
47 import javax.management.relation.RelationTypeNotFoundException JavaDoc;
48 import javax.management.relation.RelationTypeSupport JavaDoc;
49 import javax.management.relation.Role JavaDoc;
50 import javax.management.relation.RoleInfo JavaDoc;
51 import javax.management.relation.RoleInfoNotFoundException JavaDoc;
52 import javax.management.relation.RoleList JavaDoc;
53 import javax.management.relation.RoleNotFoundException JavaDoc;
54 import javax.management.relation.RoleResult JavaDoc;
55 import javax.management.relation.RoleStatus JavaDoc;
56 import javax.management.relation.RoleUnresolved JavaDoc;
57 import javax.management.relation.RoleUnresolvedList JavaDoc;
58
59 import junit.framework.TestCase;
60
61 import org.jboss.test.jmx.compliance.relation.support.Trivial;
62
63 /**
64  * Relation Service tests
65  *
66  * //TODO test internal relations
67  * //TODO test relations as mbeans in roles
68  * //TODO test multiple relation services (avoid future mods adding static data)
69  *
70  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
71  */

72 public class RelationServiceTestCase
73    extends TestCase
74 {
75    // Constants -----------------------------------------------------------------
76

77    // Attributes ----------------------------------------------------------------
78

79    HashMap JavaDoc services = new HashMap JavaDoc();
80
81    RoleList JavaDoc rolesA;
82    HashMap JavaDoc roleInfosA = new HashMap JavaDoc();
83    Role JavaDoc roleB1;
84    Role JavaDoc roleB2;
85    RoleList JavaDoc rolesB;
86    HashMap JavaDoc roleInfosB = new HashMap JavaDoc();
87    Role JavaDoc roleC1;
88    Role JavaDoc roleC2;
89    RoleList JavaDoc rolesC;
90    HashMap JavaDoc roleInfosC = new HashMap JavaDoc();
91    Role JavaDoc roleCX1;
92    Role JavaDoc roleCX2;
93    RoleList JavaDoc rolesCX;
94    HashMap JavaDoc roleInfosCX = new HashMap JavaDoc();
95    Role JavaDoc roleCZ2;
96    RoleList JavaDoc rolesCZ;
97    HashMap JavaDoc roleInfosCZ = new HashMap JavaDoc();
98    Role JavaDoc roleCZZ;
99    RoleList JavaDoc rolesCZZ;
100    HashMap JavaDoc roleInfosCZZ = new HashMap JavaDoc();
101    Role JavaDoc roleCZZZ;
102    RoleList JavaDoc rolesCZZZ;
103    HashMap JavaDoc roleInfosCZZZ = new HashMap JavaDoc();
104
105    // Constructor ---------------------------------------------------------------
106

107    /**
108     * Construct the test
109     */

110    public RelationServiceTestCase(String JavaDoc s)
111    {
112       super(s);
113    }
114
115    // Tests ---------------------------------------------------------------------
116

117    /**
118     * Test the constructor
119     */

120    public void testConstructor() throws Exception JavaDoc
121    {
122       RelationService JavaDoc rs = null;
123       rs = new RelationService JavaDoc(true);
124       assertEquals(true, rs.getPurgeFlag());
125
126       rs = new RelationService JavaDoc(false);
127       assertEquals(false, rs.getPurgeFlag());
128    }
129
130    /**
131     * Test add a relation
132     */

133    public void testAddRelation() throws Exception JavaDoc
134    {
135       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
136       try
137       {
138          ObjectName JavaDoc service = createRelationService("test:type=service", server);
139          createRelationTypeB(service);
140          createRolesB(server);
141          RelationSupport JavaDoc support = null;
142          ObjectName JavaDoc rsupp = null;
143          String JavaDoc result = null;
144          Listener JavaDoc listener = new Listener JavaDoc(RelationNotification.RELATION_MBEAN_CREATION);
145          RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
146          server.addNotificationListener(service, listener, null, null);
147          support = new RelationSupport JavaDoc("id", service, server, "relationTypeB",
148                                        rolesB);
149          rsupp = new ObjectName JavaDoc("test:add=relation");
150          server.registerMBean(support, rsupp);
151          rs.addRelation(rsupp);
152          result = rs.isRelation(rsupp);
153          assertEquals("id", result);
154          listener.check(1);
155       }
156       finally
157       {
158          MBeanServerFactory.releaseMBeanServer(server);
159       }
160    }
161
162    /**
163     * Test add a relation errors
164     */

165    public void testAddRelationErrors() throws Exception JavaDoc
166    {
167       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
168       try
169       {
170          ObjectName JavaDoc service = createRelationService("test:type=service", null);
171          RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
172          createRelationTypeB(service);
173          createRolesB(server);
174          RelationSupport JavaDoc support = null;
175          ObjectName JavaDoc name = null;
176          support = new RelationSupport JavaDoc("id", service, server, "relationTypeB",
177                                           rolesB);
178          name = new ObjectName JavaDoc("test:type=relation");
179          server.registerMBean(support, name);
180
181          boolean caught = false;
182          try
183          {
184             rs.addRelation(null);
185          }
186          catch (IllegalArgumentException JavaDoc e)
187          {
188             caught = true;
189          }
190          if (caught == false)
191             fail("addRelation allows null relation");
192
193          caught = false;
194          try
195          {
196             rs.addRelation(name);
197          }
198          catch (RelationServiceNotRegisteredException JavaDoc e)
199          {
200             caught = true;
201          }
202          if (caught == false)
203             fail("addRelation allowed when not registered");
204
205          ObjectName JavaDoc badRelation = null;
206          server.registerMBean(rs, service);
207          badRelation = new ObjectName JavaDoc("test:type=bad");
208          server.registerMBean(new Trivial(), badRelation);
209
210          caught = false;
211          try
212          {
213             rs.addRelation(badRelation);
214          }
215          catch (NoSuchMethodException JavaDoc e)
216          {
217             caught = true;
218          }
219          if (caught == false)
220             fail("addRelation allowed when not a relation");
221
222          caught = false;
223          try
224          {
225             rs.addRelation(name);
226             rs.addRelation(name);
227          }
228          catch (InvalidRelationIdException JavaDoc e)
229          {
230             caught = true;
231          }
232          if (caught == false)
233             fail("addRelation allows duplicate relation ids");
234
235          rs.removeRelation("id");
236          server.unregisterMBean(name);
237
238          caught = false;
239          try
240          {
241             rs.addRelation(name);
242          }
243          catch (InstanceNotFoundException JavaDoc e)
244          {
245             caught = true;
246          }
247          if (caught == false)
248             fail("addRelation allows unregistered relation");
249
250          ObjectName JavaDoc service2 = createRelationService("test:type=service2", null);
251          createRelationTypeB(service2);
252          ObjectName JavaDoc name2 = null;
253          support = new RelationSupport JavaDoc("id", service2, server, "relationTypeB",
254                                           rolesB);
255          name2 = new ObjectName JavaDoc("test:type=relation2");
256          server.registerMBean(support, name2);
257
258          caught = false;
259          try
260          {
261             rs.addRelation(name2);
262          }
263          catch (InvalidRelationServiceException JavaDoc e)
264          {
265             caught = true;
266          }
267          if (caught == false)
268             fail("addRelation allows registration in the wrong relation service");
269
270          support = new RelationSupport JavaDoc("id", service, server, "relationTypeX",
271                                           rolesB);
272          name = new ObjectName JavaDoc("test:type=relationX");
273          server.registerMBean(support, name);
274
275          caught = false;
276          try
277          {
278             rs.addRelation(name);
279          }
280          catch (RelationTypeNotFoundException JavaDoc e)
281          {
282             caught = true;
283          }
284          if (caught == false)
285             fail("addRelation allows registration with invalid relation type");
286
287          createRelationTypeC(service);
288          createRolesC(server);
289          createRolesCZ(server);
290          support = new RelationSupport JavaDoc("idC", service, server, "relationTypeB",
291                                           rolesC);
292          name = new ObjectName JavaDoc("test:type=relationC");
293          server.registerMBean(support, name);
294
295          caught = false;
296          try
297          {
298             rs.addRelation(name);
299          }
300          catch (RoleNotFoundException JavaDoc e)
301          {
302             caught = true;
303          }
304          if (caught == false)
305             fail("addRelation allows registration with invalid role name");
306
307          support = new RelationSupport JavaDoc("idCZ", service, server, "relationTypeC",
308                                           rolesCZ);
309          name = new ObjectName JavaDoc("test:type=relationCZ");
310          server.registerMBean(support, name);
311
312          caught = false;
313          try
314          {
315             rs.addRelation(name);
316          }
317          catch (InvalidRoleValueException JavaDoc e)
318          {
319             caught = true;
320          }
321          if (caught == false)
322             fail("addRelation allows registration with invalid role value");
323       }
324       finally
325       {
326          MBeanServerFactory.releaseMBeanServer(server);
327       }
328    }
329
330    /**
331     * Test add a relation type
332     */

333    public void testAddRelationType() throws Exception JavaDoc
334    {
335       RoleInfo JavaDoc roleInfo1 = null;
336       RoleInfo JavaDoc roleInfo2 = null;
337       RoleInfo JavaDoc[] roleInfos = null;
338       RelationService JavaDoc rs = null;
339       ArrayList JavaDoc result = null;
340       RoleInfo JavaDoc result1 = null;
341       RoleInfo JavaDoc result2 = null;
342       roleInfo1 = new RoleInfo JavaDoc("roleInfo1", Trivial.class.getName());
343       roleInfo2 = new RoleInfo JavaDoc("roleInfo2", Trivial.class.getName());
344       roleInfos = new RoleInfo JavaDoc[] { roleInfo1, roleInfo2 };
345       RelationTypeSupport JavaDoc rtsupp = new RelationTypeSupport JavaDoc("RelationTypeName",
346                                                   roleInfos);
347       rs = new RelationService JavaDoc(true);
348       rs.addRelationType(rtsupp);
349       result = (ArrayList JavaDoc) rs.getRoleInfos("RelationTypeName");
350       result1 = rs.getRoleInfo("RelationTypeName", "roleInfo1");
351       result2 = rs.getRoleInfo("RelationTypeName", "roleInfo2");
352
353       // Check the roleInfos
354
assertEquals(2, result.size());
355       assertEquals(roleInfo1.toString(), result1.toString());
356       assertEquals(roleInfo2.toString(), result2.toString());
357    }
358
359    /**
360     * Test create relation type errors
361     */

362    public void testAddRelationTypeErrors() throws Exception JavaDoc
363    {
364       RoleInfo JavaDoc roleInfo1 = null;
365       RoleInfo JavaDoc roleInfo2 = null;
366       RoleInfo JavaDoc[] roleInfos = null;
367       RelationService JavaDoc rs = null;
368       RelationTypeSupport JavaDoc rtsupp = null;
369
370       // Null relation type
371
boolean caught = false;
372       try
373       {
374          roleInfo1 = new RoleInfo JavaDoc("roleInfo1", Trivial.class.getName());
375          roleInfo2 = new RoleInfo JavaDoc("roleInfo2", Trivial.class.getName());
376          roleInfos = new RoleInfo JavaDoc[] { roleInfo1, roleInfo2 };
377          rs = new RelationService JavaDoc(true);
378          rs.addRelationType(null);
379       }
380       catch (IllegalArgumentException JavaDoc e)
381       {
382          caught = true;
383       }
384       if (caught == false)
385          fail("addRelationType allows null relation type");
386
387       // Duplicate relation types
388
caught = false;
389       try
390       {
391          rtsupp = new RelationTypeSupport JavaDoc("RelationTypeName", roleInfos);
392          rs.addRelationType(rtsupp);
393          rs.addRelationType(rtsupp);
394       }
395       catch (InvalidRelationTypeException JavaDoc e)
396       {
397          caught = true;
398       }
399       if (caught == false)
400          fail("addRelationType allows duplication relation types");
401
402       // Duplicate role infos
403
caught = false;
404       try
405       {
406          roleInfos[1] = roleInfos[0];
407          rtsupp = new RelationTypeSupport JavaDoc("RelationTypeName1", roleInfos);
408          rs.addRelationType(rtsupp);
409       }
410       catch (InvalidRelationTypeException JavaDoc e)
411       {
412          caught = true;
413       }
414       if (caught == false)
415          fail("addRelationType allows duplicate role names");
416
417       // Null role info
418
caught = false;
419       try
420       {
421          roleInfos[1] = null;
422          rtsupp = new RelationTypeSupport JavaDoc("RelationTypeName1", roleInfos);
423          rs.addRelationType(rtsupp);
424       }
425       catch (InvalidRelationTypeException JavaDoc e)
426       {
427          caught = true;
428       }
429       if (caught == false)
430          fail("addRelationType allows null role info");
431
432       // No role info
433
caught = false;
434       try
435       {
436          rtsupp = new RelationTypeSupport JavaDoc("RelationTypeName1", new RoleInfo JavaDoc[0]);
437          rs.addRelationType(rtsupp);
438       }
439       catch (InvalidRelationTypeException JavaDoc e)
440       {
441          caught = true;
442       }
443       if (caught == false)
444          fail("addRelationType allows no role info");
445    }
446
447    /**
448     * Test check role reading
449     */

450    public void testCheckRoleReadingExternal() throws Exception JavaDoc
451    {
452       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
453       try
454       {
455          ObjectName JavaDoc service = createRelationService("test:type=service", server);
456          createRelationTypeB(service);
457          createRolesB(server);
458          RelationSupport JavaDoc support = null;
459          Integer JavaDoc readB1 = null;
460          Integer JavaDoc readB2 = null;
461          RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
462          support = new RelationSupport JavaDoc("id", service, server,
463                                           "relationTypeB", rolesB);
464          addRelation(server, service, support, "test:type=support");
465          readB1 = rs.checkRoleReading("roleB1", "relationTypeB");
466          readB2 = rs.checkRoleReading("roleB2", "relationTypeB");
467
468          assertEquals(0, readB1.intValue());
469          assertEquals(RoleStatus.ROLE_NOT_READABLE, readB2.intValue());
470       }
471       finally
472       {
473          MBeanServerFactory.releaseMBeanServer(server);
474       }
475    }
476
477    /**
478     * Test check role reading errors
479     */

480    public void testCheckRoleReadingErrors() throws Exception JavaDoc
481    {
482       ObjectName JavaDoc service = createRelationService("test:type=service", null);
483       RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
484       createRelationTypeB(service);
485       createRolesB(null);
486
487       boolean caught = false;
488       try
489       {
490          rs.checkRoleReading(null, "relationTypeB");
491       }
492       catch(IllegalArgumentException JavaDoc e)
493       {
494          caught = true;
495       }
496       if (caught == false)
497          fail("checkRoleReading allows null role name");
498
499       caught = false;
500       try
501       {
502          rs.checkRoleReading("roleB1", null);
503       }
504       catch(IllegalArgumentException JavaDoc e)
505       {
506          caught = true;
507       }
508       if (caught == false)
509          fail("checkRoleReading allows null relation name");
510
511       caught = false;
512       try
513       {
514          rs.checkRoleReading("roleB1", "rubbish");
515       }
516       catch(RelationTypeNotFoundException JavaDoc e)
517       {
518          caught = true;
519       }
520       if (caught == false)
521          fail("checkRoleReading allows invalid relation type name");
522    }
523
524    /**
525     * Test check role writing
526     */

527    public void testCheckRoleWritingExternal() throws Exception JavaDoc
528    {
529       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
530       try
531       {
532          ObjectName JavaDoc service = createRelationService("test:type=service", server);
533          createRelationTypeB(service);
534          createRolesB(server);
535          RelationSupport JavaDoc support = null;
536          Integer JavaDoc writeB1normal = null;
537          Integer JavaDoc writeB2normal = null;
538          Integer JavaDoc writeB1init = null;
539          Integer JavaDoc writeB2init = null;
540          RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
541          support = new RelationSupport JavaDoc("id", service, server,
542                                        "relationTypeB", rolesB);
543          addRelation(server, service, support, "test:type=support");
544          writeB1normal = rs.checkRoleWriting(roleB1, "relationTypeB", new Boolean JavaDoc(false));
545          writeB2normal = rs.checkRoleWriting(roleB2, "relationTypeB", new Boolean JavaDoc(false));
546          writeB1init = rs.checkRoleWriting(roleB1, "relationTypeB", new Boolean JavaDoc(true));
547          writeB2init = rs.checkRoleWriting(roleB2, "relationTypeB", new Boolean JavaDoc(true));
548          assertEquals(RoleStatus.ROLE_NOT_WRITABLE, writeB1normal.intValue());
549          assertEquals(0, writeB2normal.intValue());
550          assertEquals(0, writeB1init.intValue());
551          assertEquals(0, writeB2init.intValue());
552       }
553       finally
554       {
555          MBeanServerFactory.releaseMBeanServer(server);
556       }
557    }
558
559    /**
560     * Test check role writing errors
561     */

562    public void testCheckRoleWritingErrors() throws Exception JavaDoc
563    {
564       ObjectName JavaDoc service = createRelationService("test:type=service", null);
565       RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
566       createRelationTypeB(service);
567       createRolesB(null);
568
569       boolean caught = false;
570       try
571       {
572          rs.checkRoleWriting(null, "relationTypeB", new Boolean JavaDoc(true));
573       }
574       catch(IllegalArgumentException JavaDoc e)
575       {
576          caught = true;
577       }
578       if (caught == false)
579          fail("checkRoleWriting allows null role name");
580
581       caught = false;
582       try
583       {
584          rs.checkRoleWriting(roleB1, null, new Boolean JavaDoc(true));
585       }
586       catch(IllegalArgumentException JavaDoc e)
587       {
588          caught = true;
589       }
590       if (caught == false)
591          fail("checkRoleWriting allows null relation name");
592
593       caught = false;
594       try
595       {
596          rs.checkRoleWriting(roleB1, "relationTypeB", null);
597       }
598       catch(IllegalArgumentException JavaDoc e)
599       {
600          caught = true;
601       }
602       if (caught == false)
603          fail("checkRoleWriting allows null init flag");
604
605       caught = false;
606       try
607       {
608          rs.checkRoleWriting(roleB1, "rubbish", new Boolean JavaDoc(true));
609       }
610       catch(RelationTypeNotFoundException JavaDoc e)
611       {
612          caught = true;
613       }
614       if (caught == false)
615          fail("checkRoleWriting allows invalid relation type name");
616    }
617
618    /**
619     * Test create relation
620     */

621    public void testCreateRelation() throws Exception JavaDoc
622    {
623       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
624       try
625       {
626          ObjectName JavaDoc service = createRelationService("test:type=service", server);
627          createRelationTypeB(service);
628          createRolesB(server);
629          Listener JavaDoc listener = new Listener JavaDoc(RelationNotification.RELATION_BASIC_CREATION);
630          RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
631          server.addNotificationListener(service, listener, null, null);
632          rs.createRelation("id", "relationTypeB", rolesB);
633          boolean result = rs.hasRelation("id").booleanValue();
634          assertEquals(true, result);
635          listener.check(1);
636       }
637       finally
638       {
639          MBeanServerFactory.releaseMBeanServer(server);
640       }
641    }
642
643    /**
644     * Test create relation errors
645     */

646    public void testCreateRelationErrors() throws Exception JavaDoc
647    {
648       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
649       try
650       {
651          ObjectName JavaDoc service = createRelationService("test:type=service", server);
652          RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
653          createRelationTypeB(service);
654          createRolesB(server);
655          createRelationTypeC(service);
656          createRolesC(server);
657          createRolesCZ(server);
658          createRolesCZZ(server);
659
660          boolean caught = false;
661          try
662          {
663             rs.createRelation(null, "relationTypeC", rolesC);
664          }
665          catch(IllegalArgumentException JavaDoc e)
666          {
667             caught = true;
668          }
669          if (caught == false)
670             fail("createRelation allows null relation id");
671         
672          caught = false;
673          try
674          {
675             rs.createRelation("relationId", null, rolesC);
676          }
677          catch(IllegalArgumentException JavaDoc e)
678          {
679             caught = true;
680          }
681          if (caught == false)
682             fail("createRelation allows null relation type name");
683         
684          caught = false;
685          try
686          {
687             rs.createRelation("relationId", "rubbish", rolesC);
688          }
689          catch(RelationTypeNotFoundException JavaDoc e)
690          {
691             caught = true;
692          }
693          if (caught == false)
694             fail("createRelation allows invalid relation type name");
695         
696          caught = false;
697          try
698          {
699             RoleList JavaDoc roleList = new RoleList JavaDoc();
700             roleList.add(roleC1);
701             roleList.add(roleB1);
702             rs.createRelation("relationId", "relationTypeC", roleList);
703          }
704          catch(RoleNotFoundException JavaDoc e)
705          {
706             caught = true;
707          }
708          if (caught == false)
709             fail("createRelation allows invalid role name");
710
711          caught = false;
712          try
713          {
714             RoleList JavaDoc roleList = new RoleList JavaDoc();
715             roleList.add(roleC1);
716             roleList.add(roleCZ2);
717             rs.createRelation("relationId", "relationTypeC", roleList);
718          }
719          catch(InvalidRoleValueException JavaDoc e)
720          {
721             caught = true;
722          }
723          if (caught == false)
724             fail("createRelation allows a role below the minimum");
725         
726          caught = false;
727          try
728          {
729             RoleList JavaDoc roleList = new RoleList JavaDoc();
730             roleList.add(roleC1);
731             roleList.add(roleCZZ);
732             rs.createRelation("relationId", "relationTypeC", roleList);
733          }
734          catch(InvalidRoleValueException JavaDoc e)
735          {
736             caught = true;
737          }
738          if (caught == false)
739             fail("createRelation allows a role above the maximum");
740         
741          caught = false;
742          try
743          {
744             RoleList JavaDoc roleList = new RoleList JavaDoc();
745             roleList.add(roleC1);
746             roleList.add(roleCZZZ);
747             rs.createRelation("relationId", "relationTypeC", roleList);
748          }
749          catch(InvalidRoleValueException JavaDoc e)
750          {
751             caught = true;
752          }
753          if (caught == false)
754             fail("createRelation allows a role with unregistered beans");
755         
756          caught = false;
757          try
758          {
759             rs.createRelation("relationId", "relationTypeC", rolesC);
760             rs.createRelation("relationId", "relationTypeC", rolesC);
761          }
762          catch(InvalidRelationIdException JavaDoc e)
763          {
764             caught = true;
765          }
766          if (caught == false)
767             fail("createRelation allows duplicate relation id");
768
769          server.unregisterMBean(service);
770          caught = false;
771          try
772          {
773             rs.createRelation("relationId2", "relationTypeC", rolesC);
774          }
775          catch(RelationServiceNotRegisteredException JavaDoc e)
776          {
777             caught = true;
778          }
779          if (caught == false)
780             fail("FAILS IN RI: createRelation allowed when not registered");
781       }
782       finally
783       {
784          MBeanServerFactory.releaseMBeanServer(server);
785       }
786    }
787
788    /**
789     * Test create relation type, getRoleInfo and getRoleInfos
790     */

791    public void testCreationRelationType() throws Exception JavaDoc
792    {
793       RoleInfo JavaDoc roleInfo1 = null;
794       RoleInfo JavaDoc roleInfo2 = null;
795       RoleInfo JavaDoc[] roleInfos = null;
796       RelationService JavaDoc rs = null;
797       ArrayList JavaDoc result = null;
798       RoleInfo JavaDoc result1 = null;
799       RoleInfo JavaDoc result2 = null;
800       roleInfo1 = new RoleInfo JavaDoc("roleInfo1", Trivial.class.getName());
801       roleInfo2 = new RoleInfo JavaDoc("roleInfo2", Trivial.class.getName());
802       roleInfos = new RoleInfo JavaDoc[] { roleInfo1, roleInfo2 };
803       rs = new RelationService JavaDoc(true);
804       rs.createRelationType("RelationTypeName", roleInfos);
805       result = (ArrayList JavaDoc) rs.getRoleInfos("RelationTypeName");
806       result1 = rs.getRoleInfo("RelationTypeName", "roleInfo1");
807       result2 = rs.getRoleInfo("RelationTypeName", "roleInfo2");
808
809       // Check the roleInfos
810
assertEquals(2, result.size());
811       assertEquals(roleInfo1.toString(), result1.toString());
812       assertEquals(roleInfo2.toString(), result2.toString());
813    }
814
815    /**
816     * Test create relation type errors
817     */

818    public void testCreateRelationTypeErrors() throws Exception JavaDoc
819    {
820       RoleInfo JavaDoc roleInfo1 = null;
821       RoleInfo JavaDoc roleInfo2 = null;
822       RoleInfo JavaDoc[] roleInfos = null;
823       RelationService JavaDoc rs = null;
824
825       // Null relation type name
826
boolean caught = false;
827       try
828       {
829          roleInfo1 = new RoleInfo JavaDoc("roleInfo1", Trivial.class.getName());
830          roleInfo2 = new RoleInfo JavaDoc("roleInfo2", Trivial.class.getName());
831          roleInfos = new RoleInfo JavaDoc[] { roleInfo1, roleInfo2 };
832          rs = new RelationService JavaDoc(true);
833          rs.createRelationType(null, roleInfos);
834       }
835       catch (IllegalArgumentException JavaDoc e)
836       {
837          caught = true;
838       }
839       if (caught == false)
840          fail("createRelationType allows null relation type name");
841
842       // Null role infos
843
caught = false;
844       try
845       {
846          rs.createRelationType("relationTypeName", null);
847       }
848       catch (IllegalArgumentException JavaDoc e)
849       {
850          caught = true;
851       }
852       if (caught == false)
853          fail("createRelationType allows null role infos");
854
855       // Duplicate relation types
856
caught = false;
857       try
858       {
859          rs.createRelationType("relationTypeName", roleInfos);
860          rs.createRelationType("relationTypeName", roleInfos);
861       }
862       catch (InvalidRelationTypeException JavaDoc e)
863       {
864          caught = true;
865       }
866       if (caught == false)
867          fail("createRelationType allows duplicate relation type names");
868
869       // Duplicate role infos
870
caught = false;
871       try
872       {
873          roleInfos[1] = roleInfos[0];
874          rs.createRelationType("relationTypeName1", roleInfos);
875       }
876       catch (InvalidRelationTypeException JavaDoc e)
877       {
878          caught = true;
879       }
880       if (caught == false)
881          fail("createRelationType allows duplicate role names");
882
883       // Null role info
884
caught = false;
885       try
886       {
887          roleInfos[1] = null;
888          rs.createRelationType("relationTypeName1", roleInfos);
889       }
890       catch (InvalidRelationTypeException JavaDoc e)
891       {
892          caught = true;
893       }
894       if (caught == false)
895          fail("createRelationType allows null role info");
896
897       // No role info
898
caught = false;
899       try
900       {
901          rs.createRelationType("relationTypeName1", new RoleInfo JavaDoc[0]);
902       }
903       catch (InvalidRelationTypeException JavaDoc e)
904       {
905          caught = true;
906       }
907       if (caught == false)
908          fail("createRelationType allows no role info");
909    }
910
911    /**
912     * Test getRoleInfo errors
913     */

914    public void testGetRoleInfoErrors() throws Exception JavaDoc
915    {
916       RoleInfo JavaDoc roleInfo1 = null;
917       RoleInfo JavaDoc roleInfo2 = null;
918       RoleInfo JavaDoc[] roleInfos = null;
919       RelationService JavaDoc rs = null;
920       roleInfo1 = new RoleInfo JavaDoc("roleInfo1", Trivial.class.getName());
921       roleInfo2 = new RoleInfo JavaDoc("roleInfo2", Trivial.class.getName());
922       roleInfos = new RoleInfo JavaDoc[] { roleInfo1, roleInfo2 };
923       rs = new RelationService JavaDoc(true);
924       rs.createRelationType("RelationTypeName", roleInfos);
925
926       boolean caught = false;
927       try
928       {
929          rs.getRoleInfo(null, "roleInfo1");
930       }
931       catch (IllegalArgumentException JavaDoc e)
932       {
933          caught = true;
934       }
935       if (caught == false)
936          fail("getRoleInfo allows null relation type name");
937
938       caught = false;
939       try
940       {
941          rs.getRoleInfo("RelationTypeName", null);
942       }
943       catch (IllegalArgumentException JavaDoc e)
944       {
945          caught = true;
946       }
947       if (caught == false)
948          fail("getRoleInfo allows null role info name");
949
950       caught = false;
951       try
952       {
953          rs.getRoleInfo("RelationTypeNameX", "roleInfo1");
954       }
955       catch (RelationTypeNotFoundException JavaDoc e)
956       {
957          caught = true;
958       }
959       if (caught == false)
960          fail("getRoleInfo allows non-existent relation type name");
961
962       caught = false;
963       try
964       {
965          rs.getRoleInfo("RelationTypeName", "roleInfoX");
966       }
967       catch (RoleInfoNotFoundException JavaDoc e)
968       {
969          caught = true;
970       }
971       if (caught == false)
972          fail("getRoleInfo allows non-existent role info name");
973    }
974
975    /**
976     * Test getRoleInfos errors
977     */

978    public void testGetRoleInfosErrors() throws Exception JavaDoc
979    {
980       RoleInfo JavaDoc roleInfo1 = null;
981       RoleInfo JavaDoc roleInfo2 = null;
982       RoleInfo JavaDoc[] roleInfos = null;
983       RelationService JavaDoc rs = null;
984       roleInfo1 = new RoleInfo JavaDoc("roleInfo1", Trivial.class.getName());
985       roleInfo2 = new RoleInfo JavaDoc("roleInfo2", Trivial.class.getName());
986       roleInfos = new RoleInfo JavaDoc[] { roleInfo1, roleInfo2 };
987       rs = new RelationService JavaDoc(true);
988       rs.createRelationType("RelationTypeName", roleInfos);
989
990       boolean caught = false;
991       try
992       {
993          rs.getRoleInfos(null);
994       }
995       catch (IllegalArgumentException JavaDoc e)
996       {
997          caught = true;
998       }
999       if (caught == false)
1000         fail("getRoleInfos allows null relation type name");
1001
1002      caught = false;
1003      try
1004      {
1005         rs.getRoleInfos("RelationTypeNameX");
1006      }
1007      catch (RelationTypeNotFoundException JavaDoc e)
1008      {
1009         caught = true;
1010      }
1011      if (caught == false)
1012         fail("getRoleInfos allows non-existent relation type name");
1013   }
1014
1015   /**
1016    * Test find associated mbeans
1017    *
1018    * REVIEW: This test needs more thought
1019    */

1020   public void testFindAssociatedMBeansExternal() throws Exception JavaDoc
1021   {
1022      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1023      try
1024      {
1025         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1026         createRelationTypeC(service);
1027         createRolesC(server);
1028         createRelationTypeCX(service);
1029         createRolesCX(server);
1030         Map JavaDoc result1 = null;
1031         Map JavaDoc result2 = null;
1032         Map JavaDoc result3 = null;
1033         Map JavaDoc result4 = null;
1034         Map JavaDoc result5 = null;
1035         Map JavaDoc result6 = null;
1036         Map JavaDoc result7 = null;
1037         Map JavaDoc result8 = null;
1038         Map JavaDoc result9 = null;
1039         Map JavaDoc result10 = null;
1040         Map JavaDoc result11 = null;
1041         Map JavaDoc result12 = null;
1042         Map JavaDoc result13 = null;
1043         Map JavaDoc result14 = null;
1044         Map JavaDoc result15 = null;
1045         Map JavaDoc result16 = null;
1046         RelationSupport JavaDoc supportCX = new RelationSupport JavaDoc("idcx", service, server,
1047                                       "relationTypeCX", rolesCX);
1048         RelationSupport JavaDoc supportC = new RelationSupport JavaDoc("idc", service, server,
1049                                       "relationTypeC", rolesC);
1050         addRelation(server, service, supportCX, "test:type=supportCX");
1051         addRelation(server, service, supportC, "test:type=supportC");
1052         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
1053         result1 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), null, null);
1054         result2 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), null, null);
1055         result3 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeCX", null);
1056         result4 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeC", null);
1057         result5 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), null, "roleC1");
1058         result6 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), null, "roleC2");
1059         result7 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), null, "roleC1");
1060         result8 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), null, "roleC2");
1061         result9 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeCX", "roleC1");
1062         result10 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeC", "roleC1");
1063         result11 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeCX", "roleC2");
1064         result12 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeC", "roleC2");
1065         result13 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeCX", "roleC1");
1066         result14 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeC", "roleC1");
1067         result15 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeCX", "roleC2");
1068         result16 = rs.findAssociatedMBeans(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeC", "roleC2");
1069         assertEquals(5, result1.size());
1070         assertEquals(5, result2.size());
1071         assertEquals(4, result3.size());
1072         assertEquals(2, result4.size());
1073         assertEquals(2, result5.size());
1074         assertEquals(5, result6.size());
1075         assertEquals(2, result7.size());
1076         assertEquals(5, result8.size());
1077         assertEquals(0, result9.size());
1078         assertEquals(2, result10.size());
1079         assertEquals(4, result11.size());
1080         assertEquals(2, result12.size());
1081         assertEquals(0, result13.size());
1082         assertEquals(2, result14.size());
1083         assertEquals(4, result15.size());
1084         assertEquals(2, result16.size());
1085      }
1086      finally
1087      {
1088         MBeanServerFactory.releaseMBeanServer(server);
1089      }
1090   }
1091
1092   /**
1093    * Test find associated mbeans errors
1094    */

1095   public void testFindAssociatedMBeansErrors() throws Exception JavaDoc
1096   {
1097      RelationService JavaDoc rs = new RelationService JavaDoc(true);
1098      
1099      boolean caught = false;
1100      try
1101      {
1102         rs.findAssociatedMBeans(null, null, null);
1103      }
1104      catch (IllegalArgumentException JavaDoc e)
1105      {
1106         caught = true;
1107      }
1108      if (caught == false)
1109         fail ("findAssociatedMBeans allows a null mbean name");
1110   }
1111
1112   /**
1113    * Test find referencing relations
1114    *
1115    * REVIEW: This test needs more thought
1116    */

1117   public void testFindReferencingRelationsExternal() throws Exception JavaDoc
1118   {
1119      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1120      try
1121      {
1122         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1123         createRelationTypeC(service);
1124         createRolesC(server);
1125         createRelationTypeCX(service);
1126         createRolesCX(server);
1127         Map JavaDoc result1 = null;
1128         Map JavaDoc result2 = null;
1129         Map JavaDoc result3 = null;
1130         Map JavaDoc result4 = null;
1131         Map JavaDoc result5 = null;
1132         Map JavaDoc result6 = null;
1133         Map JavaDoc result7 = null;
1134         Map JavaDoc result8 = null;
1135         Map JavaDoc result9 = null;
1136         Map JavaDoc result10 = null;
1137         Map JavaDoc result11 = null;
1138         Map JavaDoc result12 = null;
1139         Map JavaDoc result13 = null;
1140         Map JavaDoc result14 = null;
1141         Map JavaDoc result15 = null;
1142         Map JavaDoc result16 = null;
1143         RelationSupport JavaDoc supportCX = new RelationSupport JavaDoc("idcx", service, server,
1144                                       "relationTypeCX", rolesCX);
1145         RelationSupport JavaDoc supportC = new RelationSupport JavaDoc("idc", service, server,
1146                                       "relationTypeC", rolesC);
1147         addRelation(server, service, supportCX, "test:type=supportCX");
1148         addRelation(server, service, supportC, "test:type=supportC");
1149         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
1150         result1 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), null, null);
1151         result2 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), null, null);
1152         result3 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeCX", null);
1153         result4 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeC", null);
1154         result5 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), null, "roleC1");
1155         result6 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), null, "roleC2");
1156         result7 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), null, "roleC1");
1157         result8 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), null, "roleC2");
1158         result9 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeCX", "roleC1");
1159         result10 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeC", "roleC1");
1160         result11 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeCX", "roleC2");
1161         result12 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeC", "roleC2");
1162         result13 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeCX", "roleC1");
1163         result14 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeC", "roleC1");
1164         result15 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeCX", "roleC2");
1165         result16 = rs.findReferencingRelations(new ObjectName JavaDoc("x:relation=c,role=1,bean=1"), "relationTypeC", "roleC2");
1166         assertEquals(2, result1.size());
1167         assertEquals(2, result2.size());
1168         assertEquals(1, result3.size());
1169         assertEquals(1, result4.size());
1170         assertEquals(1, result5.size());
1171         assertEquals(2, result6.size());
1172         assertEquals(1, result7.size());
1173         assertEquals(2, result8.size());
1174         assertEquals(0, result9.size());
1175         assertEquals(1, result10.size());
1176         assertEquals(1, result11.size());
1177         assertEquals(1, result12.size());
1178         assertEquals(0, result13.size());
1179         assertEquals(1, result14.size());
1180         assertEquals(1, result15.size());
1181         assertEquals(1, result16.size());
1182      }
1183      finally
1184      {
1185         MBeanServerFactory.releaseMBeanServer(server);
1186      }
1187   }
1188
1189   /**
1190    * Test find referencing relations errors
1191    */

1192   public void testFindReferencingRelationsErrors() throws Exception JavaDoc
1193   {
1194      RelationService JavaDoc rs = new RelationService JavaDoc(true);
1195      
1196      boolean caught = false;
1197      try
1198      {
1199         rs.findReferencingRelations(null, null, null);
1200      }
1201      catch (IllegalArgumentException JavaDoc e)
1202      {
1203         caught = true;
1204      }
1205      if (caught == false)
1206         fail ("findReferencingRelations allows a null mbean name");
1207   }
1208
1209   /**
1210    * Test find relations of types
1211    *
1212    * REVIEW: This test needs more thought
1213    */

1214   public void testFindRelationsOfTypeExternal() throws Exception JavaDoc
1215   {
1216      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1217      try
1218      {
1219         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1220         createRelationTypeA(service);
1221         createRolesA(server);
1222         createRelationTypeB(service);
1223         createRolesB(server);
1224         createRelationTypeC(service);
1225         createRolesC(server);
1226         createRelationTypeCX(service);
1227         createRolesCX(server);
1228         List JavaDoc result1 = null;
1229         List JavaDoc result2 = null;
1230         List JavaDoc result3 = null;
1231         List JavaDoc result4 = null;
1232         RelationSupport JavaDoc supportA1 = new RelationSupport JavaDoc("ida1", service, server,
1233                                          "relationTypeA", rolesA);
1234         RelationSupport JavaDoc supportA2 = new RelationSupport JavaDoc("ida2", service, server,
1235                                          "relationTypeA", rolesA);
1236         RelationSupport JavaDoc supportCX = new RelationSupport JavaDoc("idcx", service, server,
1237                                          "relationTypeCX", rolesCX);
1238         RelationSupport JavaDoc supportC = new RelationSupport JavaDoc("idc", service, server,
1239                                          "relationTypeC", rolesC);
1240         addRelation(server, service, supportA1, "test:type=supportA1");
1241         addRelation(server, service, supportA2, "test:type=supportA2");
1242         addRelation(server, service, supportCX, "test:type=supportCX");
1243         addRelation(server, service, supportC, "test:type=supportC");
1244         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
1245         result1 = rs.findRelationsOfType("relationTypeA");
1246         result2 = rs.findRelationsOfType("relationTypeB");
1247         result3 = rs.findRelationsOfType("relationTypeC");
1248         result4 = rs.findRelationsOfType("relationTypeCX");
1249         assertEquals(2, result1.size());
1250         assertEquals(0, result2.size());
1251         assertEquals(1, result3.size());
1252         assertEquals(1, result4.size());
1253      }
1254      finally
1255      {
1256         MBeanServerFactory.releaseMBeanServer(server);
1257      }
1258   }
1259
1260   /**
1261    * Test find relations of type errors
1262    */

1263   public void testFindRelationsOfTypeErrors() throws Exception JavaDoc
1264   {
1265      RelationService JavaDoc rs = new RelationService JavaDoc(true);
1266      
1267      boolean caught = false;
1268      try
1269      {
1270         rs.findRelationsOfType(null);
1271      }
1272      catch (IllegalArgumentException JavaDoc e)
1273      {
1274         caught = true;
1275      }
1276      if (caught == false)
1277         fail ("findRelationsOfType allows a null relation type name");
1278
1279      caught = false;
1280      try
1281      {
1282         rs.findRelationsOfType("rubbish");
1283      }
1284      catch (RelationTypeNotFoundException JavaDoc e)
1285      {
1286         caught = true;
1287      }
1288      if (caught == false)
1289         fail ("findRelationsOfType allows an invalid relation type name");
1290   }
1291
1292   /**
1293    * Test get all relations ids
1294    *
1295    * REVIEW: This test needs more thought
1296    */

1297   public void testGetAllRelationsIdsExternal() throws Exception JavaDoc
1298   {
1299      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1300      try
1301      {
1302         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1303         createRelationTypeA(service);
1304         createRolesA(server);
1305         createRelationTypeB(service);
1306         createRolesB(server);
1307         createRelationTypeC(service);
1308         createRolesC(server);
1309         createRelationTypeCX(service);
1310         createRolesCX(server);
1311         List JavaDoc result = null;
1312         RelationSupport JavaDoc supportA1 = new RelationSupport JavaDoc("ida1", service, server,
1313                                          "relationTypeA", rolesA);
1314         RelationSupport JavaDoc supportA2 = new RelationSupport JavaDoc("ida2", service, server,
1315                                          "relationTypeA", rolesA);
1316         RelationSupport JavaDoc supportCX = new RelationSupport JavaDoc("idcx", service, server,
1317                                          "relationTypeCX", rolesCX);
1318         RelationSupport JavaDoc supportC = new RelationSupport JavaDoc("idc", service, server,
1319                                          "relationTypeC", rolesC);
1320         addRelation(server, service, supportA1, "test:type=supportA1");
1321         addRelation(server, service, supportA2, "test:type=supportA2");
1322         addRelation(server, service, supportCX, "test:type=supportCX");
1323         addRelation(server, service, supportC, "test:type=supportC");
1324         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
1325         result = rs.getAllRelationIds();
1326         assertEquals(4, result.size());
1327         assertEquals(true, result.contains("ida1"));
1328         assertEquals(true, result.contains("ida2"));
1329         assertEquals(true, result.contains("idcx"));
1330         assertEquals(true, result.contains("idc"));
1331      }
1332      finally
1333      {
1334         MBeanServerFactory.releaseMBeanServer(server);
1335      }
1336   }
1337
1338   /**
1339    * Test get all relation type names
1340    */

1341   public void testGetAllRelationTypeNames() throws Exception JavaDoc
1342   {
1343      RelationService JavaDoc rs = new RelationService JavaDoc(true);
1344      assertEquals(0, rs.getAllRelationTypeNames().size());
1345
1346      RoleInfo JavaDoc roleInfo1 = null;
1347      RoleInfo JavaDoc roleInfo2 = null;
1348      RoleInfo JavaDoc[] roleInfos = null;
1349      roleInfo1 = new RoleInfo JavaDoc("roleInfo1", Trivial.class.getName());
1350      roleInfo2 = new RoleInfo JavaDoc("roleInfo2", Trivial.class.getName());
1351      roleInfos = new RoleInfo JavaDoc[] { roleInfo1, roleInfo2 };
1352      rs.createRelationType("name1", roleInfos);
1353      rs.createRelationType("name2", roleInfos);
1354      rs.createRelationType("name3", roleInfos);
1355
1356      ArrayList JavaDoc result = (ArrayList JavaDoc) rs.getAllRelationTypeNames();
1357      assertEquals(3, result.size());
1358      assertEquals(true, result.contains("name1"));
1359      assertEquals(true, result.contains("name2"));
1360      assertEquals(true, result.contains("name3"));
1361   }
1362
1363   /**
1364    * Test get all roles
1365    */

1366   public void testGetAllRolesExternal() throws Exception JavaDoc
1367   {
1368      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1369      try
1370      {
1371         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1372         createRelationTypeB(service);
1373         createRolesB(server);
1374         RoleResult JavaDoc result = null;
1375         RelationSupport JavaDoc support = new RelationSupport JavaDoc("id", service, server,
1376                                         "relationTypeB", rolesB);
1377         addRelation(server, service, support, "test:type=support");
1378         result = support.getAllRoles();
1379         checkResult(result, roleInfosB, rolesB);
1380      }
1381      finally
1382      {
1383         MBeanServerFactory.releaseMBeanServer(server);
1384      }
1385   }
1386
1387   /**
1388    * Test get all roles errors
1389    */

1390   public void testGetAllRolesErrors() throws Exception JavaDoc
1391   {
1392      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1393      try
1394      {
1395         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1396         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
1397         createRelationTypeC(service);
1398         createRolesC(server);
1399         RoleList JavaDoc roles = new RoleList JavaDoc();
1400         roles.add(roleC1);
1401         roles.add(roleC2);
1402         rs.createRelation("relationId", "relationTypeC", roles);
1403
1404         boolean caught = false;
1405         try
1406         {
1407            rs.getAllRoles(null);
1408         }
1409         catch(IllegalArgumentException JavaDoc e)
1410         {
1411            caught = true;
1412         }
1413         if (caught == false)
1414            fail("getAllRoles allows null relation id");
1415        
1416         caught = false;
1417         try
1418         {
1419            rs.getAllRoles("rubbish");
1420         }
1421         catch(RelationNotFoundException JavaDoc e)
1422         {
1423            caught = true;
1424         }
1425         if (caught == false)
1426            fail("getAllRoles allows invalid relation id");
1427
1428         server.unregisterMBean(service);
1429         caught = false;
1430         try
1431         {
1432            rs.getAllRoles("relationId");
1433         }
1434         catch(RelationServiceNotRegisteredException JavaDoc e)
1435         {
1436            caught = true;
1437         }
1438         if (caught == false)
1439            fail("FAILS IN RI: getAllRoles allowed when not registered");
1440      }
1441      finally
1442      {
1443         MBeanServerFactory.releaseMBeanServer(server);
1444      }
1445   }
1446
1447   /**
1448    * Test get Notification info
1449    */

1450   public void testGetNotificationInfo()
1451   {
1452      RelationService JavaDoc rs = new RelationService JavaDoc(true);
1453      MBeanNotificationInfo JavaDoc[] mbni = rs.getNotificationInfo();
1454      assertEquals(1, mbni.length);
1455      HashSet JavaDoc types = new HashSet JavaDoc();
1456      types.add(RelationNotification.RELATION_BASIC_CREATION);
1457      types.add(RelationNotification.RELATION_BASIC_REMOVAL);
1458      types.add(RelationNotification.RELATION_BASIC_UPDATE);
1459      types.add(RelationNotification.RELATION_MBEAN_CREATION);
1460      types.add(RelationNotification.RELATION_MBEAN_REMOVAL);
1461      types.add(RelationNotification.RELATION_MBEAN_UPDATE);
1462      String JavaDoc[] mbniTypes = mbni[0].getNotifTypes();
1463      assertEquals(types.size(), mbniTypes.length);
1464      for (int i = 0; i < mbniTypes.length; i++)
1465      {
1466         if (types.contains(mbniTypes[i]) == false)
1467            fail("Unexpected relation notification type: " + mbniTypes[i]);
1468      }
1469   }
1470
1471   /**
1472    * Test get/set Purge Flag
1473    */

1474   public void testGetSetPurgeFlag() throws Exception JavaDoc
1475   {
1476      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1477      try
1478      {
1479         RelationService JavaDoc rs = null;
1480         ObjectName JavaDoc name = null;
1481         rs = new RelationService JavaDoc(true);
1482         name = new ObjectName JavaDoc("test:type = rs");
1483         server.registerMBean(rs, name);
1484         assertEquals(true, rs.getPurgeFlag());
1485         rs.setPurgeFlag(false);
1486         assertEquals(false, rs.getPurgeFlag());
1487         rs.setPurgeFlag(true);
1488         assertEquals(true, rs.getPurgeFlag());
1489      }
1490      finally
1491      {
1492         MBeanServerFactory.releaseMBeanServer(server);
1493      }
1494   }
1495
1496   /**
1497    * Test get Referenced MBeans
1498    */

1499   public void testGetReferencedMBeansExternal() throws Exception JavaDoc
1500   {
1501      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1502      try
1503      {
1504         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1505         createRelationTypeC(service);
1506         createRolesC(server);
1507         Map JavaDoc result = null;
1508         RelationSupport JavaDoc support = new RelationSupport JavaDoc("id", service, server,
1509                                         "relationTypeC", rolesC);
1510         addRelation(server, service, support, "test:type=support");
1511         result = support.getReferencedMBeans();
1512         checkMBeans(result, rolesC);
1513      }
1514      finally
1515      {
1516         MBeanServerFactory.releaseMBeanServer(server);
1517      }
1518   }
1519
1520   /**
1521    * Test get referenced mbeans errors
1522    */

1523   public void testGetReferencedMBeansErrors() throws Exception JavaDoc
1524   {
1525      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1526      try
1527      {
1528         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1529         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
1530         createRelationTypeC(service);
1531         createRolesC(server);
1532         RoleList JavaDoc roles = new RoleList JavaDoc();
1533         roles.add(roleC1);
1534         roles.add(roleC2);
1535         rs.createRelation("relationId", "relationTypeC", roles);
1536
1537         boolean caught = false;
1538         try
1539         {
1540            rs.getReferencedMBeans(null);
1541         }
1542         catch(IllegalArgumentException JavaDoc e)
1543         {
1544            caught = true;
1545         }
1546         if (caught == false)
1547            fail("getReferencedMBeans allows null relation id");
1548        
1549         caught = false;
1550         try
1551         {
1552            rs.getReferencedMBeans("rubbish");
1553         }
1554         catch(RelationNotFoundException JavaDoc e)
1555         {
1556            caught = true;
1557         }
1558         if (caught == false)
1559            fail("getReferencedMBeans allows invalid relation id");
1560      }
1561      finally
1562      {
1563         MBeanServerFactory.releaseMBeanServer(server);
1564      }
1565   }
1566
1567   /**
1568    * Test get Relation Type Names
1569    */

1570   public void testGetRelationTypeNameExternal() throws Exception JavaDoc
1571   {
1572      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1573      try
1574      {
1575         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1576         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
1577         createRelationTypeB(service);
1578         createRolesB(server);
1579         createRelationTypeC(service);
1580         createRolesC(server);
1581         RelationSupport JavaDoc relB = null;
1582         RelationSupport JavaDoc relC = null;
1583         String JavaDoc resultB = null;
1584         String JavaDoc resultC = null;
1585         relB = new RelationSupport JavaDoc("idB", service, server,
1586                                       "relationTypeB", rolesB);
1587         addRelation(server, service, relB, "test:type=supportB");
1588         relC = new RelationSupport JavaDoc("idC", service, server,
1589                                       "relationTypeC", rolesC);
1590         addRelation(server, service, relC, "test:type=supportC");
1591         resultB = rs.getRelationTypeName("idB");
1592         resultC = rs.getRelationTypeName("idC");
1593         assertEquals("relationTypeB", resultB);
1594         assertEquals("relationTypeC", resultC);
1595      }
1596      finally
1597      {
1598         MBeanServerFactory.releaseMBeanServer(server);
1599      }
1600   }
1601
1602   /**
1603    * Test get relation type name errors
1604    */

1605   public void testGetRelationTypeNameErrors() throws Exception JavaDoc
1606   {
1607      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1608      try
1609      {
1610         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1611         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
1612         createRelationTypeC(service);
1613         createRolesC(server);
1614         RoleList JavaDoc roles = new RoleList JavaDoc();
1615         roles.add(roleC1);
1616         roles.add(roleC2);
1617         rs.createRelation("relationId", "relationTypeC", roles);
1618
1619         boolean caught = false;
1620         try
1621         {
1622            rs.getRelationTypeName(null);
1623         }
1624         catch(IllegalArgumentException JavaDoc e)
1625         {
1626            caught = true;
1627         }
1628         if (caught == false)
1629            fail("getRelationTypeName allows null relation id");
1630        
1631         caught = false;
1632         try
1633         {
1634            rs.getRelationTypeName("rubbish");
1635         }
1636         catch(RelationNotFoundException JavaDoc e)
1637         {
1638            caught = true;
1639         }
1640         if (caught == false)
1641            fail("getRelationTypeName allows invalid relation id");
1642      }
1643      finally
1644      {
1645         MBeanServerFactory.releaseMBeanServer(server);
1646      }
1647   }
1648
1649   /**
1650    * Test get Role
1651    */

1652   public void testGetRoleExternal() throws Exception JavaDoc
1653   {
1654      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1655      try
1656      {
1657         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1658         createRelationTypeC(service);
1659         createRolesC(server);
1660         List JavaDoc result = null;
1661         RelationSupport JavaDoc support = new RelationSupport JavaDoc("id", service, server,
1662                                         "relationTypeC", rolesC);
1663         addRelation(server, service, support, "test:type=support");
1664         result = support.getRole("roleC1");
1665         compareListOfObjectNames(getRole(rolesC, "roleC1").getRoleValue(), result);
1666      }
1667      finally
1668      {
1669         MBeanServerFactory.releaseMBeanServer(server);
1670      }
1671   }
1672
1673   /**
1674    * Test get role errors
1675    */

1676   public void testGetRoleErrors() throws Exception JavaDoc
1677   {
1678      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1679      try
1680      {
1681         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1682         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
1683         createRelationTypeC(service);
1684         createRolesC(server);
1685         RoleList JavaDoc roles = new RoleList JavaDoc();
1686         roles.add(roleC1);
1687         roles.add(roleC2);
1688         rs.createRelation("relationId", "relationTypeC", roles);
1689
1690         boolean caught = false;
1691         try
1692         {
1693            rs.getRole(null, "roleC1");
1694         }
1695         catch(IllegalArgumentException JavaDoc e)
1696         {
1697            caught = true;
1698         }
1699         if (caught == false)
1700            fail("getRole allows null relation id");
1701        
1702         caught = false;
1703         try
1704         {
1705            rs.getRole("relationId", null);
1706         }
1707         catch(IllegalArgumentException JavaDoc e)
1708         {
1709            caught = true;
1710         }
1711         if (caught == false)
1712            fail("getRole allows null role");
1713        
1714         caught = false;
1715         try
1716         {
1717            rs.getRole("rubbish", "roleC1");
1718         }
1719         catch(RelationNotFoundException JavaDoc e)
1720         {
1721            caught = true;
1722         }
1723         if (caught == false)
1724            fail("getRole allows invalid relation id");
1725        
1726         caught = false;
1727         try
1728         {
1729            rs.getRole("relationId", "rubbish");
1730         }
1731         catch(RoleNotFoundException JavaDoc e)
1732         {
1733            caught = true;
1734         }
1735         if (caught == false)
1736            fail("getRole allows invalid role name");
1737        
1738         caught = false;
1739         try
1740         {
1741            rs.getRole("relationId", "roleC2");
1742         }
1743         catch(RoleNotFoundException JavaDoc e)
1744         {
1745            caught = true;
1746         }
1747         if (caught == false)
1748            fail("getRole allows unreadable role");
1749
1750         server.unregisterMBean(service);
1751         caught = false;
1752         try
1753         {
1754            rs.getRole("relationId", "roleC1");
1755         }
1756         catch(RelationServiceNotRegisteredException JavaDoc e)
1757         {
1758            caught = true;
1759         }
1760         if (caught == false)
1761            fail("FAILS IN RI: getRole allowed when not registered");
1762      }
1763      finally
1764      {
1765         MBeanServerFactory.releaseMBeanServer(server);
1766      }
1767   }
1768
1769   /**
1770    * Test get Role Cardinality
1771    */

1772   public void testGetRoleCardinalityExternal() throws Exception JavaDoc
1773   {
1774      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1775      try
1776      {
1777         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1778         createRelationTypeC(service);
1779         createRolesC(server);
1780         Integer JavaDoc result = null;
1781         RelationSupport JavaDoc support = null;
1782         support = new RelationSupport JavaDoc("id", service, server,
1783                                          "relationTypeC", rolesC);
1784         addRelation(server, service, support, "test:type=support");
1785         result = support.getRoleCardinality("roleC1");
1786         assertEquals(2, result.intValue());
1787
1788         result = support.getRoleCardinality("roleC2");
1789         assertEquals(3, result.intValue());
1790      }
1791      finally
1792      {
1793         MBeanServerFactory.releaseMBeanServer(server);
1794      }
1795   }
1796
1797   /**
1798    * Test get role cardinality errors
1799    */

1800   public void testGetRoleCardinalityErrors() throws Exception JavaDoc
1801   {
1802      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1803      try
1804      {
1805         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1806         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
1807         createRelationTypeC(service);
1808         createRolesC(server);
1809         RoleList JavaDoc roles = new RoleList JavaDoc();
1810         roles.add(roleC1);
1811         roles.add(roleC2);
1812         rs.createRelation("relationId", "relationTypeC", roles);
1813
1814         boolean caught = false;
1815         try
1816         {
1817            rs.getRoleCardinality(null, "roleC1");
1818         }
1819         catch(IllegalArgumentException JavaDoc e)
1820         {
1821            caught = true;
1822         }
1823         if (caught == false)
1824            fail("getRoleCardinality allows null relation id");
1825        
1826         caught = false;
1827         try
1828         {
1829            rs.getRoleCardinality("relationId", null);
1830         }
1831         catch(IllegalArgumentException JavaDoc e)
1832         {
1833            caught = true;
1834         }
1835         if (caught == false)
1836            fail("getRoleCardinality allows null role");
1837        
1838         caught = false;
1839         try
1840         {
1841            rs.getRoleCardinality("rubbish", "roleC1");
1842         }
1843         catch(RelationNotFoundException JavaDoc e)
1844         {
1845            caught = true;
1846         }
1847         if (caught == false)
1848            fail("getRoleCardinality allows invalid relation id");
1849        
1850         caught = false;
1851         try
1852         {
1853            rs.getRoleCardinality("relationId", "rubbish");
1854         }
1855         catch(RoleNotFoundException JavaDoc e)
1856         {
1857            caught = true;
1858         }
1859         if (caught == false)
1860            fail("getRoleCardinality allows invalid role name");
1861      }
1862      finally
1863      {
1864         MBeanServerFactory.releaseMBeanServer(server);
1865      }
1866   }
1867
1868   /**
1869    * Test get Roles
1870    */

1871   public void testGetRolesExternal() throws Exception JavaDoc
1872   {
1873      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1874      try
1875      {
1876         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1877         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
1878         createRelationTypeC(service);
1879         createRolesC(server);
1880         RoleResult JavaDoc result = null;
1881         RelationSupport JavaDoc support = null;
1882         support = new RelationSupport JavaDoc("id", service, server,
1883                                       "relationTypeC", rolesC);
1884         addRelation(server, service, support, "test:type=support");
1885         result = rs.getRoles("id", new String JavaDoc[] {"roleC1", "roleC2" });
1886         checkResult(result, roleInfosC, rolesC);
1887
1888         result = rs.getRoles("id", new String JavaDoc[] {"roleC1" });
1889         RoleList JavaDoc resolved = result.getRoles();
1890         assertEquals(1, resolved.size());
1891         assertEquals(0, result.getRolesUnresolved().size());
1892         compare(getRole(rolesC, "roleC1"), (Role JavaDoc) resolved.get(0));
1893
1894         result = rs.getRoles("id", new String JavaDoc[] {"roleC2" });
1895         RoleUnresolvedList JavaDoc unresolved = result.getRolesUnresolved();
1896         assertEquals(0, result.getRoles().size());
1897         assertEquals(1, unresolved.size());
1898         assertEquals("roleC2", ((RoleUnresolved JavaDoc)unresolved.get(0)).getRoleName());
1899      }
1900      finally
1901      {
1902         MBeanServerFactory.releaseMBeanServer(server);
1903      }
1904   }
1905
1906   /**
1907    * Test get roles errors
1908    */

1909   public void testGetRolesErrors() throws Exception JavaDoc
1910   {
1911      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1912      try
1913      {
1914         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1915         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
1916         createRelationTypeC(service);
1917         createRolesC(server);
1918         RoleList JavaDoc roles = new RoleList JavaDoc();
1919         roles.add(roleC1);
1920         roles.add(roleC2);
1921         rs.createRelation("relationId", "relationTypeC", roles);
1922         String JavaDoc[] roleNames = new String JavaDoc[] {"roleC1"};
1923
1924         boolean caught = false;
1925         try
1926         {
1927            rs.getRoles(null, roleNames);
1928         }
1929         catch(IllegalArgumentException JavaDoc e)
1930         {
1931            caught = true;
1932         }
1933         if (caught == false)
1934            fail("getRoles allows null relation id");
1935        
1936         caught = false;
1937         try
1938         {
1939            rs.getRoles("relationId", null);
1940         }
1941         catch(IllegalArgumentException JavaDoc e)
1942         {
1943            caught = true;
1944         }
1945         if (caught == false)
1946            fail("getRoles allows null role name array");
1947        
1948         caught = false;
1949         try
1950         {
1951            rs.getRoles("rubbish", roleNames);
1952         }
1953         catch(RelationNotFoundException JavaDoc e)
1954         {
1955            caught = true;
1956         }
1957         if (caught == false)
1958            fail("getRoles allows invalid relation id");
1959
1960         server.unregisterMBean(service);
1961         caught = false;
1962         try
1963         {
1964            rs.getRoles("relationId", roleNames);
1965         }
1966         catch(RelationServiceNotRegisteredException JavaDoc e)
1967         {
1968            caught = true;
1969         }
1970         if (caught == false)
1971            fail("FAILS IN RI: getRoles allowed when not registered");
1972      }
1973      finally
1974      {
1975         MBeanServerFactory.releaseMBeanServer(server);
1976      }
1977   }
1978
1979   /**
1980    * Test Has Relation
1981    */

1982   public void testHasRelationExternal() throws Exception JavaDoc
1983   {
1984      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
1985      try
1986      {
1987         ObjectName JavaDoc service = createRelationService("test:type=service", server);
1988         createRelationTypeC(service);
1989         createRolesC(server);
1990         RelationSupport JavaDoc support = null;
1991         Boolean JavaDoc result1 = null;
1992         Boolean JavaDoc result2 = null;
1993         Boolean JavaDoc result3 = null;
1994         Boolean JavaDoc result4 = null;
1995         Boolean JavaDoc result5 = null;
1996         Boolean JavaDoc result6 = null;
1997         support = new RelationSupport JavaDoc("id1", service, server,
1998                                       "relationTypeC", rolesC);
1999         addRelation(server, service, support, "test:type=support1");
2000         support = new RelationSupport JavaDoc("id2", service, server,
2001                                       "relationTypeC", rolesC);
2002         addRelation(server, service, support, "test:type=support2");
2003         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
2004         result1 = rs.hasRelation("id1");
2005         result2 = rs.hasRelation("id2");
2006         result3 = rs.hasRelation("id3");
2007         rs.removeRelation("id2");
2008         result4 = rs.hasRelation("id1");
2009         result5 = rs.hasRelation("id2");
2010         result6 = rs.hasRelation("id3");
2011         assertEquals(true, result1.booleanValue());
2012         assertEquals(true, result2.booleanValue());
2013         assertEquals(false, result3.booleanValue());
2014         assertEquals(true, result4.booleanValue());
2015         assertEquals(false, result5.booleanValue());
2016         assertEquals(false, result6.booleanValue());
2017      }
2018      finally
2019      {
2020         MBeanServerFactory.releaseMBeanServer(server);
2021      }
2022   }
2023
2024   /**
2025    * Test Has Relation Errors
2026    */

2027   public void testHasRelationErrors() throws Exception JavaDoc
2028   {
2029      RelationService JavaDoc rs = new RelationService JavaDoc(true);
2030
2031      boolean caught = false;
2032      try
2033      {
2034         rs.hasRelation(null);
2035      }
2036      catch(IllegalArgumentException JavaDoc e)
2037      {
2038         caught = true;
2039      }
2040      if (caught == false)
2041         fail("hasRelation allows null relation id");
2042   }
2043
2044   /**
2045    * Test Is Active
2046    */

2047   public void testIsActive() throws Exception JavaDoc
2048   {
2049      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2050      try
2051      {
2052         RelationService JavaDoc rs = null;
2053         boolean caught = false;
2054         try
2055         {
2056            rs = new RelationService JavaDoc(true);
2057            rs.isActive();
2058         }
2059         catch (RelationServiceNotRegisteredException JavaDoc e)
2060         {
2061            caught = true;
2062         }
2063         catch (Exception JavaDoc e)
2064         {
2065            fail(e.toString());
2066         }
2067         assertEquals(true, caught);
2068
2069         ObjectName JavaDoc name = null;
2070         name = new ObjectName JavaDoc("test:type = rs");
2071         server.registerMBean(rs, name);
2072         rs.isActive();
2073
2074         caught = false;
2075         try
2076         {
2077            server.unregisterMBean(name);
2078            rs.isActive();
2079         }
2080         catch (RelationServiceNotRegisteredException JavaDoc e)
2081         {
2082            caught = true;
2083         }
2084         if (caught == false)
2085            fail("FAILS IN RI: Relation Service still reports itself active.");
2086      }
2087      finally
2088      {
2089         MBeanServerFactory.releaseMBeanServer(server);
2090      }
2091   }
2092
2093   /**
2094    * Test Is Relation
2095    */

2096   public void testIsRelationExternal() throws Exception JavaDoc
2097   {
2098      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2099      try
2100      {
2101         ObjectName JavaDoc service = createRelationService("test:type=service", server);
2102         createRelationTypeC(service);
2103         createRolesC(server);
2104         RelationSupport JavaDoc support = null;
2105         String JavaDoc result1 = null;
2106         String JavaDoc result2 = null;
2107         String JavaDoc result3 = null;
2108         String JavaDoc result4 = null;
2109         String JavaDoc result5 = null;
2110         String JavaDoc result6 = null;
2111         support = new RelationSupport JavaDoc("id1", service, server,
2112                                       "relationTypeC", rolesC);
2113         addRelation(server, service, support, "test:type=support1");
2114         support = new RelationSupport JavaDoc("id2", service, server,
2115                                       "relationTypeC", rolesC);
2116         addRelation(server, service, support, "test:type=support2");
2117         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
2118         result1 = rs.isRelation(new ObjectName JavaDoc("test:type=support1"));
2119         result2 = rs.isRelation(new ObjectName JavaDoc("test:type=support2"));
2120         result3 = rs.isRelation(new ObjectName JavaDoc("test:type=support3"));
2121         rs.removeRelation("id2");
2122         result4 = rs.isRelation(new ObjectName JavaDoc("test:type=support1"));
2123         result5 = rs.isRelation(new ObjectName JavaDoc("test:type=support2"));
2124         result6 = rs.isRelation(new ObjectName JavaDoc("test:type=support3"));
2125         assertEquals("id1", result1);
2126         assertEquals("id2", result2);
2127         assertEquals(null, result3);
2128         assertEquals("id1", result4);
2129         assertEquals(null, result5);
2130         assertEquals(null, result6);
2131      }
2132      finally
2133      {
2134         MBeanServerFactory.releaseMBeanServer(server);
2135      }
2136   }
2137
2138   /**
2139    * Test Is Relation Errors
2140    */

2141   public void testIsRelationErrors() throws Exception JavaDoc
2142   {
2143      RelationService JavaDoc rs = new RelationService JavaDoc(true);
2144
2145      boolean caught = false;
2146      try
2147      {
2148         rs.isRelation(null);
2149      }
2150      catch(IllegalArgumentException JavaDoc e)
2151      {
2152         caught = true;
2153      }
2154      if (caught == false)
2155         fail("isRelation allows null relation id");
2156   }
2157
2158   /**
2159    * Test Is Relation MBean
2160    */

2161   public void testIsRelationMBeanExternal() throws Exception JavaDoc
2162   {
2163      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2164      try
2165      {
2166         ObjectName JavaDoc service = createRelationService("test:type=service", server);
2167         createRelationTypeC(service);
2168         createRolesC(server);
2169         RelationSupport JavaDoc support = null;
2170         ObjectName JavaDoc result1 = null;
2171         ObjectName JavaDoc result2 = null;
2172         ObjectName JavaDoc on1 = null;
2173         ObjectName JavaDoc on2 = null;
2174         support = new RelationSupport JavaDoc("id1", service, server,
2175                                       "relationTypeC", rolesC);
2176         addRelation(server, service, support, "test:type=support1");
2177         support = new RelationSupport JavaDoc("id2", service, server,
2178                                       "relationTypeC", rolesC);
2179         addRelation(server, service, support, "test:type=support2");
2180         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
2181         result1 = rs.isRelationMBean("id1");
2182         result2 = rs.isRelationMBean("id2");
2183         on1 = new ObjectName JavaDoc("test:type=support1");
2184         on2 = new ObjectName JavaDoc("test:type=support2");
2185         assertEquals(on1, result1);
2186         assertEquals(on2, result2);
2187      }
2188      finally
2189      {
2190         MBeanServerFactory.releaseMBeanServer(server);
2191      }
2192   }
2193
2194   /**
2195    * Test Is Relation MBean Errors
2196    */

2197   public void testIsRelationMBeanErrors() throws Exception JavaDoc
2198   {
2199      RelationService JavaDoc rs = new RelationService JavaDoc(true);
2200
2201      boolean caught = false;
2202      try
2203      {
2204         rs.isRelationMBean(null);
2205      }
2206      catch(IllegalArgumentException JavaDoc e)
2207      {
2208         caught = true;
2209      }
2210      if (caught == false)
2211         fail("isRelationMBean allows null relation id");
2212
2213      caught = false;
2214      try
2215      {
2216         rs.isRelationMBean("rubbish");
2217      }
2218      catch(RelationNotFoundException JavaDoc e)
2219      {
2220         caught = true;
2221      }
2222      if (caught == false)
2223         fail("isRelationMBean allows non-existent relation");
2224   }
2225
2226   /**
2227    * Test purge Relations Automatically
2228    */

2229   public void testPurgeRelationsAutomaticExternal() throws Exception JavaDoc
2230   {
2231      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2232      try
2233      {
2234         ObjectName JavaDoc service = createRelationService("test:type=service", server);
2235         createRelationTypeC(service);
2236         createRolesC(server);
2237         RelationSupport JavaDoc support = null;
2238         ObjectName JavaDoc on = null;
2239         Listener JavaDoc listener = new Listener JavaDoc(RelationNotification.RELATION_MBEAN_REMOVAL);
2240         boolean result = false;
2241         support = new RelationSupport JavaDoc("id1", service, server,
2242                                       "relationTypeC", rolesC);
2243         addRelation(server, service, support, "test:type=support1");
2244         server.addNotificationListener(service, listener, null, null);
2245         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
2246         server.unregisterMBean(new ObjectName JavaDoc("x:relation=c,role=2,bean=1"));
2247         on = new ObjectName JavaDoc("test:type=support1");
2248         result = rs.hasRelation("id1").booleanValue();
2249         assertEquals(false, result);
2250         RelationNotification JavaDoc rn = listener.check(1);
2251         assertEquals(new ArrayList JavaDoc(), rn.getMBeansToUnregister());
2252         assertEquals(on, rn.getObjectName());
2253         assertEquals("id1", rn.getRelationId());
2254         assertEquals("relationTypeC", rn.getRelationTypeName());
2255      }
2256      finally
2257      {
2258         MBeanServerFactory.releaseMBeanServer(server);
2259      }
2260   }
2261
2262   /**
2263    * Test purge Relations Manually
2264    */

2265   public void testPurgeRelationsManuallyExternal() throws Exception JavaDoc
2266   {
2267      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2268      try
2269      {
2270         ObjectName JavaDoc service = createRelationService("test:type=service", server);
2271         createRelationTypeC(service);
2272         createRolesC(server);
2273         RelationSupport JavaDoc support = null;
2274         ObjectName JavaDoc on = null;
2275         Listener JavaDoc listener = new Listener JavaDoc(RelationNotification.RELATION_MBEAN_REMOVAL);
2276         boolean result = false;
2277         RelationService JavaDoc rs = null;
2278         support = new RelationSupport JavaDoc("id1", service, server,
2279                                       "relationTypeC", rolesC);
2280         addRelation(server, service, support, "test:type=support1");
2281         server.addNotificationListener(service, listener, null, null);
2282         rs = (RelationService JavaDoc) services.get(service);
2283         rs.setPurgeFlag(false);
2284         server.unregisterMBean(new ObjectName JavaDoc("x:relation=c,role=2,bean=1"));
2285         on = new ObjectName JavaDoc("test:type=support1");
2286         result = rs.hasRelation("id1").booleanValue();
2287 
2288         assertEquals(true, result);
2289         RelationNotification JavaDoc rn = listener.check(0);
2290
2291         rs.purgeRelations();
2292         result = rs.hasRelation("id1").booleanValue();
2293         assertEquals(false, result);
2294         rn = listener.check(1);
2295         assertEquals(new ArrayList JavaDoc(), rn.getMBeansToUnregister());
2296         assertEquals(on, rn.getObjectName());
2297         assertEquals("id1", rn.getRelationId());
2298         assertEquals("relationTypeC", rn.getRelationTypeName());
2299      }
2300      finally
2301      {
2302         MBeanServerFactory.releaseMBeanServer(server);
2303      }
2304   }
2305
2306   /**
2307    * Test purge relations errors
2308    */

2309   public void testPurgeRelationsErrors() throws Exception JavaDoc
2310   {
2311      RelationService JavaDoc rs = new RelationService JavaDoc(true);
2312
2313      boolean caught = false;
2314      try
2315      {
2316         rs.purgeRelations();
2317      }
2318      catch (RelationServiceNotRegisteredException JavaDoc e)
2319      {
2320         caught = true;
2321      }
2322      if (caught == false)
2323         fail("purgeRelations allowed when not registered");
2324   }
2325
2326   /**
2327    * Test remove relation
2328    */

2329   public void testRemoveRelationExternal() throws Exception JavaDoc
2330   {
2331      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2332      try
2333      {
2334         ObjectName JavaDoc service = createRelationService("test:type=service", server);
2335         createRelationTypeA(service);
2336         createRolesA(server);
2337         createRelationTypeB(service);
2338         createRolesB(server);
2339         createRelationTypeC(service);
2340         createRolesC(server);
2341         createRelationTypeCX(service);
2342         createRolesCX(server);
2343         List JavaDoc result = null;
2344         RelationSupport JavaDoc supportA1 = new RelationSupport JavaDoc("ida1", service, server,
2345                                          "relationTypeA", rolesA);
2346         RelationSupport JavaDoc supportA2 = new RelationSupport JavaDoc("ida2", service, server,
2347                                          "relationTypeA", rolesA);
2348         RelationSupport JavaDoc supportCX = new RelationSupport JavaDoc("idcx", service, server,
2349                                          "relationTypeCX", rolesCX);
2350         RelationSupport JavaDoc supportC = new RelationSupport JavaDoc("idc", service, server,
2351                                          "relationTypeC", rolesC);
2352         addRelation(server, service, supportA1, "test:type=supportA1");
2353         addRelation(server, service, supportA2, "test:type=supportA2");
2354         addRelation(server, service, supportCX, "test:type=supportCX");
2355         addRelation(server, service, supportC, "test:type=supportC");
2356         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
2357         rs.removeRelation("idcx");
2358         result = rs.getAllRelationIds();
2359         assertEquals(3, result.size());
2360         assertEquals(true, result.contains("ida1"));
2361         assertEquals(true, result.contains("ida2"));
2362         assertEquals(true, result.contains("idc"));
2363         assertEquals(false, result.contains("idcx"));
2364      }
2365      finally
2366      {
2367         MBeanServerFactory.releaseMBeanServer(server);
2368      }
2369   }
2370
2371   /**
2372    * Test remove relation errors
2373    */

2374   public void testRemoveRelationErrors() throws Exception JavaDoc
2375   {
2376      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2377      try
2378      {
2379         ObjectName JavaDoc service = createRelationService("test:type=serviceA", null);
2380         RelationService JavaDoc rs = null;
2381         rs = (RelationService JavaDoc) services.get(service);
2382
2383         boolean caught = false;
2384         try
2385         {
2386            rs.removeRelation("RelationId");
2387         }
2388         catch (RelationServiceNotRegisteredException JavaDoc e)
2389         {
2390            caught = true;
2391         }
2392         if (caught == false)
2393            fail("removeRelation allowed when not registered");
2394
2395         service = createRelationService("test:type=service", server);
2396         createRelationTypeA(service);
2397         createRolesA(server);
2398         RelationSupport JavaDoc supportA1 = new RelationSupport JavaDoc("ida1", service, server,
2399                                       "relationTypeA", rolesA);
2400         addRelation(server, service, supportA1, "test:type=supportA1");
2401         rs = (RelationService JavaDoc) services.get(service);
2402
2403         caught = false;
2404         try
2405         {
2406            rs.removeRelation(null);
2407         }
2408         catch (IllegalArgumentException JavaDoc e)
2409         {
2410            caught = true;
2411         }
2412         if (caught == false)
2413            fail("removeRelation accepts a null relation");
2414
2415         caught = false;
2416         try
2417         {
2418            rs.removeRelation("rubbish");
2419         }
2420         catch (RelationNotFoundException JavaDoc e)
2421         {
2422            caught = true;
2423         }
2424         if (caught == false)
2425            fail("removeRelation accepts a non existent relation");
2426      }
2427      finally
2428      {
2429         MBeanServerFactory.releaseMBeanServer(server);
2430      }
2431   }
2432
2433   /**
2434    * Test remove relation type
2435    */

2436   public void testRemoveRelationType() throws Exception JavaDoc
2437   {
2438      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2439      try
2440      {
2441         RelationService JavaDoc rs = new RelationService JavaDoc(true);
2442         assertEquals(0, rs.getAllRelationTypeNames().size());
2443
2444         RoleInfo JavaDoc roleInfo1 = null;
2445         RoleInfo JavaDoc roleInfo2 = null;
2446         RoleInfo JavaDoc[] roleInfos = null;
2447         ObjectName JavaDoc name = new ObjectName JavaDoc("test:type = rs");
2448         server.registerMBean(rs, name);
2449         roleInfo1 = new RoleInfo JavaDoc("roleInfo1", Trivial.class.getName());
2450         roleInfo2 = new RoleInfo JavaDoc("roleInfo2", Trivial.class.getName());
2451         roleInfos = new RoleInfo JavaDoc[] { roleInfo1, roleInfo2 };
2452         rs.createRelationType("name1", roleInfos);
2453         rs.createRelationType("name2", roleInfos);
2454         rs.createRelationType("name3", roleInfos);
2455         rs.removeRelationType("name3");
2456
2457         ArrayList JavaDoc result = (ArrayList JavaDoc) rs.getAllRelationTypeNames();
2458         assertEquals(2, result.size());
2459         assertEquals(true, result.contains("name1"));
2460         assertEquals(true, result.contains("name2"));
2461         assertEquals(false, result.contains("name3"));
2462      }
2463      finally
2464      {
2465         MBeanServerFactory.releaseMBeanServer(server);
2466      }
2467   }
2468
2469   /**
2470    * Test remove relation type errors
2471    */

2472   public void testRemoveRelationTypeErrors() throws Exception JavaDoc
2473   {
2474      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2475      try
2476      {
2477         RelationService JavaDoc rs = null;
2478         RoleInfo JavaDoc roleInfo1 = null;
2479         RoleInfo JavaDoc roleInfo2 = null;
2480         RoleInfo JavaDoc[] roleInfos = null;
2481         rs = new RelationService JavaDoc(true);
2482         roleInfo1 = new RoleInfo JavaDoc("roleInfo1", Trivial.class.getName());
2483         roleInfo2 = new RoleInfo JavaDoc("roleInfo2", Trivial.class.getName());
2484         roleInfos = new RoleInfo JavaDoc[] { roleInfo1, roleInfo2 };
2485         rs.createRelationType("name1", roleInfos);
2486
2487         boolean caught = false;
2488         try
2489         {
2490            rs.removeRelationType("name1");
2491         }
2492         catch (RelationServiceNotRegisteredException JavaDoc e)
2493         {
2494            caught = true;
2495         }
2496         if (caught == false)
2497            fail("Remove relation type allowed when not registered, why not?");
2498
2499         server.registerMBean(rs, new ObjectName JavaDoc("test:type=RelationService"));
2500
2501         caught = false;
2502         try
2503         {
2504            rs.removeRelationType(null);
2505         }
2506         catch (IllegalArgumentException JavaDoc e)
2507         {
2508            caught = true;
2509         }
2510         if (caught == false)
2511            fail("Remove relation type allows null relation type name");
2512
2513         caught = false;
2514         try
2515         {
2516            rs.removeRelationType("rubbish");
2517         }
2518         catch (RelationTypeNotFoundException JavaDoc e)
2519         {
2520            caught = true;
2521         }
2522         if (caught == false)
2523            fail("Remove relation type allows non-existent relation type name");
2524      }
2525      finally
2526      {
2527         MBeanServerFactory.releaseMBeanServer(server);
2528      }
2529   }
2530
2531   /**
2532    * Test send relation creation notification
2533    */

2534   public void testSendRelationCreationNotificationExternal() throws Exception JavaDoc
2535   {
2536      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2537      try
2538      {
2539         ObjectName JavaDoc service = createRelationService("test:type=service", server);
2540         createRelationTypeC(service);
2541         createRolesC(server);
2542         RelationSupport JavaDoc support = null;
2543         ObjectName JavaDoc on = null;
2544         Listener JavaDoc listener = new Listener JavaDoc(RelationNotification.RELATION_MBEAN_CREATION);
2545         support = new RelationSupport JavaDoc("id1", service, server,
2546                                       "relationTypeC", rolesC);
2547         addRelation(server, service, support, "test:type=support1");
2548         server.addNotificationListener(service, listener, null, null);
2549         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
2550         rs.sendRelationCreationNotification("id1");
2551         on = new ObjectName JavaDoc("test:type=support1");
2552         RelationNotification JavaDoc rn = listener.check(1);
2553         assertEquals(new ArrayList JavaDoc(), rn.getMBeansToUnregister());
2554         assertEquals(new ArrayList JavaDoc(), rn.getNewRoleValue());
2555         assertEquals(on, rn.getObjectName());
2556         assertEquals(new ArrayList JavaDoc(), rn.getOldRoleValue());
2557         assertEquals("id1", rn.getRelationId());
2558         assertEquals("relationTypeC", rn.getRelationTypeName());
2559         assertEquals(null, rn.getRoleName());
2560      }
2561      finally
2562      {
2563         MBeanServerFactory.releaseMBeanServer(server);
2564      }
2565   }
2566
2567   /**
2568    * Test send relation removal notification errors
2569    */

2570   public void testSendRelationCreationNotificationErrors() throws Exception JavaDoc
2571   {
2572      RelationService JavaDoc rs = new RelationService JavaDoc(true);
2573
2574      boolean caught = false;
2575      try
2576      {
2577         rs.sendRelationCreationNotification(null);
2578      }
2579      catch (IllegalArgumentException JavaDoc e)
2580      {
2581         caught = true;
2582      }
2583      if (caught == false)
2584         fail("sendRelationCreationNotification allows null relation id");
2585
2586      caught = false;
2587      try
2588      {
2589         rs.sendRelationCreationNotification("rubbish");
2590      }
2591      catch (RelationNotFoundException JavaDoc e)
2592      {
2593         caught = true;
2594      }
2595      if (caught == false)
2596         fail("sendRelationCreationNotification allows invalid relation id");
2597   }
2598
2599   /**
2600    * Test send relation removal notification
2601    */

2602   public void testSendRelationRemovalNotificationExternal() throws Exception JavaDoc
2603   {
2604      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2605      try
2606      {
2607         ObjectName JavaDoc service = createRelationService("test:type=service", server);
2608         createRelationTypeC(service);
2609         createRolesC(server);
2610         RelationSupport JavaDoc support = null;
2611         ObjectName JavaDoc on = null;
2612         ArrayList JavaDoc test = new ArrayList JavaDoc();
2613         Listener JavaDoc listener = new Listener JavaDoc(RelationNotification.RELATION_MBEAN_REMOVAL);
2614         support = new RelationSupport JavaDoc("id1", service, server,
2615                                          "relationTypeC", rolesC);
2616         addRelation(server, service, support, "test:type=support1");
2617         server.addNotificationListener(service, listener, null, null);
2618         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
2619         test.add(new ObjectName JavaDoc("test:type=test"));
2620         rs.sendRelationRemovalNotification("id1", test);
2621         on = new ObjectName JavaDoc("test:type=support1");
2622         RelationNotification JavaDoc rn = listener.check(1);
2623         assertEquals(test, rn.getMBeansToUnregister());
2624         assertEquals(new ArrayList JavaDoc(), rn.getNewRoleValue());
2625         assertEquals(on, rn.getObjectName());
2626         assertEquals(new ArrayList JavaDoc(), rn.getOldRoleValue());
2627         assertEquals("id1", rn.getRelationId());
2628         assertEquals("relationTypeC", rn.getRelationTypeName());
2629         assertEquals(null, rn.getRoleName());
2630      }
2631      finally
2632      {
2633         MBeanServerFactory.releaseMBeanServer(server);
2634      }
2635   }
2636
2637   /**
2638    * Test send relation removal notification errors
2639    */

2640   public void testSendRelationRemovalNotificationErrors() throws Exception JavaDoc
2641   {
2642      RelationService JavaDoc rs = new RelationService JavaDoc(true);
2643
2644      boolean caught = false;
2645      try
2646      {
2647         rs.sendRelationRemovalNotification(null, new ArrayList JavaDoc());
2648      }
2649      catch (IllegalArgumentException JavaDoc e)
2650      {
2651         caught = true;
2652      }
2653      if (caught == false)
2654         fail("sendRelationRemovalNotification allows null relation id");
2655
2656
2657      caught = false;
2658      try
2659      {
2660         rs.sendRelationRemovalNotification("rubbish", new ArrayList JavaDoc());
2661      }
2662      catch (RelationNotFoundException JavaDoc e)
2663      {
2664         caught = true;
2665      }
2666      if (caught == false)
2667         fail("sendRelationRemovalNotification allows invalid relation id");
2668   }
2669
2670   /**
2671    * Test send role update notification
2672    */

2673   public void testSendRoleUpdateNotificationExternal() throws Exception JavaDoc
2674   {
2675      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2676      try
2677      {
2678         ObjectName JavaDoc service = createRelationService("test:type=service", server);
2679         createRelationTypeC(service);
2680         createRolesB(server);
2681         createRolesC(server);
2682         RelationSupport JavaDoc support = null;
2683         ObjectName JavaDoc on = null;
2684         ArrayList JavaDoc test = new ArrayList JavaDoc();
2685         Listener JavaDoc listener = new Listener JavaDoc(RelationNotification.RELATION_MBEAN_UPDATE);
2686         support = new RelationSupport JavaDoc("id1", service, server,
2687                                          "relationTypeC", rolesC);
2688         addRelation(server, service, support, "test:type=support1");
2689         server.addNotificationListener(service, listener, null, null);
2690         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
2691         test.add(new ObjectName JavaDoc("test:type=test"));
2692         rs.sendRoleUpdateNotification("id1", roleB1, test);
2693         on = new ObjectName JavaDoc("test:type=support1");
2694         RelationNotification JavaDoc rn = listener.check(1);
2695         assertEquals(new ArrayList JavaDoc(), rn.getMBeansToUnregister());
2696         assertEquals(roleB1.getRoleValue(), rn.getNewRoleValue());
2697         assertEquals(on, rn.getObjectName());
2698         assertEquals(test, rn.getOldRoleValue());
2699         assertEquals("id1", rn.getRelationId());
2700         assertEquals("relationTypeC", rn.getRelationTypeName());
2701         assertEquals("roleB1", rn.getRoleName());
2702      }
2703      finally
2704      {
2705         MBeanServerFactory.releaseMBeanServer(server);
2706      }
2707   }
2708
2709   /**
2710    * Test send role update notification errors
2711    */

2712   public void testSendRoleUpdateNotificationErrors() throws Exception JavaDoc
2713   {
2714      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2715      try
2716      {
2717         ObjectName JavaDoc service = createRelationService("test:type=service", server);
2718         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
2719         createRelationTypeB(service);
2720         createRolesB(server);
2721
2722         boolean caught = false;
2723         try
2724         {
2725            rs.sendRoleUpdateNotification(null, roleB1, new ArrayList JavaDoc());
2726         }
2727         catch (IllegalArgumentException JavaDoc e)
2728         {
2729            caught = true;
2730         }
2731         if (caught == false)
2732            fail("sendRoleUpdateNotification allows null relation id");
2733
2734         RoleList JavaDoc roleList = new RoleList JavaDoc();
2735         roleList.add(roleB1);
2736         roleList.add(roleB2);
2737         rs.createRelation("relationId", "relationTypeB", roleList);
2738
2739         caught = false;
2740         try
2741         {
2742            rs.sendRoleUpdateNotification("relationId", null, new ArrayList JavaDoc());
2743         }
2744         catch (IllegalArgumentException JavaDoc e)
2745         {
2746            caught = true;
2747         }
2748         if (caught == false)
2749            fail("sendRoleUpdateNotification allows null role");
2750
2751
2752         caught = false;
2753         try
2754         {
2755            rs.sendRoleUpdateNotification("rubbish", roleB1, new ArrayList JavaDoc());
2756         }
2757         catch (RelationNotFoundException JavaDoc e)
2758         {
2759            caught = true;
2760         }
2761         if (caught == false)
2762            fail("sendRoleUpdateNotification allows invalid relation id");
2763      }
2764      finally
2765      {
2766         MBeanServerFactory.releaseMBeanServer(server);
2767      }
2768   }
2769
2770   /**
2771    * Test set a role
2772    */

2773   public void testSetRoleExternal() throws Exception JavaDoc
2774   {
2775      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2776      try
2777      {
2778         ObjectName JavaDoc service = createRelationService("test:type=service", server);
2779         createRelationTypeC(service);
2780         createRolesC(server);
2781         createRolesCX(server);
2782         RelationSupport JavaDoc support = null;
2783         ObjectName JavaDoc on = null;
2784         Listener JavaDoc listener = new Listener JavaDoc(RelationNotification.RELATION_MBEAN_UPDATE);
2785         support = new RelationSupport JavaDoc("id1", service, server,
2786                                          "relationTypeC", rolesC);
2787         addRelation(server, service, support, "test:type=support1");
2788         server.addNotificationListener(service, listener, null, null);
2789         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
2790         rs.setRole("id1", roleCX2);
2791         on = new ObjectName JavaDoc("test:type=support1");
2792         RoleList JavaDoc shouldBe = new RoleList JavaDoc();
2793         shouldBe.add(roleC1);
2794         shouldBe.add(roleCX2);
2795         compare(shouldBe, support.retrieveAllRoles());
2796         RelationNotification JavaDoc rn = listener.check(1);
2797         assertEquals(new ArrayList JavaDoc(), rn.getMBeansToUnregister());
2798         assertEquals(roleCX2.getRoleValue(), rn.getNewRoleValue());
2799         assertEquals(on, rn.getObjectName());
2800         assertEquals(roleC2.getRoleValue(), rn.getOldRoleValue());
2801         assertEquals("id1", rn.getRelationId());
2802         assertEquals("relationTypeC", rn.getRelationTypeName());
2803         assertEquals("roleC2", rn.getRoleName());
2804      }
2805      finally
2806      {
2807         MBeanServerFactory.releaseMBeanServer(server);
2808      }
2809   }
2810
2811   /**
2812    * Test set role errors
2813    */

2814   public void testSetRoleErrors() throws Exception JavaDoc
2815   {
2816      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2817      try
2818      {
2819         ObjectName JavaDoc service = createRelationService("test:type=service", server);
2820         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
2821         createRelationTypeB(service);
2822         createRolesB(server);
2823         createRelationTypeC(service);
2824         createRolesC(server);
2825         createRolesCZ(server);
2826         createRolesCZZ(server);
2827         RoleList JavaDoc roles = new RoleList JavaDoc();
2828         roles.add(roleC1);
2829         roles.add(roleC2);
2830         rs.createRelation("relationId", "relationTypeC", roles);
2831
2832         boolean caught = false;
2833         try
2834         {
2835            rs.setRole(null, roleC2);
2836         }
2837         catch(IllegalArgumentException JavaDoc e)
2838         {
2839            caught = true;
2840         }
2841         if (caught == false)
2842            fail("setRole allows null relation id");
2843        
2844         caught = false;
2845         try
2846         {
2847            rs.setRole("relationId", null);
2848         }
2849         catch(IllegalArgumentException JavaDoc e)
2850         {
2851            caught = true;
2852         }
2853         if (caught == false)
2854            fail("setRole allows null role");
2855        
2856         caught = false;
2857         try
2858         {
2859            rs.setRole("rubbish", roleC2);
2860         }
2861         catch(RelationNotFoundException JavaDoc e)
2862         {
2863            caught = true;
2864         }
2865         if (caught == false)
2866            fail("setRole allows invalid relation id");
2867        
2868         caught = false;
2869         try
2870         {
2871            rs.setRole("relationId", roleB1);
2872         }
2873         catch(RoleNotFoundException JavaDoc e)
2874         {
2875            caught = true;
2876         }
2877         if (caught == false)
2878            fail("setRole allows invalid role name");
2879        
2880         caught = false;
2881         try
2882         {
2883            rs.setRole("relationId", roleC1);
2884         }
2885         catch(RoleNotFoundException JavaDoc e)
2886         {
2887            caught = true;
2888         }
2889         if (caught == false)
2890            fail("setRole allows non-writable role");
2891
2892         caught = false;
2893         try
2894         {
2895            rs.setRole("relationId", roleCZ2);
2896         }
2897         catch(InvalidRoleValueException JavaDoc e)
2898         {
2899            caught = true;
2900         }
2901         if (caught == false)
2902            fail("setRole allows a role below the minimum");
2903        
2904         caught = false;
2905         try
2906         {
2907            rs.setRole("relationId", roleCZZ);
2908         }
2909         catch(InvalidRoleValueException JavaDoc e)
2910         {
2911            caught = true;
2912         }
2913         if (caught == false)
2914            fail("setRole allows a role above the maximum");
2915        
2916         caught = false;
2917         try
2918         {
2919            rs.setRole("relationId", roleCZZZ);
2920         }
2921         catch(InvalidRoleValueException JavaDoc e)
2922         {
2923            caught = true;
2924         }
2925         if (caught == false)
2926            fail("setRole allows a role with unregistered beans");
2927
2928         server.unregisterMBean(service);
2929         caught = false;
2930         try
2931         {
2932            rs.setRole("relationId", roleC2);
2933         }
2934         catch(RelationServiceNotRegisteredException JavaDoc e)
2935         {
2936            caught = true;
2937         }
2938         if (caught == false)
2939            fail("FAILS IN RI: setRole allowed when not registered");
2940      }
2941      finally
2942      {
2943         MBeanServerFactory.releaseMBeanServer(server);
2944      }
2945   }
2946
2947   /**
2948    * Test set roles
2949    * @info.todo different permutations
2950    */

2951   public void testSetRolesExternal() throws Exception JavaDoc
2952   {
2953      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2954      try
2955      {
2956         ObjectName JavaDoc service = createRelationService("test:type=service", server);
2957         createRelationTypeC(service);
2958         createRolesC(server);
2959         createRolesCX(server);
2960         RelationSupport JavaDoc support = null;
2961         Listener JavaDoc listener = new Listener JavaDoc(RelationNotification.RELATION_MBEAN_UPDATE);
2962         RoleList JavaDoc shouldBe = new RoleList JavaDoc();
2963         shouldBe.add(roleC1);
2964         shouldBe.add(roleCX2);
2965         support = new RelationSupport JavaDoc("id1", service, server,
2966                                          "relationTypeC", rolesC);
2967         addRelation(server, service, support, "test:type=support1");
2968         server.addNotificationListener(service, listener, null, null);
2969         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
2970            
2971         rs.setRoles("id1", shouldBe);
2972         compare(shouldBe, support.retrieveAllRoles());
2973         listener.check(1);
2974      }
2975      finally
2976      {
2977         MBeanServerFactory.releaseMBeanServer(server);
2978      }
2979   }
2980
2981   /**
2982    * Test set roles errors
2983    */

2984   public void testSetRolesErrors() throws Exception JavaDoc
2985   {
2986      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
2987      try
2988      {
2989         ObjectName JavaDoc service = createRelationService("test:type=service", server);
2990         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
2991         createRelationTypeC(service);
2992         createRolesC(server);
2993         RoleList JavaDoc roles = new RoleList JavaDoc();
2994         roles.add(roleC1);
2995         roles.add(roleC2);
2996         rs.createRelation("relationId", "relationTypeC", roles);
2997         RoleList JavaDoc newRoles = new RoleList JavaDoc();
2998         newRoles.add(roleC2);
2999
3000         boolean caught = false;
3001         try
3002         {
3003            rs.setRoles(null, newRoles);
3004         }
3005         catch(IllegalArgumentException JavaDoc e)
3006         {
3007            caught = true;
3008         }
3009         if (caught == false)
3010            fail("setRoles allows null relation id");
3011        
3012         caught = false;
3013         try
3014         {
3015            rs.setRole("relationId", null);
3016         }
3017         catch(IllegalArgumentException JavaDoc e)
3018         {
3019            caught = true;
3020         }
3021         if (caught == false)
3022            fail("setRoles allows null role list");
3023        
3024         caught = false;
3025         try
3026         {
3027            rs.setRoles("rubbish", newRoles);
3028         }
3029         catch(RelationNotFoundException JavaDoc e)
3030         {
3031            caught = true;
3032         }
3033         if (caught == false)
3034            fail("setRoles allows invalid relation id");
3035
3036         server.unregisterMBean(service);
3037         caught = false;
3038         try
3039         {
3040            rs.setRoles("relationId", newRoles);
3041         }
3042         catch(RelationServiceNotRegisteredException JavaDoc e)
3043         {
3044            caught = true;
3045         }
3046         if (caught == false)
3047            fail("FAILS IN RI: setRoles allowed when not registered");
3048      }
3049      finally
3050      {
3051         MBeanServerFactory.releaseMBeanServer(server);
3052      }
3053   }
3054
3055   /**
3056    * Test update role map errors
3057    */

3058   public void testUpdateRoleMapErrors() throws Exception JavaDoc
3059   {
3060      MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
3061      try
3062      {
3063         ObjectName JavaDoc service = createRelationService("test:type=service", server);
3064         RelationService JavaDoc rs = (RelationService JavaDoc) services.get(service);
3065         createRelationTypeB(service);
3066         createRolesB(server);
3067         RoleList JavaDoc roleList = new RoleList JavaDoc();
3068         roleList.add(roleB1);
3069         roleList.add(roleB2);
3070         rs.createRelation("relationId", "relationTypeB", roleList);
3071
3072         boolean caught = false;
3073         try
3074         {
3075            rs.updateRoleMap(null, roleB1, new ArrayList JavaDoc());
3076         }
3077         catch (IllegalArgumentException JavaDoc e)
3078         {
3079            caught = true;
3080         }
3081         if (caught == false)
3082            fail("updateRoleMap allows null relation id");
3083
3084         caught = false;
3085         try
3086         {
3087            rs.updateRoleMap("relationId", null, new ArrayList JavaDoc());
3088         }
3089         catch (IllegalArgumentException JavaDoc e)
3090         {
3091            caught = true;
3092         }
3093         if (caught == false)
3094            fail("updateRoleMap allows null role");
3095
3096         caught = false;
3097         try
3098         {
3099            rs.updateRoleMap("rubbish", roleB1, new ArrayList JavaDoc());
3100         }
3101         catch (RelationNotFoundException JavaDoc e)
3102         {
3103            caught = true;
3104         }
3105         if (caught == false)
3106            fail("updateRoleMap allows invalid relation id");
3107
3108         server.unregisterMBean(service);
3109
3110         caught = false;
3111         try
3112         {
3113            rs.updateRoleMap("relationId", roleB1, new ArrayList JavaDoc());
3114         }
3115         catch (RelationServiceNotRegisteredException JavaDoc e)
3116         {
3117            caught = true;
3118         }
3119         if (caught == false)
3120            fail("FAILS IN RI: updateRoleMap allowed when not registered");
3121      }
3122      finally
3123      {
3124         MBeanServerFactory.releaseMBeanServer(server);
3125      }
3126   }
3127
3128   // Support -----------------------------------------------------------------
3129

3130   private ObjectName JavaDoc createRelationService(String JavaDoc name, MBeanServer JavaDoc server)
3131   {
3132      ObjectName JavaDoc result = null;
3133      RelationService JavaDoc relationService = new RelationService JavaDoc(true);
3134      try
3135      {
3136         result = new ObjectName JavaDoc(name);
3137         services.put(result, relationService);
3138         if (server !=null)
3139            server.registerMBean(relationService, result);
3140      }
3141      catch(Exception JavaDoc e)
3142      {
3143         fail(e.toString());
3144      }
3145      return result;
3146   }
3147
3148   private ObjectName JavaDoc addRelation(MBeanServer JavaDoc server, ObjectName JavaDoc service,
3149                                  RelationSupport JavaDoc support, String JavaDoc name)
3150   {
3151      ObjectName JavaDoc result = null;
3152      try
3153      {
3154         result = new ObjectName JavaDoc(name);
3155         server.registerMBean(support, result);
3156         if (service != null)
3157         {
3158            RelationService JavaDoc relationService = (RelationService JavaDoc) services.get(service);
3159            relationService.addRelation(result);
3160         }
3161      }
3162      catch(Exception JavaDoc e)
3163      {
3164         fail(e.toString());
3165      }
3166      return result;
3167   }
3168
3169   private RoleInfo JavaDoc createRoleInfo(String JavaDoc name, Class JavaDoc mbean,
3170                                   boolean read, boolean write,
3171                                   int min, int max)
3172   {
3173      RoleInfo JavaDoc result = null;
3174      try
3175      {
3176         result = new RoleInfo JavaDoc(name, mbean.getName(), read, write, min, max, "");
3177      }
3178      catch(Exception JavaDoc e)
3179      {
3180         fail(e.toString());
3181      }
3182      return result;
3183   }
3184
3185   private void createRelationType(ObjectName JavaDoc relationService, String JavaDoc name, RoleInfo JavaDoc[] roleInfos)
3186   {
3187      try
3188      {
3189         RelationService JavaDoc service = (RelationService JavaDoc) services.get(relationService);
3190         service.createRelationType(name, roleInfos);
3191      }
3192      catch(Exception JavaDoc e)
3193      {
3194         fail(e.toString());
3195      }
3196   }
3197
3198   private void compare(RoleList JavaDoc original, RoleList JavaDoc result)
3199   {
3200      assertEquals(original.size(), result.size());
3201      Iterator JavaDoc iterator = original.iterator();
3202      while (iterator.hasNext())
3203      {
3204         Role JavaDoc originalRole = (Role JavaDoc) iterator.next();
3205         Iterator JavaDoc iterator2 = result.iterator();
3206         while (iterator2.hasNext())
3207         {
3208            Role JavaDoc resultRole = (Role JavaDoc) iterator2.next();
3209            if (originalRole.getRoleName().equals(resultRole.getRoleName()))
3210            {
3211               compare(originalRole, resultRole);
3212               iterator2.remove();
3213            }
3214         }
3215      }
3216      assertEquals(0, result.size());
3217   }
3218
3219   private void compare(Role JavaDoc original, Role JavaDoc result)
3220   {
3221      assertEquals(original.getRoleName(), result.getRoleName());
3222      compareListOfObjectNames(original.getRoleValue(), result.getRoleValue());
3223   }
3224
3225   private void compareListOfObjectNames(List JavaDoc original, List JavaDoc result)
3226   {
3227      assertEquals(original.size(), result.size());
3228      Iterator JavaDoc iterator = original.iterator();
3229      while (iterator.hasNext())
3230      {
3231         ObjectName JavaDoc originalBean = (ObjectName JavaDoc) iterator.next();
3232         Iterator JavaDoc iterator2 = result.iterator();
3233         while (iterator2.hasNext())
3234         {
3235            ObjectName JavaDoc resultBean = (ObjectName JavaDoc) iterator2.next();
3236            if (originalBean.equals(resultBean))
3237            {
3238               iterator2.remove();
3239            }
3240         }
3241      }
3242      assertEquals(0, result.size());
3243   }
3244
3245   private void compareListOfStrings(List JavaDoc original, List JavaDoc result)
3246   {
3247      assertEquals(original.size(), result.size());
3248      Iterator JavaDoc iterator = original.iterator();
3249      while (iterator.hasNext())
3250      {
3251         String JavaDoc originalString = (String JavaDoc) iterator.next();
3252         Iterator JavaDoc iterator2 = result.iterator();
3253         while (iterator2.hasNext())
3254         {
3255            String JavaDoc resultString = (String JavaDoc) iterator2.next();
3256            if (originalString.equals(resultString))
3257            {
3258               iterator2.remove();
3259            }
3260         }
3261      }
3262      assertEquals(0, result.size());
3263   }
3264
3265   private ObjectName JavaDoc createRoleValueBean(String JavaDoc name, Class JavaDoc mbean, MBeanServer JavaDoc server)
3266   {
3267      ObjectName JavaDoc result = null;
3268      try
3269      {
3270         result = new ObjectName JavaDoc(name);
3271         if (server != null)
3272         {
3273            server.registerMBean(mbean.newInstance(), result);
3274         }
3275      }
3276      catch(Exception JavaDoc e)
3277      {
3278         fail(e.toString());
3279      }
3280      return result;
3281   }
3282
3283   private void checkResult(RoleResult JavaDoc result, HashMap JavaDoc infos, RoleList JavaDoc roles)
3284   {
3285      checkResolved(result.getRoles(), infos, roles);
3286      checkUnresolved(result.getRolesUnresolved(), infos, roles);
3287   }
3288
3289   private void checkResolved(RoleList JavaDoc resolved, HashMap JavaDoc infos, RoleList JavaDoc roles)
3290   {
3291      RoleList JavaDoc copy = (RoleList JavaDoc) roles.clone();
3292      Iterator JavaDoc iterator = resolved.iterator();
3293      while (iterator.hasNext())
3294      {
3295         Role JavaDoc role = (Role JavaDoc) iterator.next();
3296         String JavaDoc roleName = role.getRoleName();
3297         RoleInfo JavaDoc info = (RoleInfo JavaDoc) infos.get(roleName);
3298         if (info == null)
3299            fail("unknown role " + roleName);
3300         if (info.isReadable() == false)
3301            fail("role should not be readable " + roleName);
3302         Role JavaDoc original = removeRole(copy, roleName);
3303         compareListOfObjectNames(original.getRoleValue(), role.getRoleValue());
3304      }
3305
3306      iterator = copy.iterator();
3307      while (iterator.hasNext())
3308      {
3309         Role JavaDoc role = (Role JavaDoc) iterator.next();
3310         String JavaDoc roleName = role.getRoleName();
3311         RoleInfo JavaDoc info = (RoleInfo JavaDoc) infos.get(roleName);
3312         if (info.isReadable() == true)
3313            fail("missing role " + roleName);
3314      }
3315   }
3316
3317   private void checkUnresolved(RoleUnresolvedList JavaDoc unresolved, HashMap JavaDoc infos, RoleList JavaDoc roles)
3318   {
3319      RoleList JavaDoc copy = (RoleList JavaDoc) roles.clone();
3320      Iterator JavaDoc iterator = unresolved.iterator();
3321      while (iterator.hasNext())
3322      {
3323         RoleUnresolved JavaDoc roleUnresolved = (RoleUnresolved JavaDoc) iterator.next();
3324         String JavaDoc roleName = roleUnresolved.getRoleName();
3325         RoleInfo JavaDoc info = (RoleInfo JavaDoc) infos.get(roleName);
3326         if (info == null)
3327            fail("unknown role " + roleName);
3328         if (info.isReadable() == true)
3329            fail("role should be readable " + roleName);
3330         removeRole(copy, roleName);
3331      }
3332
3333      iterator = copy.iterator();
3334      while (iterator.hasNext())
3335      {
3336         Role JavaDoc role = (Role JavaDoc) iterator.next();
3337         String JavaDoc roleName = role.getRoleName();
3338         RoleInfo JavaDoc info = (RoleInfo JavaDoc) infos.get(roleName);
3339         if (info.isReadable() == false)
3340            fail("missing unresolved role " + roleName);
3341      }
3342   }
3343
3344   private Role JavaDoc removeRole(RoleList JavaDoc roles, String JavaDoc roleName)
3345   {
3346      Iterator JavaDoc iterator = roles.iterator();
3347      while (iterator.hasNext())
3348      {
3349         Role JavaDoc role = (Role JavaDoc) iterator.next();
3350         if (role.getRoleName().equals(roleName))
3351         {
3352            iterator.remove();
3353            return role;
3354         }
3355      }
3356      fail("role was not in the original " + roleName);
3357      return null;
3358   }
3359
3360   private Role JavaDoc getRole(RoleList JavaDoc roles, String JavaDoc roleName)
3361   {
3362      Iterator JavaDoc iterator = roles.iterator();
3363      while (iterator.hasNext())
3364      {
3365         Role JavaDoc role = (Role JavaDoc) iterator.next();
3366         if (role.getRoleName().equals(roleName))
3367         {
3368            return role;
3369         }
3370      }
3371      fail("role was not in the original " + roleName);
3372      return null;
3373   }
3374
3375   private void checkMBeans(Map JavaDoc result, RoleList JavaDoc roles)
3376   {
3377      // Construct what we think the value should be
3378
Map JavaDoc expected = calcMBeanRoleMap(roles);
3379   
3380      // Check the actual result
3381
Iterator JavaDoc iterator = result.entrySet().iterator();
3382      while (iterator.hasNext())
3383      {
3384         Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iterator.next();
3385         ObjectName JavaDoc key = (ObjectName JavaDoc) entry.getKey();
3386         ArrayList JavaDoc roleNames = (ArrayList JavaDoc) entry.getValue();
3387         ArrayList JavaDoc expectedNames = (ArrayList JavaDoc) expected.get(key);
3388         if (expectedNames == null)
3389            fail("Unexpected object name " + key);
3390         compareListOfStrings(expectedNames, roleNames);
3391         expected.remove(key);
3392      }
3393      assertEquals(0, expected.size());
3394   }
3395
3396   private Map JavaDoc calcMBeanRoleMap(RoleList JavaDoc roles)
3397   {
3398      HashMap JavaDoc result = new HashMap JavaDoc();
3399      Iterator JavaDoc iterator = roles.iterator();
3400      while (iterator.hasNext())
3401      {
3402         Role JavaDoc role = (Role JavaDoc) iterator.next();
3403         String JavaDoc roleName = role.getRoleName();
3404         ArrayList JavaDoc mbeans = (ArrayList JavaDoc) role.getRoleValue();
3405         Iterator JavaDoc iterator2 = mbeans.iterator();
3406         while (iterator2.hasNext())
3407         {
3408            ObjectName JavaDoc objectName = (ObjectName JavaDoc) iterator2.next();
3409            ArrayList JavaDoc names = (ArrayList JavaDoc) result.get(objectName);
3410            if (names == null)
3411            {
3412               names = new ArrayList JavaDoc();
3413               result.put(objectName, names);
3414            }
3415            // It seems the role name should be duplicated?
3416
// Include the following test if this is a bug in RI.
3417
// if (names.contains(roleName) == false)
3418

3419            names.add(roleName);
3420         }
3421      }
3422      return result;
3423   }
3424
3425   private void createRolesA(MBeanServer JavaDoc server)
3426   {
3427      try
3428      {
3429         ArrayList JavaDoc roleA1Values = new ArrayList JavaDoc();
3430         roleA1Values.add(createRoleValueBean("x:relation=a,role=1,bean=1",
3431                                              Trivial.class, server));
3432         Role JavaDoc roleA1 = new Role JavaDoc("roleA1", roleA1Values);
3433         rolesA = new RoleList JavaDoc();
3434         rolesA.add(roleA1);
3435      }
3436      catch(Exception JavaDoc e)
3437      {
3438         fail(e.toString());
3439      }
3440   }
3441
3442   private void createRelationTypeA(ObjectName JavaDoc relationService)
3443   {
3444      try
3445      {
3446         RoleInfo JavaDoc roleInfoA1 = createRoleInfo("roleA1", Trivial.class, true, true, 1, 1);
3447         RoleInfo JavaDoc[] roleInfos = new RoleInfo JavaDoc[] { roleInfoA1 };
3448         createRelationType(relationService, "relationTypeA", roleInfos);
3449         for (int i=0; i < roleInfos.length; i++)
3450            roleInfosA.put(roleInfos[i].getName(), roleInfos[i]);
3451      }
3452      catch(Exception JavaDoc e)
3453      {
3454         fail(e.toString());
3455      }
3456   }
3457
3458   private void createRolesB(MBeanServer JavaDoc server)
3459   {
3460      try
3461      {
3462         ArrayList JavaDoc roleB1Values = new ArrayList JavaDoc();
3463         roleB1Values.add(createRoleValueBean("x:relation=b,role=1,bean=1",
3464                                              Trivial.class, server));
3465         roleB1Values.add(createRoleValueBean("x:relation=b,role=1,bean=2",
3466                                              Trivial.class, server));
3467         roleB1 = new Role JavaDoc("roleB1", roleB1Values);
3468
3469         ArrayList JavaDoc roleB2Values = new ArrayList JavaDoc();
3470         roleB2Values.add(createRoleValueBean("x:relation=b,role=2,bean=1",
3471                                              Trivial.class, server));
3472         roleB2Values.add(createRoleValueBean("x:relation=b,role=2,bean=2",
3473                                              Trivial.class, server));
3474         roleB2Values.add(createRoleValueBean("x:relation=b,role=2,bean=3",
3475                                              Trivial.class, server));
3476         roleB2 = new Role JavaDoc("roleB2", roleB2Values);
3477
3478         rolesB = new RoleList JavaDoc();
3479         rolesB.add(roleB1);
3480         rolesB.add(roleB2);
3481      }
3482      catch(Exception JavaDoc e)
3483      {
3484         fail(e.toString());
3485      }
3486   }
3487
3488   private void createRelationTypeB(ObjectName JavaDoc relationService)
3489   {
3490      try
3491      {
3492         RoleInfo JavaDoc roleInfoB1 = createRoleInfo("roleB1", Trivial.class, true, false, 1, 2);
3493         RoleInfo JavaDoc roleInfoB2 = createRoleInfo("roleB2", Trivial.class, false, true, 3, 4);
3494         RoleInfo JavaDoc[] roleInfos = new RoleInfo JavaDoc[] { roleInfoB1, roleInfoB2 };
3495         createRelationType(relationService, "relationTypeB", roleInfos );
3496         for (int i=0; i < roleInfos.length; i++)
3497         roleInfosB.put(roleInfos[i].getName(), roleInfos[i]);
3498      }
3499      catch(Exception JavaDoc e)
3500      {
3501         fail(e.toString());
3502      }
3503   }
3504
3505   private void createRolesC(MBeanServer JavaDoc server)
3506   {
3507      try
3508      {
3509         ArrayList JavaDoc roleC1Values = new ArrayList JavaDoc();
3510         roleC1Values.add(createRoleValueBean("x:relation=c,role=1,bean=1",
3511                                              Trivial.class, server));
3512         roleC1Values.add(createRoleValueBean("x:relation=c,role=1,bean=1",
3513                                              Trivial.class, null));
3514         roleC1 = new Role JavaDoc("roleC1", roleC1Values);
3515
3516         ArrayList JavaDoc roleC2Values = new ArrayList JavaDoc();
3517         roleC2Values.add(createRoleValueBean("x:relation=c,role=1,bean=1",
3518                                              Trivial.class, null));
3519         roleC2Values.add(createRoleValueBean("x:relation=c,role=2,bean=1",
3520                                              Trivial.class, server));
3521         roleC2Values.add(createRoleValueBean("x:relation=c,role=2,bean=2",
3522                                              Trivial.class, server));
3523         roleC2 = new Role JavaDoc("roleC2", roleC2Values);
3524
3525         rolesC = new RoleList JavaDoc();
3526         rolesC.add(roleC1);
3527         rolesC.add(roleC2);
3528      }
3529      catch(Exception JavaDoc e)
3530      {
3531         fail(e.toString());
3532      }
3533   }
3534
3535   private void createRelationTypeC(ObjectName JavaDoc relationService)
3536   {
3537      try
3538      {
3539         RoleInfo JavaDoc roleInfoC1 = createRoleInfo("roleC1", Trivial.class, true, false, 1, 2);
3540         RoleInfo JavaDoc roleInfoC2 = createRoleInfo("roleC2", Trivial.class, false, true, 3, 4);
3541         RoleInfo JavaDoc[] roleInfos = new RoleInfo JavaDoc[] { roleInfoC1, roleInfoC2 };
3542         createRelationType(relationService, "relationTypeC", roleInfos );
3543         for (int i=0; i < roleInfos.length; i++)
3544            roleInfosC.put(roleInfos[i].getName(), roleInfos[i]);
3545      }
3546      catch(Exception JavaDoc e)
3547      {
3548         fail(e.toString());
3549      }
3550   }
3551
3552   private void createRolesCX(MBeanServer JavaDoc server)
3553   {
3554      try
3555      {
3556         ArrayList JavaDoc roleCX1Values = new ArrayList JavaDoc();
3557         roleCX1Values.add(createRoleValueBean("x:relation=c,role=2,bean=1",
3558                                              Trivial.class, null));
3559         roleCX1 = new Role JavaDoc("roleC1", roleCX1Values);
3560
3561         ArrayList JavaDoc roleCX2Values = new ArrayList JavaDoc();
3562         roleCX2Values.add(createRoleValueBean("x:relation=c,role=1,bean=1",
3563                                              Trivial.class, null));
3564         roleCX2Values.add(createRoleValueBean("x:relation=c,role=1,bean=2",
3565                                              Trivial.class, server));
3566         roleCX2Values.add(createRoleValueBean("x:relation=c,role=1,bean=3",
3567                                              Trivial.class, server));
3568         roleCX2Values.add(createRoleValueBean("x:relation=c,role=1,bean=4",
3569                                              Trivial.class, server));
3570         roleCX2 = new Role JavaDoc("roleC2", roleCX2Values);
3571
3572         rolesCX = new RoleList JavaDoc();
3573         rolesCX.add(roleCX1);
3574         rolesCX.add(roleCX2);
3575      }
3576      catch(Exception JavaDoc e)
3577      {
3578         fail(e.toString());
3579      }
3580   }
3581
3582   private void createRelationTypeCX(ObjectName JavaDoc relationService)
3583   {
3584      try
3585      {
3586         RoleInfo JavaDoc roleInfoCX1 = createRoleInfo("roleC1", Trivial.class, true, false, 1, 2);
3587         RoleInfo JavaDoc roleInfoCX2 = createRoleInfo("roleC2", Trivial.class, false, true, 3, 4);
3588         RoleInfo JavaDoc[] roleInfos = new RoleInfo JavaDoc[] { roleInfoCX1, roleInfoCX2 };
3589         createRelationType(relationService, "relationTypeCX", roleInfos );
3590         for (int i=0; i < roleInfos.length; i++)
3591            roleInfosCX.put(roleInfos[i].getName(), roleInfos[i]);
3592      }
3593      catch(Exception JavaDoc e)
3594      {
3595         fail(e.toString());
3596      }
3597   }
3598
3599   private void createRolesCZ(MBeanServer JavaDoc server)
3600   {
3601      try
3602      {
3603         ArrayList JavaDoc roleCZ2Values = new ArrayList JavaDoc();
3604         roleCZ2Values.add(createRoleValueBean("x:relation=c,role=1,bean=1",
3605                                              Trivial.class, null));
3606         roleCZ2 = new Role JavaDoc("roleC2", roleCZ2Values);
3607
3608         rolesCZ = new RoleList JavaDoc();
3609         rolesCZ.add(roleCZ2);
3610      }
3611      catch(Exception JavaDoc e)
3612      {
3613         fail(e.toString());
3614      }
3615   }
3616
3617   private void createRolesCZZ(MBeanServer JavaDoc server)
3618   {
3619      try
3620      {
3621         ArrayList JavaDoc roleCZZValues = new ArrayList JavaDoc();
3622         roleCZZValues.add(createRoleValueBean("x:relation=c,role=1,bean=1",
3623                                              Trivial.class, null));
3624         roleCZZValues.add(createRoleValueBean("x:relation=c,role=1,bean=2",
3625                                              Trivial.class, null));
3626         roleCZZValues.add(createRoleValueBean("x:relation=c,role=1,bean=3",
3627                                              Trivial.class, null));
3628         roleCZZValues.add(createRoleValueBean("x:relation=c,role=1,bean=4",
3629                                              Trivial.class, null));
3630         roleCZZValues.add(createRoleValueBean("x:relation=c,role=1,bean=5",
3631                                              Trivial.class, server));
3632         roleCZZ = new Role JavaDoc("roleC2", roleCZZValues);
3633
3634         rolesCZZ = new RoleList JavaDoc();
3635         rolesCZZ.add(roleCZZ);
3636
3637         ArrayList JavaDoc roleCZZZValues = new ArrayList JavaDoc();
3638         roleCZZZValues.add(createRoleValueBean("x:relation=c,role=1x,bean=1",
3639                                              Trivial.class, null));
3640         roleCZZZValues.add(createRoleValueBean("x:relation=c,role=1x,bean=2",
3641                                              Trivial.class, null));
3642         roleCZZZValues.add(createRoleValueBean("x:relation=c,role=1x,bean=3",
3643                                              Trivial.class, null));
3644         roleCZZZ = new Role JavaDoc("roleC2", roleCZZZValues);
3645
3646         rolesCZZZ = new RoleList JavaDoc();
3647         rolesCZZZ.add(roleCZZZ);
3648      }
3649      catch(Exception JavaDoc e)
3650      {
3651         fail(e.toString());
3652      }
3653   }
3654
3655   private class Listener
3656      implements NotificationListener JavaDoc
3657   {
3658      String JavaDoc type;
3659      HashSet JavaDoc notifications = new HashSet JavaDoc();
3660      public Listener(String JavaDoc type)
3661      {
3662         this.type = type;
3663      }
3664      public void handleNotification(Notification JavaDoc n, Object JavaDoc h)
3665      {
3666         notifications.add(n);
3667      }
3668      public RelationNotification JavaDoc check(int size)
3669      {
3670         RelationNotification JavaDoc result = null;
3671         assertEquals(size, notifications.size());
3672         Iterator JavaDoc iterator = notifications.iterator();
3673         while (iterator.hasNext())
3674         {
3675            RelationNotification JavaDoc rn = (RelationNotification JavaDoc) iterator.next();
3676            assertEquals(type, rn.getType());
3677            result = rn;
3678         }
3679         return result;
3680      }
3681   }
3682}
3683
Popular Tags