View Javadoc

1   package org.itracker.model;
2   import static org.itracker.Assert.assertEntityComparator;
3   import static org.itracker.Assert.assertEntityComparatorEquals;
4   import static org.junit.Assert.assertNotNull;
5   import static org.junit.Assert.assertTrue;
6   import static org.junit.Assert.fail;
7   
8   import org.itracker.services.util.UserUtilities;
9   import org.junit.After;
10  import org.junit.Before;
11  import org.junit.Test;
12  
13  public class PermissionTest {
14  	private Permission per;
15  	
16  	@Test
17  	public void testSetUser(){
18  		try{
19  			per.setUser(null);
20  			fail("did not throw IllegalArgumentException");
21  		} catch (IllegalArgumentException e){
22  			assertTrue(true);
23  		}
24  	}
25  	
26  	@Test
27  	public void testToString(){		
28  		assertNotNull("toString", per.toString());
29  	}
30  	
31  	@Test
32  	public void testPermissionPropertiesComparator() {
33  		User userA = new User("aaa", "", "a", "a", "a@a.com", false);
34  		User userB = new User("bbb", "", "b", "b", "b@b.com", false);
35  		Project projectA = new Project("a");
36  		Project projectB = new Project("b");
37  		Permission entityA = new Permission(UserUtilities.PERMISSION_PRODUCT_ADMIN, userA);
38  		entityA.setProject(projectA);
39  		Permission entityB = new Permission(UserUtilities.PERMISSION_CREATE, userA);
40  		entityB.setProject(projectA);
41  
42  		assertEntityComparator("permission comparator", Permission.PERMISSION_PROPERTIES_COMPARATOR, entityA, entityB);
43  		assertEntityComparator("permission comparator", Permission.PERMISSION_PROPERTIES_COMPARATOR, entityA, null);
44  		assertEntityComparatorEquals("permission comparator", Permission.PERMISSION_PROPERTIES_COMPARATOR, entityA, entityA);
45  
46  		entityA.setPermissionType(entityB.getPermissionType());
47  		entityB.setUser(userB);
48  
49  		assertEntityComparator("permission comparator", Permission.PERMISSION_PROPERTIES_COMPARATOR, entityA, entityB);
50  		assertEntityComparator("permission comparator", Permission.PERMISSION_PROPERTIES_COMPARATOR, entityA, null);
51  		assertEntityComparatorEquals("permission comparator", Permission.PERMISSION_PROPERTIES_COMPARATOR, entityA, entityA);
52  		
53  		entityB.setUser(userA);
54  		entityB.setProject(projectB);
55  		
56  		assertEntityComparator("permission comparator", Permission.PERMISSION_PROPERTIES_COMPARATOR, entityA, entityB);
57  		assertEntityComparator("permission comparator", Permission.PERMISSION_PROPERTIES_COMPARATOR, entityA, null);
58  		assertEntityComparatorEquals("permission comparator", Permission.PERMISSION_PROPERTIES_COMPARATOR, entityA, entityA);
59  		
60  		entityA.setProject(entityB.getProject());
61  		
62  		assertEntityComparatorEquals("permission comparator", Permission.PERMISSION_PROPERTIES_COMPARATOR, entityA, entityB);
63  		assertEntityComparatorEquals("permission comparator", Permission.PERMISSION_PROPERTIES_COMPARATOR, entityA, entityA);
64  	}
65  	
66  	@Before
67      public void setUp() throws Exception {
68  		per = new Permission();
69      }
70  	
71  	@After
72  	public void tearDown() throws Exception {
73  		per = null;
74  	}
75  
76  }