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