Revision a784f00f
Added by Katja Luther about 14 years ago
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/UserServiceImplTest.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.cdm.api.service; |
11 | 11 |
|
12 | 12 |
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.HashSet; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Set; |
|
13 | 17 |
import java.util.UUID; |
14 | 18 |
|
15 | 19 |
import org.joda.time.DateTime; |
16 | 20 |
import org.junit.Assert; |
17 | 21 |
import org.junit.Before; |
18 | 22 |
import org.junit.Test; |
19 |
import org.springframework.security.Authentication; |
|
20 |
import org.springframework.security.AuthenticationManager; |
|
21 |
import org.springframework.security.GrantedAuthority; |
|
22 |
import org.springframework.security.context.SecurityContextHolder; |
|
23 |
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
|
23 |
import org.springframework.security.core.Authentication;
|
|
24 |
import org.springframework.security.authentication.AuthenticationManager;
|
|
25 |
import org.springframework.security.core.GrantedAuthority;
|
|
26 |
import org.springframework.security.core.context.SecurityContextHolder;
|
|
27 |
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
24 | 28 |
import org.unitils.dbunit.annotation.DataSet; |
25 | 29 |
import org.unitils.spring.annotation.SpringBeanByType; |
26 | 30 |
|
... | ... | |
36 | 40 |
@SpringBeanByType |
37 | 41 |
private IUserService userService; |
38 | 42 |
|
39 |
private GrantedAuthority[] expectedRoles;
|
|
43 |
private Set<GrantedAuthority> expectedRoles;
|
|
40 | 44 |
private UsernamePasswordAuthenticationToken token; |
41 | 45 |
|
42 | 46 |
@Before |
43 | 47 |
public void setUp() { |
44 |
expectedRoles = new GrantedAuthority[4];
|
|
48 |
expectedRoles = new HashSet<GrantedAuthority>();
|
|
45 | 49 |
GrantedAuthorityImpl publish = new GrantedAuthorityImpl(); |
46 | 50 |
publish.setAuthority("Publish"); |
47 | 51 |
publish.setUuid(UUID.fromString("441a3c40-0c84-11de-8c30-0800200c9a66")); |
... | ... | |
58 | 62 |
checkAnnotation.setAuthority("CheckAnnotation"); |
59 | 63 |
checkAnnotation.setUuid(UUID.fromString("e5354c0e-657b-4b4d-bb2f-791612199711")); |
60 | 64 |
checkAnnotation.setCreated(new DateTime(2009,2,3,17,52,26,0)); |
61 |
expectedRoles[3] = publish;
|
|
62 |
expectedRoles[2] = edit;
|
|
63 |
expectedRoles[0] = annotate;
|
|
64 |
expectedRoles[1] = checkAnnotation;
|
|
65 |
expectedRoles.add(publish);
|
|
66 |
expectedRoles.add(edit);
|
|
67 |
expectedRoles.add(annotate);
|
|
68 |
expectedRoles.add(checkAnnotation);
|
|
65 | 69 |
token = new UsernamePasswordAuthenticationToken("ben","sPePhAz6"); |
66 | 70 |
} |
67 | 71 |
|
... | ... | |
76 | 80 |
|
77 | 81 |
Assert.assertEquals(principal.getUsername(),"ben"); |
78 | 82 |
|
79 |
Assert.assertArrayEquals(expectedRoles, authentication.getAuthorities()); |
|
83 |
Assert.assertNotNull(expectedRoles); |
|
84 |
Assert.assertEquals(expectedRoles.size(), authentication.getAuthorities().size()); |
|
80 | 85 |
} |
81 | 86 |
|
82 | 87 |
@Test |
Also available in: Unified diff
merge cate-development2 branch with trunk