View Javadoc

1   /**
2    * Copyright 2011-2013 The Kuali Foundation Licensed under the Educational
3    * Community License, Version 2.0 (the "License"); you may not use this file
4    * except in compliance with the License. You may obtain a copy of the License
5    * at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12   * License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package org.kuali.mobility.library.entity;
16  
17  
18  import org.junit.Test;
19  import static org.junit.Assert.*;
20  import org.kuali.mobility.security.group.api.Group;
21  import org.kuali.mobility.security.group.entity.GroupImpl;
22  import org.kuali.mobility.security.user.api.User;
23  import org.kuali.mobility.security.user.entity.UserImpl;
24  
25  
26  
27  /**
28   * Unit tests for library permissions
29   * @author Kuali Mobility Team (mobility.collab@kuali.org)
30   * @since 2.3.0
31   */
32  public class LibraryPermissionsTest {
33  
34  	/**
35  	 * Test that a user with the correct groups is allowed by the
36  	 * Library admin ACL.
37  	 */
38  	@Test
39  	public void testValidUserPermissions(){
40  		User user = new UserImpl();
41  		Group group = new GroupImpl();
42  		group.setName(LibraryPermissions.ADMIN);
43  		user.addGroup(group);
44  		assertTrue("User with admin permission is expected to be allowed", LibraryPermissions.ADMIN_EXPRESSION.evaluate(user)); 
45  	}
46  	
47  	/**
48  	 * Test that a user that does not have the correct groups is not allowed
49  	 * by the Library admin ACL
50  	 */
51  	@Test
52  	public void testInvalidUserPermissions(){
53  		User user = new UserImpl();
54  		Group group = new GroupImpl();
55  		group.setName("nothing_special");
56  		user.addGroup(group);
57  		assertFalse("User without admin permission not is expected to be allowed", LibraryPermissions.ADMIN_EXPRESSION.evaluate(user)); 
58  	}
59  }