1   // Copyright 2008 Thiago H. de Paula Figueiredo
2   //
3   // Licensed under the Apache License, Version 2.0 (the "License");
4   // you may not use this file except in compliance with the License.
5   // You may obtain a copy of the License at
6   //
7   //     http://www.apache.org/licenses/LICENSE-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,
11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  // See the License for the specific language governing permissions and
13  // limitations under the License.
14  
15  package br.com.arsmachina.authentication.entity;
16  
17  import java.util.ArrayList;
18  import java.util.List;
19  
20  import org.testng.Assert;
21  import org.testng.annotations.Test;
22  
23  /**
24   * Test class for {@link User}.
25   * 
26   * @author Thiago H. de Paula Figueiredo
27   */
28  public class UserTest {
29  
30  	@Test
31  	public void getRoles() {
32  
33  		User user = new User();
34  		user.setName("Test");
35  
36  		new ArrayList<Permission>();
37  
38  		for (int i = 0; i < 2; i++) {
39  			
40  			final PermissionGroup group = new PermissionGroup();
41  			group.setName("Group " + i);
42  			user.getPermissionGroups().add(group);
43  			
44  		}
45  
46  		for (int i = 0; i < 8; i++) {
47  
48  			final Permission permission = new Permission();
49  			permission.setName("ROLE_" + i);
50  
51  			user.getPermissionGroups().get(i % 2).getPermissions().add(permission);
52  
53  			if (i % 4 == 0) {
54  				user.getRemovedPermissions().add(permission);
55  			}
56  
57  		}
58  
59  		List<Permission> permissions = user.getPermissions(); 
60  
61  		Assert.assertEquals(permissions.size(), 6);
62  
63  		for (Permission permission : permissions) {
64  
65  			Assert.assertFalse(permission.getName().equals("ROLE_0"));
66  			Assert.assertFalse(permission.getName().equals("ROLE_4"));
67  
68  		}
69  
70  	}
71  
72  }