1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.service.impl;
17
18 import com.google.common.collect.Maps;
19 import org.junit.Test;
20 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
21 import org.kuali.rice.kim.api.KimApiConstants;
22 import org.kuali.rice.kim.api.role.RoleService;
23 import org.kuali.rice.kim.impl.role.RoleServiceImpl;
24 import org.kuali.rice.kim.test.KIMTestCase;
25
26 import javax.xml.namespace.QName;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33 import static org.junit.Assert.assertTrue;
34
35
36 public class RoleServiceImplTest extends KIMTestCase {
37
38 private RoleService roleService;
39
40 public void setUp() throws Exception {
41 super.setUp();
42 roleService = (RoleService) GlobalResourceLoader.getService(
43 new QName(KimApiConstants.Namespaces.KIM_NAMESPACE_2_0, KimApiConstants.ServiceNames.ROLE_SERVICE_SOAP));
44 }
45
46 @Test
47 public void testPrincipaHasRoleOfDirectAssignment() {
48 List <String>roleIds = new ArrayList<String>();
49 roleIds.add("r1");
50 assertTrue( "p1 has direct role r1", roleService.principalHasRole("p1", roleIds, Collections
51 .<String, String>emptyMap() ));
52
53 Map<String, String> qualification = new HashMap<String, String>();
54 qualification.put("Attribute 2", "CHEM");
55 assertTrue( "p1 has direct role r1 with rp2 attr data", roleService.principalHasRole("p1", roleIds, qualification));
56 qualification.clear();
57
58
59 qualification.put("Attribute 3", "PHYS");
60 assertTrue( "p1 has direct role r1 with rp2 attr data", roleService.principalHasRole("p1", roleIds, Maps.newHashMap(
61 qualification)));
62 }
63
64 @Test
65 public void testPrincipalHasRoleOfHigherLevel() {
66
67 List <String>roleIds = new ArrayList<String>();
68 roleIds.add("r2");
69 assertTrue( "p1 has assigned in higher level role r1", roleService.principalHasRole("p1", roleIds, Collections.<String, String>emptyMap() ));
70 }
71
72 @Test
73 public void testPrincipalHasRoleContainsGroupAssigned() {
74
75 List <String>roleIds = new ArrayList<String>();
76 roleIds.add("r2");
77 assertTrue( "p2 is assigned to g1 and g1 assigned to r2", roleService.principalHasRole("p2", roleIds, Collections.<String, String>emptyMap() ));
78 }
79
80
81
82
83
84
85 @Test (expected=IllegalArgumentException.class)
86 public void testCircularRoleAssignment() {
87 Map<String, String> map = new HashMap<String, String>();
88 List <String>roleIds = new ArrayList<String>();
89 roleIds.add("r1");
90 roleService.assignRoleToRole("r5", "AUTH_SVC_TEST2", "RoleThree", map);
91 }
92 }