KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > compliance > relation > RelationServiceTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package test.compliance.relation;
9
10 import test.compliance.relation.support.Trivial;
11
12 import junit.framework.TestCase;
13
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.HashSet;
17 import java.util.Iterator;
18 import java.util.List;
19 import java.util.Map;
20
21 import javax.management.InstanceNotFoundException;
22 import javax.management.MBeanNotificationInfo;
23 import javax.management.MBeanServer;
24 import javax.management.Notification;
25 import javax.management.NotificationListener;
26 import javax.management.MBeanServerFactory;
27 import javax.management.ObjectName;
28
29 import javax.management.relation.InvalidRelationIdException;
30 import javax.management.relation.InvalidRelationServiceException;
31 import javax.management.relation.InvalidRelationTypeException;
32 import javax.management.relation.InvalidRoleValueException;
33 import javax.management.relation.RelationNotFoundException;
34 import javax.management.relation.RelationNotification;
35 import javax.management.relation.RelationService;
36 import javax.management.relation.RelationServiceNotRegisteredException;
37 import javax.management.relation.RelationSupport;
38 import javax.management.relation.RelationTypeNotFoundException;
39 import javax.management.relation.RelationTypeSupport;
40 import javax.management.relation.Role;
41 import javax.management.relation.RoleInfo;
42 import javax.management.relation.RoleInfoNotFoundException;
43 import javax.management.relation.RoleList;
44 import javax.management.relation.RoleNotFoundException;
45 import javax.management.relation.RoleResult;
46 import javax.management.relation.RoleStatus;
47 import javax.management.relation.RoleUnresolved;
48 import javax.management.relation.RoleUnresolvedList;
49
50 /**
51  * Relation Service tests
52  *
53  * //TODO test internal relations
54  * //TODO test relations as mbeans in roles
55  * //TODO test multiple relation services (avoid future mods adding static data)
56  *
57  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
58  */

59 public class RelationServiceTestCase
60    extends TestCase
61 {
62    // Constants -----------------------------------------------------------------
63

64    // Attributes ----------------------------------------------------------------
65

66    HashMap services = new HashMap();
67
68    RoleList rolesA;
69    HashMap roleInfosA = new HashMap();
70    Role roleB1;
71    Role roleB2;
72    RoleList rolesB;
73    HashMap roleInfosB = new HashMap();
74    Role roleC1;
75    Role roleC2;
76    RoleList rolesC;
77    HashMap roleInfosC = new HashMap();
78    Role roleCX1;
79    Role roleCX2;
80    RoleList rolesCX;
81    HashMap roleInfosCX = new HashMap();
82    Role roleCZ2;
83    RoleList rolesCZ;
84    HashMap roleInfosCZ = new HashMap();
85    Role roleCZZ;
86    RoleList rolesCZZ;
87    HashMap roleInfosCZZ = new HashMap();
88    Role roleCZZZ;
89    RoleList rolesCZZZ;
90    HashMap roleInfosCZZZ = new HashMap();
91
92    // Constructor ---------------------------------------------------------------
93

94    /**
95     * Construct the test
96     */

97    public RelationServiceTestCase(String s)
98    {
99       super(s);
100    }
101
102    // Tests ---------------------------------------------------------------------
103

104    /**
105     * Test the constructor
106     */

107    public void testConstructor() throws Exception
108    {
109       RelationService rs = null;
110       rs = new RelationService(true);
111       assertEquals(true, rs.getPurgeFlag());
112
113       rs = new RelationService(false);
114       assertEquals(false, rs.getPurgeFlag());
115    }
116
117    /**
118     * Test add a relation
119     */

120    public void testAddRelation() throws Exception
121    {
122       MBeanServer server = MBeanServerFactory.createMBeanServer();
123       try
124       {
125          ObjectName service = createRelationService("test:type=service", server);
126          createRelationTypeB(service);
127          createRolesB(server);
128          RelationSupport support = null;
129          ObjectName rsupp = null;
130          String result = null;
131          Listener listener = new Listener(RelationNotification.RELATION_MBEAN_CREATION);
132          RelationService rs = (RelationService) services.get(service);
133          server.addNotificationListener(service, listener, null, null);
134          support = new RelationSupport("id", service, server, "relationTypeB",
135                                        rolesB);
136          rsupp = new ObjectName("test:add=relation");
137          server.registerMBean(support, rsupp);
138          rs.addRelation(rsupp);
139          result = rs.isRelation(rsupp);
140          assertEquals("id", result);
141          listener.check(1);
142       }
143       finally
144       {
145          MBeanServerFactory.releaseMBeanServer(server);
146       }
147    }
148
149    /**
150     * Test add a relation errors
151     */

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

322    public void testAddRelationType() throws Exception
323    {
324       RoleInfo roleInfo1 = null;
325       RoleInfo roleInfo2 = null;
326       RoleInfo[] roleInfos = null;
327       RelationService rs = null;
328       ArrayList result = null;
329       RoleInfo result1 = null;
330       RoleInfo result2 = null;
331       roleInfo1 = new RoleInfo("roleInfo1", Trivial.class.getName());
332       roleInfo2 = new RoleInfo("roleInfo2", Trivial.class.getName());
333       roleInfos = new RoleInfo[] { roleInfo1, roleInfo2 };
334       RelationTypeSupport rtsupp = new RelationTypeSupport("RelationTypeName",
335                                                   roleInfos);
336       rs = new RelationService(true);
337       rs.addRelationType(rtsupp);
338       result = (ArrayList) rs.getRoleInfos("RelationTypeName");
339       result1 = rs.getRoleInfo("RelationTypeName", "roleInfo1");
340       result2 = rs.getRoleInfo("RelationTypeName", "roleInfo2");
341
342       // Check the roleInfos
343
assertEquals(2, result.size());
344       assertEquals(roleInfo1.toString(), result1.toString());
345       assertEquals(roleInfo2.toString(), result2.toString());
346    }
347
348    /**
349     * Test create relation type errors
350     */

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

439    public void testCheckRoleReadingExternal() throws Exception
440    {
441       MBeanServer server = MBeanServerFactory.createMBeanServer();
442       try
443       {
444          ObjectName service = createRelationService("test:type=service", server);
445          createRelationTypeB(service);
446          createRolesB(server);
447          RelationSupport support = null;
448          Integer readB1 = null;
449          Integer readB2 = null;
450          RelationService rs = (RelationService) services.get(service);
451          support = new RelationSupport("id", service, server,
452                                           "relationTypeB", rolesB);
453          addRelation(server, service, support, "test:type=support");
454          readB1 = rs.checkRoleReading("roleB1", "relationTypeB");
455          readB2 = rs.checkRoleReading("roleB2", "relationTypeB");
456
457          assertEquals(0, readB1.intValue());
458          assertEquals(RoleStatus.ROLE_NOT_READABLE, readB2.intValue());
459       }
460       finally
461       {
462          MBeanServerFactory.releaseMBeanServer(server);
463       }
464    }
465
466    /**
467     * Test check role reading errors
468     */

469    public void testCheckRoleReadingErrors() throws Exception
470    {
471       ObjectName service = createRelationService("test:type=service", null);
472       RelationService rs = (RelationService) services.get(service);
473       createRelationTypeB(service);
474       createRolesB(null);
475
476       boolean caught = false;
477       try
478       {
479          rs.checkRoleReading(null, "relationTypeB");
480       }
481       catch(IllegalArgumentException e)
482       {
483          caught = true;
484       }
485       if (caught == false)
486          fail("checkRoleReading allows null role name");
487
488       caught = false;
489       try
490       {
491          rs.checkRoleReading("roleB1", null);
492       }
493       catch(IllegalArgumentException e)
494       {
495          caught = true;
496       }
497       if (caught == false)
498          fail("checkRoleReading allows null relation name");
499
500       caught = false;
501       try
502       {
503          rs.checkRoleReading("roleB1", "rubbish");
504       }
505       catch(RelationTypeNotFoundException e)
506       {
507          caught = true;
508       }
509       if (caught == false)
510          fail("checkRoleReading allows invalid relation type name");
511    }
512
513    /**
514     * Test check role writing
515     */

516    public void testCheckRoleWritingExternal() throws Exception
517    {
518       MBeanServer server = MBeanServerFactory.createMBeanServer();
519       try
520       {
521          ObjectName service = createRelationService("test:type=service", server);
522          createRelationTypeB(service);
523          createRolesB(server);
524          RelationSupport support = null;
525          Integer writeB1normal = null;
526          Integer writeB2normal = null;
527          Integer writeB1init = null;
528          Integer writeB2init = null;
529          RelationService rs = (RelationService) services.get(service);
530          support = new RelationSupport("id", service, server,
531                                        "relationTypeB", rolesB);
532          addRelation(server, service, support, "test:type=support");
533          writeB1normal = rs.checkRoleWriting(roleB1, "relationTypeB", new Boolean(false));
534          writeB2normal = rs.checkRoleWriting(roleB2, "relationTypeB", new Boolean(false));
535          writeB1init = rs.checkRoleWriting(roleB1, "relationTypeB", new Boolean(true));
536          writeB2init = rs.checkRoleWriting(roleB2, "relationTypeB", new Boolean(true));
537          assertEquals(RoleStatus.ROLE_NOT_WRITABLE, writeB1normal.intValue());
538          assertEquals(0, writeB2normal.intValue());
539          assertEquals(0, writeB1init.intValue());
540          assertEquals(0, writeB2init.intValue());
541       }
542       finally
543       {
544          MBeanServerFactory.releaseMBeanServer(server);
545       }
546    }
547
548    /**
549     * Test check role writing errors
550     */

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

610    public void testCreateRelation() throws Exception
611    {
612       MBeanServer server = MBeanServerFactory.createMBeanServer();
613       try
614       {
615          ObjectName service = createRelationService("test:type=service", server);
616          createRelationTypeB(service);
617          createRolesB(server);
618          RelationSupport support = null;
619          Listener listener = new Listener(RelationNotification.RELATION_BASIC_CREATION);
620          RelationService rs = (RelationService) services.get(service);
621          server.addNotificationListener(service, listener, null, null);
622          rs.createRelation("id", "relationTypeB", rolesB);
623          boolean result = rs.hasRelation("id").booleanValue();
624          assertEquals(true, result);
625          listener.check(1);
626       }
627       finally
628       {
629          MBeanServerFactory.releaseMBeanServer(server);
630       }
631    }
632
633    /**
634     * Test create relation errors
635     */

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

781    public void testCreationRelationType() throws Exception
782    {
783       RoleInfo roleInfo1 = null;
784       RoleInfo roleInfo2 = null;
785       RoleInfo[] roleInfos = null;
786       RelationService rs = null;
787       ArrayList result = null;
788       RoleInfo result1 = null;
789       RoleInfo result2 = null;
790       roleInfo1 = new RoleInfo("roleInfo1", Trivial.class.getName());
791       roleInfo2 = new RoleInfo("roleInfo2", Trivial.class.getName());
792       roleInfos = new RoleInfo[] { roleInfo1, roleInfo2 };
793       rs = new RelationService(true);
794       rs.createRelationType("RelationTypeName", roleInfos);
795       result = (ArrayList) rs.getRoleInfos("RelationTypeName");
796       result1 = rs.getRoleInfo("RelationTypeName", "roleInfo1");
797       result2 = rs.getRoleInfo("RelationTypeName", "roleInfo2");
798
799       // Check the roleInfos
800
assertEquals(2, result.size());
801       assertEquals(roleInfo1.toString(), result1.toString());
802       assertEquals(roleInfo2.toString(), result2.toString());
803    }
804
805    /**
806     * Test create relation type errors
807     */

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

904    public void testGetRoleInfoErrors() throws Exception
905    {
906       RoleInfo roleInfo1 = null;
907       RoleInfo roleInfo2 = null;
908       RoleInfo[] roleInfos = null;
909       RelationService rs = null;
910       ArrayList result = null;