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 com.google.common.collect.Maps;
19 import org.junit.Test;
20 import org.kuali.rice.kim.api.role.RoleService;
21 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
22 import org.kuali.rice.kim.test.KIMTestCase;
23 import org.kuali.rice.test.BaselineTestCase;
24
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30
31 import static org.junit.Assert.*;
32
33
34
35
36
37
38
39 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
40 public class RoleServiceTest extends KIMTestCase {
41
42 private RoleService roleService;
43
44 public void setUp() throws Exception {
45 super.setUp();
46 setRoleService(KimApiServiceLocator.getRoleService());
47 }
48
49 @Test
50 public void testPrincipaHasRoleOfDirectAssignment() {
51 List <String>roleIds = new ArrayList<String>();
52 roleIds.add("r1");
53 assertTrue( "p1 has direct role r1", getRoleService().principalHasRole("p1", roleIds, null ));
54
55 Map<String, String> qualification = new HashMap<String, String>();
56 qualification.put("Attribute 2", "CHEM");
57 assertTrue( "p1 has direct role r1 with rp2 attr data", getRoleService().principalHasRole("p1", roleIds,
58 qualification));
59 qualification.clear();
60
61
62 qualification.put("Attribute 3", "PHYS");
63 assertTrue( "p1 has direct role r1 with rp2 attr data", getRoleService().principalHasRole("p1", roleIds, Maps.newHashMap(
64 qualification)));
65 }
66
67 @Test
68 public void testPrincipalHasRoleOfHigherLevel() {
69
70 List <String>roleIds = new ArrayList<String>();
71 roleIds.add("r2");
72 assertTrue( "p1 has assigned in higher level role r1", getRoleService().principalHasRole("p1", roleIds, null ));
73 }
74
75 @Test
76 public void testPrincipalHasRoleContainsGroupAssigned() {
77
78 List <String>roleIds = new ArrayList<String>();
79 roleIds.add("r2");
80 assertTrue( "p2 is assigned to g1 and g1 assigned to r2", getRoleService().principalHasRole("p2", roleIds, null ));
81 }
82
83 @Test
84 public void testGetPrincipalsFromCircularRoles() {
85
86 List <String>roleIds = new ArrayList<String>();
87 Collection <String>rolePrincipalIds;
88 roleIds.add("r101");
89 rolePrincipalIds = getRoleService().getRoleMemberPrincipalIds("ADDL_ROLES_TESTS", "Role A", null);
90 assertNotNull(rolePrincipalIds);
91 assertEquals("RoleTwo should have 6 principal ids", 5, rolePrincipalIds.size());
92 }
93
94 public RoleService getRoleService() {
95 return this.roleService;
96 }
97
98 public void setRoleService(RoleService roleService) {
99 this.roleService = roleService;
100 }
101
102 }