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