View Javadoc

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