1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.providers.x509.cache;
17
18 import junit.framework.TestCase;
19
20 import org.acegisecurity.GrantedAuthority;
21 import org.acegisecurity.GrantedAuthorityImpl;
22 import org.acegisecurity.MockApplicationContext;
23 import org.acegisecurity.providers.x509.X509TestUtils;
24 import org.acegisecurity.userdetails.User;
25 import org.acegisecurity.userdetails.UserDetails;
26
27 import net.sf.ehcache.Cache;
28
29 import org.springframework.context.ApplicationContext;
30
31
32 /***
33 * DOCUMENT ME!
34 *
35 * @author Luke Taylor
36 * @version $Id: EhCacheBasedX509UserCacheTests.java,v 1.4 2005/11/29 13:10:14 benalex Exp $
37 */
38 public class EhCacheBasedX509UserCacheTests extends TestCase {
39
40
41 public EhCacheBasedX509UserCacheTests() {
42 super();
43 }
44
45 public EhCacheBasedX509UserCacheTests(String arg0) {
46 super(arg0);
47 }
48
49
50
51 public final void setUp() throws Exception {
52 super.setUp();
53 }
54
55 public void testCacheOperation() throws Exception {
56 EhCacheBasedX509UserCache cache = new EhCacheBasedX509UserCache();
57 cache.setCache(getCache());
58 cache.afterPropertiesSet();
59
60
61 cache.putUserInCache(X509TestUtils.buildTestCertificate(), getUser());
62 assertEquals(getUser().getPassword(),
63 cache.getUserFromCache(X509TestUtils.buildTestCertificate())
64 .getPassword());
65
66
67 cache.removeUserFromCache(X509TestUtils.buildTestCertificate());
68 assertNull(cache.getUserFromCache(X509TestUtils.buildTestCertificate()));
69
70
71 assertNull(cache.getUserFromCache(null));
72 }
73
74 private Cache getCache() {
75 ApplicationContext ctx = MockApplicationContext.getContext();
76
77 return (Cache) ctx.getBean("eHCacheBackend");
78 }
79
80 private UserDetails getUser() {
81 return new User("marissa", "password", true, true, true, true,
82 new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl(
83 "ROLE_TWO")});
84 }
85 }