1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.test.service;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.List;
21
22 import org.junit.Test;
23 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
24 import org.kuali.rice.kim.service.KIMServiceLocator;
25 import org.kuali.rice.kim.service.RoleService;
26 import org.kuali.rice.kim.test.KIMTestCase;
27
28
29
30
31
32
33
34 public class RoleServiceTest extends KIMTestCase {
35
36 private RoleService roleService;
37
38 public void setUp() throws Exception {
39 super.setUp();
40 setRoleService(KIMServiceLocator.getRoleService());
41 }
42
43 @Test
44 public void testPrincipaHasRoleOfDirectAssignment() {
45 List <String>roleIds = new ArrayList<String>();
46 roleIds.add("r1");
47 assertTrue( "p1 has direct role r1", getRoleService().principalHasRole("p1", roleIds, null ));
48
49 AttributeSet qualification = new AttributeSet();
50 qualification.put("Attribute 2", "CHEM");
51 assertTrue( "p1 has direct role r1 with rp2 attr data", getRoleService().principalHasRole("p1", roleIds, qualification ));
52 qualification.clear();
53
54
55 qualification.put("Attribute 3", "PHYS");
56 assertTrue( "p1 has direct role r1 with rp2 attr data", getRoleService().principalHasRole("p1", roleIds, qualification ));
57 }
58
59 @Test
60 public void testPrincipalHasRoleOfHigherLevel() {
61
62 List <String>roleIds = new ArrayList<String>();
63 roleIds.add("r2");
64 assertTrue( "p1 has assigned in higher level role r1", getRoleService().principalHasRole("p1", roleIds, null ));
65 }
66
67 @Test
68 public void testPrincipalHasRoleContainsGroupAssigned() {
69
70 List <String>roleIds = new ArrayList<String>();
71 roleIds.add("r2");
72 assertTrue( "p2 is assigned to g1 and g1 assigned to r2", getRoleService().principalHasRole("p2", roleIds, null ));
73 }
74
75 @Test
76 public void testGetPrincipalsFromCircularRoles() {
77
78 List <String>roleIds = new ArrayList<String>();
79 Collection <String>rolePrincipalIds = null;
80 roleIds.add("r101");
81 rolePrincipalIds = getRoleService().getRoleMemberPrincipalIds("ADDL_ROLES_TESTS", "Role A", null);
82 assertNotNull(rolePrincipalIds);
83 assertEquals("RoleTwo should have 6 principal ids", 6, rolePrincipalIds.size());
84 }
85
86 public RoleService getRoleService() {
87 return this.roleService;
88 }
89
90 public void setRoleService(RoleService roleService) {
91 this.roleService = roleService;
92 }
93
94 }