01: package info.jtrac.domain;
02:
03: import java.util.Arrays;
04: import java.util.HashSet;
05: import java.util.Set;
06:
07: import junit.framework.TestCase;
08:
09: import org.acegisecurity.GrantedAuthority;
10:
11: public class UserTest extends TestCase {
12:
13: public void testGetAuthoritiesFromUserSpaceRoles() {
14:
15: Space s1 = new Space();
16: s1.setPrefixCode("SPACE-ONE");
17:
18: User u = new User();
19: u.setLoginName("test");
20:
21: u.addSpaceWithRole(s1, "ROLE_ONE-ONE");
22: u.addSpaceWithRole(s1, "ROLE_ONE-TWO");
23: u.addSpaceWithRole(null, "ROLE_ADMIN");
24: u.setId(1);
25:
26: GrantedAuthority[] gas = u.getAuthorities();
27:
28: Set<String> set = new HashSet<String>();
29: for (GrantedAuthority ga : gas) {
30: set.add(ga.getAuthority());
31: }
32:
33: assertEquals(4, gas.length);
34:
35: assertTrue(set.contains("ROLE_USER"));
36: assertTrue(set.contains("ROLE_ONE-ONE_SPACE-ONE"));
37: assertTrue(set.contains("ROLE_ONE-TWO_SPACE-ONE"));
38: assertTrue(set.contains("ROLE_ADMIN"));
39:
40: }
41:
42: public void testCheckIfAdminForAllSpaces() {
43: User u = new User();
44: u.setLoginName("test");
45: u.addSpaceWithRole(null, "ROLE_ADMIN");
46: assertTrue(u.isAdminForAllSpaces());
47: }
48:
49: }
|