1 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 49 public class RolePropertyTest 50 extends TestCase 51 { 52 53 59 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 70 76 protected RoleDescription createRoleDesc(String id, String [] 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 id, String [] 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 [] roleIds, String [] expectedRolesIds){ 95 Role[] expectedRoles = roleProperty_.getRoles(expectedRolesIds); 96 Role[] resultRoles = roleProperty_.getRoles(roleProperty_.getInheritedRoleIds(roleIds)); 97 String result = ExplorerUtils.arrayToString(resultRoles); 98 String expected = ExplorerUtils.arrayToString(expectedRoles); 99 Assert.assertEquals(expected,result); 100 } 101 102 105 protected void setUp() throws Exception { 106 r0 = createRoleDesc("0",new String []{"1"}); 107 r1 = createRoleDesc("1",new String []{"3"}); 108 r2 = createRoleDesc("2",new String []{"4","5"}); 109 r3 = createRoleDesc("3",new String []{"6","10"}); 110 r4 = createRoleDesc("4",new String []{"7"}); 111 r5 = createRoleDesc("5",new String []{"8","9"}); 112 r6 = createRoleDesc("6",new String []{}); 113 r7 = createRoleDesc("7",new String []{"10","11"}); 114 r8 = createRoleDesc("8",null); 115 r9 = createRoleDesc("9",new String []{"12"}); 116 r10 = createRoleDesc("10",new String []{}); 117 r11 = createRoleDesc("11",new String []{}); 118 r12 = createRoleDesc("12",null); 119 r0bis = createRoleDesc("0",new String []{"1","4","2","1"}); 120 roleProperty_ = new RoleProperty(); 121 } 122 123 129 132 public void testConcreteRole() { 133 feedRoleDesc(new RoleDescription[]{r0,r0bis}); 134 Role r = roleProperty_.getRole("0"); 135 Assert.assertTrue(r.isConcrete()); 136 } 137 138 141 public void testMultipleDefinition() { 142 feedRoleDesc(new RoleDescription[]{r0,r0bis,r1,r2,r4}); 143 checkTreeInheritance(new String []{"0"},new String []{"0","1","4","2"}); 144 } 145 146 149 public void testInheritanceTree() { 150 feedRoleDesc(new RoleDescription[]{r0,r0bis,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12}); 151 152 checkTreeInheritance(new String []{"0"}, new String []{"0","1","4","2","3","7","5","6","10","11","8","9","12"}); 154 155 checkTreeInheritance(new String []{"1","5"}, new String []{"1","5","3","8","9","6","10","12"}); 158 159 } 160 161 164 public void testInfiniteLoop() { 165 RoleDescription role0 = createRoleDesc("0",new String []{"1"}); 166 RoleDescription role1 = createRoleDesc("1",new String []{"3"}); 167 RoleDescription role2 = createRoleDesc("2",new String []{"1"}); 168 RoleDescription role3 = createRoleDesc("3",new String []{"2"}); 169 feedRoleDesc(new RoleDescription[]{role0,role1,role2,role3}); 170 checkTreeInheritance(new String []{"0"}, new String []{"0","1","3","2"}); 171 checkTreeInheritance(new String []{"1"}, new String []{"1","3","2"}); 172 } 173 174 } | Popular Tags |