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