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.ArrayList;
19  import java.util.Collection;
20  import java.util.List;
21  
22  import org.junit.Test;
23  import org.kuali.rice.kim.bo.types.dto.AttributeSet;
24  import org.kuali.rice.kim.service.KIMServiceLocator;
25  import org.kuali.rice.kim.service.RoleService;
26  import org.kuali.rice.kim.test.KIMTestCase;
27  
28  /**
29   * Test the RoleService
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   *
33   */
34  public class RoleServiceTest extends KIMTestCase {
35  
36  	private RoleService roleService;
37  
38  	public void setUp() throws Exception {
39  		super.setUp();
40  		setRoleService(KIMServiceLocator.getRoleService());
41  	}
42  	
43  	@Test
44  	public void testPrincipaHasRoleOfDirectAssignment() {
45  		List <String>roleIds = new ArrayList<String>();
46  		roleIds.add("r1");
47  		assertTrue( "p1 has direct role r1", getRoleService().principalHasRole("p1", roleIds, null ));	
48  		//assertFalse( "p4 has no direct/higher level role r1", getRoleService().principalHasRole("p4", roleIds, null ));	
49  		AttributeSet qualification = new AttributeSet();
50  		qualification.put("Attribute 2", "CHEM");
51  		assertTrue( "p1 has direct role r1 with rp2 attr data", getRoleService().principalHasRole("p1", roleIds, qualification ));	
52  		qualification.clear();
53  		//requested qualification rolls up to a higher element in some hierarchy 
54  		// method not implemented yet, not quite clear how this works
55  		qualification.put("Attribute 3", "PHYS");
56  		assertTrue( "p1 has direct role r1 with rp2 attr data", getRoleService().principalHasRole("p1", roleIds, qualification ));	
57  	}
58  
59  	@Test
60  	public void testPrincipalHasRoleOfHigherLevel() {
61  		// "p3" is in "r2" and "r2 contains "r1"
62  		List <String>roleIds = new ArrayList<String>();
63  		roleIds.add("r2");
64  		assertTrue( "p1 has assigned in higher level role r1", getRoleService().principalHasRole("p1", roleIds, null ));		
65  	}
66  	
67  	@Test
68  	public void testPrincipalHasRoleContainsGroupAssigned() {
69  		// "p2" is in "g1" and "g1" assigned to "r2"
70  		List <String>roleIds = new ArrayList<String>();
71  		roleIds.add("r2");
72  		assertTrue( "p2 is assigned to g1 and g1 assigned to r2", getRoleService().principalHasRole("p2", roleIds, null ));		
73  	}
74  
75  	@Test
76  	public void testGetPrincipalsFromCircularRoles() {
77  		// "p2" is in "g1" and "g1" assigned to "r2"
78  		List <String>roleIds = new ArrayList<String>();
79  		Collection <String>rolePrincipalIds = null;
80  		roleIds.add("r101");
81  		rolePrincipalIds = getRoleService().getRoleMemberPrincipalIds("ADDL_ROLES_TESTS", "Role A", null);
82  		assertNotNull(rolePrincipalIds);
83  		assertEquals("RoleTwo should have 6 principal ids", 6, rolePrincipalIds.size());
84  	}
85  	
86  	public RoleService getRoleService() {
87  		return this.roleService;
88  	}
89  
90  	public void setRoleService(RoleService roleService) {
91  		this.roleService = roleService;
92  	}
93  
94  }