KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > core > role > RolePropertyTest


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2005 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library 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 library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================
26 $Id: RolePropertyTest.java,v 1.2 2005/07/06 15:36:01 moroy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.explorer.core.role;
30
31 import org.objectweb.util.explorer.ExplorerUtils;
32 import org.objectweb.util.explorer.core.role.api.Role;
33 import org.objectweb.util.explorer.core.role.api.RoleDescription;
34 import org.objectweb.util.explorer.core.role.lib.DefaultRoleDescription;
35 import org.objectweb.util.explorer.core.role.lib.RoleProperty;
36
37 import junit.framework.Assert;
38 import junit.framework.TestCase;
39
40 /**
41  *
42  *
43  *
44  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>,
45  * <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>.
46  *
47  * @version 0.1
48  */

49 public class RolePropertyTest
50      extends TestCase
51 {
52
53     //==================================================================
54
//
55
// Internal States.
56
//
57
// ==================================================================
58

59     /** The RoleDescription object to use to test the RoleProperty component. */
60     protected RoleDescription r0,r0bis,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12;
61     
62     protected RoleProperty roleProperty_ = null;
63     
64     // ==================================================================
65
//
66
// Constructors.
67
//
68
// ==================================================================
69

70     // ==================================================================
71
//
72
// Internal method.
73
//
74
// ==================================================================
75

76     protected RoleDescription createRoleDesc(String JavaDoc id, String JavaDoc[] inheritedRoles, boolean concrete){
77         RoleDescription r = new DefaultRoleDescription();
78         r.setId(id);
79         r.setConcrete(concrete);
80         r.setInheritance(inheritedRoles);
81         return r;
82     }
83     
84     protected RoleDescription createRoleDesc(String JavaDoc id, String JavaDoc[] inheritedRoles){
85         return createRoleDesc(id, inheritedRoles, true);
86     }
87       
88     protected void feedRoleDesc(RoleDescription[] roles){
89         for (int i = 0; i < roles.length; i++) {
90             roleProperty_.feed(roles[i]);
91         }
92     }
93     
94     protected void checkTreeInheritance(String JavaDoc[] roleIds, String JavaDoc[] expectedRolesIds){
95         Role[] expectedRoles = roleProperty_.getRoles(expectedRolesIds);
96         Role[] resultRoles = roleProperty_.getRoles(roleProperty_.getInheritedRoleIds(roleIds));
97         String JavaDoc result = ExplorerUtils.arrayToString(resultRoles);
98         String JavaDoc expected = ExplorerUtils.arrayToString(expectedRoles);
99         Assert.assertEquals(expected,result);
100     }
101     
102     /*
103      * @see TestCase#setUp()
104      */

105     protected void setUp() throws Exception JavaDoc {
106         r0 = createRoleDesc("0",new String JavaDoc[]{"1"});
107         r1 = createRoleDesc("1",new String JavaDoc[]{"3"});
108         r2 = createRoleDesc("2",new String JavaDoc[]{"4","5"});
109         r3 = createRoleDesc("3",new String JavaDoc[]{"6","10"});
110         r4 = createRoleDesc("4",new String JavaDoc[]{"7"});
111         r5 = createRoleDesc("5",new String JavaDoc[]{"8","9"});
112         r6 = createRoleDesc("6",new String JavaDoc[]{});
113         r7 = createRoleDesc("7",new String JavaDoc[]{"10","11"});
114         r8 = createRoleDesc("8",null);
115         r9 = createRoleDesc("9",new String JavaDoc[]{"12"});
116         r10 = createRoleDesc("10",new String JavaDoc[]{});
117         r11 = createRoleDesc("11",new String JavaDoc[]{});
118         r12 = createRoleDesc("12",null);
119         r0bis = createRoleDesc("0",new String JavaDoc[]{"1","4","2","1"});
120         roleProperty_ = new RoleProperty();
121     }
122         
123     // ==================================================================
124
//
125
// Public methods for ... interface.
126
//
127
// ==================================================================
128

129     /*
130      * Checks the behavior of the RoleProperty component.
131      */

132     public void testConcreteRole() {
133         feedRoleDesc(new RoleDescription[]{r0,r0bis});
134         Role r = roleProperty_.getRole("0");
135         Assert.assertTrue(r.isConcrete());
136     }
137             
138     /*
139      * Checks the behavior of the RoleProperty component.
140      */

141     public void testMultipleDefinition() {
142         feedRoleDesc(new RoleDescription[]{r0,r0bis,r1,r2,r4});
143         checkTreeInheritance(new String JavaDoc[]{"0"},new String JavaDoc[]{"0","1","4","2"});
144     }
145
146     /*
147      * Checks the behavior of the RoleProperty component.
148      */

149     public void testInheritanceTree() {
150         feedRoleDesc(new RoleDescription[]{r0,r0bis,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12});
151         
152         // Checks for {r0}
153
checkTreeInheritance(new String JavaDoc[]{"0"}, new String JavaDoc[]{"0","1","4","2","3","7","5","6","10","11","8","9","12"});
154         
155         // Checks for {r1,r5}
156
// Limit: The corresponding algorithm doesn't know the level of each role it treats
157
checkTreeInheritance(new String JavaDoc[]{"1","5"}, new String JavaDoc[]{"1","5","3","8","9","6","10","12"});
158                 
159     }
160     
161     /*
162      * Checks the behavior of the RoleProperty component.
163      */

164     public void testInfiniteLoop() {
165         RoleDescription role0 = createRoleDesc("0",new String JavaDoc[]{"1"});
166         RoleDescription role1 = createRoleDesc("1",new String JavaDoc[]{"3"});
167         RoleDescription role2 = createRoleDesc("2",new String JavaDoc[]{"1"});
168         RoleDescription role3 = createRoleDesc("3",new String JavaDoc[]{"2"});
169         feedRoleDesc(new RoleDescription[]{role0,role1,role2,role3});
170         checkTreeInheritance(new String JavaDoc[]{"0"}, new String JavaDoc[]{"0","1","3","2"});
171         checkTreeInheritance(new String JavaDoc[]{"1"}, new String JavaDoc[]{"1","3","2"});
172     }
173         
174 }
Popular Tags