1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.cache.ehcache;
20
21 import org.apache.shiro.cache.Cache;
22 import org.apache.shiro.util.LifecycleUtils;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26
27 import static org.junit.Assert.*;
28
29
30
31
32
33
34 public class EhCacheManagerTest {
35
36 private EhCacheManager cacheManager;
37
38 @Before
39 public void setUp() {
40 cacheManager = new EhCacheManager();
41 }
42
43 @After
44 public void tearDown() {
45 LifecycleUtils.destroy(cacheManager);
46 }
47
48 @Test
49 public void testCacheManagerCreationDuringInit() {
50 net.sf.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager();
51 assertNull(ehCacheManager);
52 cacheManager.init();
53
54 ehCacheManager = cacheManager.getCacheManager();
55 assertNotNull(ehCacheManager);
56 }
57
58 @Test
59 public void testLazyCacheManagerCreationWithoutCallingInit() {
60 net.sf.ehcache.CacheManager ehCacheManager = cacheManager.getCacheManager();
61 assertNull(ehCacheManager);
62
63
64
65 Cache<String, String> cache = cacheManager.getCache("test");
66
67
68 ehCacheManager = cacheManager.getCacheManager();
69 assertNotNull(ehCacheManager);
70
71 assertNotNull(cache);
72 cache.put("hello", "world");
73 String value = cache.get("hello");
74 assertNotNull(value);
75 assertEquals(value, "world");
76 }
77
78 }