View Javadoc

1   /*
2    * Copyright 2007-2009 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Test the PermissionService
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
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  		// TODO - getting a SOAPFaultException on this call; fix and un-comment
65  		// assertFalse(getPermissionService().hasPermissionByTemplateName("entity124pId", "KUALI", "Default", new Map<String, String>()));
66  	}
67  	
68  	@Test
69  	public void testIsAuthorizedByTemplateName() {
70  		// assertTrue(getPermissionService().isAuthorizedByTemplateName(principalId, namespaceCode, permissionTemplateName, permissionDetails, qualification)("entity123pId", "KR-NS", "1", new Map<String, String>()));
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  		// TODO - jax-ws remoted service returns null; local return empty List. Fix webservice return
83  		assertTrue(null == assignees || assignees.size() == 0);
84  	}
85  	
86  	@Test
87  	public void testGetPermissionAssigneesForTemplateName() {
88  		/*
89  		List<PermissionAssigneeInfo> assignees = getPermissionService().getPermissionAssignees("KUALI", "Log In", null, null);
90  		assertNotNull(assignees);
91  		assertEquals(1, assignees.size());
92  		PermissionAssigneeInfo permInfo = assignees.get(0);
93  		assertEquals("entity123pId", permInfo.getPrincipalId());
94  		assignees = getPermissionService().getPermissionAssignees("KUALI", "Not A Valid Permission Name", null, null);
95  		assertNull(assignees);
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 }