View Javadoc

1   /**
2    * Copyright 2005-2011 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.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   * Test the PermissionService
35   * 
36   * @author Kuali Rice Team (rice.collab@kuali.org)
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"));
53  		assertTrue(getPermissionService().hasPermission("entity123pId", "KR-NS", "perm2"));
54  		assertFalse(getPermissionService().hasPermission("entity124pId", "KR-NS", "perm2"));
55  	}
56  	
57  	@Test
58  	public void testIsAuthorized() {
59  		assertTrue(getPermissionService().isAuthorized("entity123pId", "KR-NS", "perm1", new HashMap<String, String>()));
60  		assertTrue(getPermissionService().isAuthorized("entity123pId", "KR-NS", "perm2", new HashMap<String, String>()));
61  		assertFalse(getPermissionService().isAuthorized("entity124pId", "KR-NS", "perm2", new HashMap<String, String>()));
62  	}
63  	
64  	@Test
65  	public void testHasPermissionByTemplateName() {
66  		assertTrue(getPermissionService().hasPermissionByTemplate("entity123pId", "KUALI", "Default",
67                  new HashMap<String, String>()));
68  		// TODO - getting a SOAPFaultException on this call; fix and un-comment
69  		// assertFalse(getPermissionService().hasPermissionByTemplate("entity124pId", "KUALI", "Default", new Map<String, String>()));
70  	}
71  	
72  	@Test
73  	public void testIsAuthorizedByTemplateName() {
74  		// assertTrue(getPermissionService().isAuthorizedByTemplate(principalId, namespaceCode, permissionTemplateName, permissionDetails, qualification)("entity123pId", "KR-NS", "1", new Map<String, String>()));
75  	}
76  	
77  	@Test
78  	public void testGetPermissionAssignees() {
79  		
80  		List<Assignee> assignees = getPermissionService().getPermissionAssignees("KUALI", "Log In Kuali Portal", 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());
86  		// TODO - jax-ws remoted service returns null; local return empty List. Fix webservice return
87  		assertTrue(null == assignees || assignees.size() == 0);
88  	}
89  	
90  	@Test
91  	public void testGetPermissionAssigneesForTemplateName() {
92  		/*
93  		List<PermissionAssigneeInfo> assignees = getPermissionService().getPermissionAssignees("KUALI", "Log In", null, null);
94  		assertNotNull(assignees);
95  		assertEquals(1, assignees.size());
96  		PermissionAssigneeInfo permInfo = assignees.get(0);
97  		assertEquals("entity123pId", permInfo.getPrincipalId());
98  		assignees = getPermissionService().getPermissionAssignees("KUALI", "Not A Valid Permission Name", null, null);
99  		assertNull(assignees);
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 }