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 org.junit.Test;
19 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
20 import org.kuali.rice.kim.bo.role.dto.PermissionAssigneeInfo;
21 import org.kuali.rice.kim.impl.common.template.TemplateBo;
22 import org.kuali.rice.kim.impl.permission.PermissionBo;
23 import org.kuali.rice.kim.service.PermissionService;
24 import org.kuali.rice.kim.test.KIMTestCase;
25
26 import java.util.HashMap;
27 import java.util.List;
28
29 import static org.junit.Assert.*;
30
31
32
33
34
35
36
37 public class PermissionServiceTest extends KIMTestCase {
38
39 private PermissionService permissionService;
40
41 @Override
42 public void setUp() throws Exception {
43 super.setUp();
44 setPermissionService(KimApiServiceLocator.getPermissionService());
45 }
46
47 @Test
48 public void testHasPermission() {
49 assertTrue(getPermissionService().hasPermission("entity123pId", "KR-NS", "perm1", new HashMap<String, String>()));
50 assertTrue(getPermissionService().hasPermission("entity123pId", "KR-NS", "perm2", new HashMap<String, String>()));
51 assertFalse(getPermissionService().hasPermission("entity124pId", "KR-NS", "perm2", new HashMap<String, String>()));
52 }
53
54 @Test
55 public void testIsAuthorized() {
56 assertTrue(getPermissionService().isAuthorized("entity123pId", "KR-NS", "perm1", new HashMap<String, String>(), new HashMap<String, String>()));
57 assertTrue(getPermissionService().isAuthorized("entity123pId", "KR-NS", "perm2", new HashMap<String, String>(), new HashMap<String, String>()));
58 assertFalse(getPermissionService().isAuthorized("entity124pId", "KR-NS", "perm2", new HashMap<String, String>(), new HashMap<String, String>()));
59 }
60
61 @Test
62 public void testHasPermissionByTemplateName() {
63 assertTrue(getPermissionService().hasPermissionByTemplateName("entity123pId", "KUALI", "Default", new HashMap<String, String>()));
64
65
66 }
67
68 @Test
69 public void testIsAuthorizedByTemplateName() {
70
71 }
72
73 @Test
74 public void testGetPermissionAssignees() {
75
76 List<PermissionAssigneeInfo> assignees = getPermissionService().getPermissionAssignees("KUALI", "Log In Kuali Portal", null, null);
77 assertNotNull(assignees);
78 assertEquals(1, assignees.size());
79 PermissionAssigneeInfo permInfo = assignees.get(0);
80 assertEquals("entity123pId", permInfo.getPrincipalId());
81 assignees = getPermissionService().getPermissionAssignees("KUALI", "Not A Valid Permission Name", null, null);
82
83 assertTrue(null == assignees || assignees.size() == 0);
84 }
85
86 @Test
87 public void testGetPermissionAssigneesForTemplateName() {
88
89
90
91
92
93
94
95
96
97 }
98
99 @Test
100 public void testIsPermissionDefined() {
101 }
102
103 @Test
104 public void testIsPermissionDefinedForTemplateName() {
105 }
106
107 @Test
108 public void testGetAuthorizedPermissions() {
109 }
110
111 @Test
112 public void testGetAuthorizedPermissionsByTemplateName() {
113 }
114
115 @Test
116 public void testGetPermission() {
117 PermissionBo permissionBo = PermissionBo.from(getPermissionService().getPermission("p1"));
118
119 assertNotNull(permissionBo);
120 assertEquals("perm1", permissionBo.getName());
121 assertEquals("KR-NS", permissionBo.getNamespaceCode());
122 assertEquals(0, permissionBo.getDetails().size());
123 assertTrue(permissionBo.isActive());
124
125 TemplateBo templateBo = permissionBo.getTemplate();
126 assertNotNull(templateBo);
127 assertTrue(templateBo.isActive());
128 assertEquals("1", templateBo.getKimTypeId());
129 assertEquals("Default", templateBo.getName());
130 assertEquals("KUALI", templateBo.getNamespaceCode());
131
132 permissionBo = PermissionBo.from(getPermissionService().getPermission("p0"));
133 assertNull(permissionBo);
134 }
135
136 @Test
137 public void testGetPermissionsByTemplateName() {
138 }
139
140 @Test
141 public void testGetPermissionsByName() {
142 }
143
144 @Test
145 public void testLookupPermissions() {
146 }
147
148 @Test
149 public void testGetRoleIdsForPermission() {
150 }
151
152 @Test
153 public void testGetRoleIdsForPermissions() {
154 }
155
156 @Test
157 public void testGetPermissionDetailLabel() {
158 }
159
160 public PermissionService getPermissionService() {
161 return this.permissionService;
162 }
163
164 public void setPermissionService(PermissionService permissionService) {
165 this.permissionService = permissionService;
166 }
167
168 }