1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.cache.ehcache; |
35 |
|
|
36 |
|
import static org.junit.Assert.*; |
37 |
|
import static org.mockito.Mockito.mock; |
38 |
|
|
39 |
|
import info.magnolia.context.MgnlContext; |
40 |
|
import info.magnolia.init.DefaultMagnoliaInitPaths; |
41 |
|
import info.magnolia.init.MagnoliaConfigurationProperties; |
42 |
|
import info.magnolia.init.MagnoliaInitPaths; |
43 |
|
import info.magnolia.jcr.node2bean.Node2BeanTransformer; |
44 |
|
import info.magnolia.jcr.node2bean.TypeMapping; |
45 |
|
import info.magnolia.jcr.node2bean.impl.Node2BeanProcessorImpl; |
46 |
|
import info.magnolia.jcr.node2bean.impl.Node2BeanTransformerImpl; |
47 |
|
import info.magnolia.jcr.node2bean.impl.TypeMappingImpl; |
48 |
|
import info.magnolia.module.ModuleManager; |
49 |
|
import info.magnolia.module.cache.mbean.CacheMonitor; |
50 |
|
import info.magnolia.test.ComponentsTestUtil; |
51 |
|
import info.magnolia.test.mock.jcr.SessionTestUtil; |
52 |
|
|
53 |
|
import javax.jcr.Session; |
54 |
|
|
55 |
|
import org.junit.After; |
56 |
|
import org.junit.Before; |
57 |
|
import org.junit.Test; |
58 |
|
|
59 |
|
import net.sf.ehcache.config.PersistenceConfiguration; |
60 |
|
import net.sf.ehcache.store.MemoryStoreEvictionPolicy; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 3 |
Complexity Density: 0.12 |
|
65 |
|
public class EhCacheNode2BeanTest extends AbstractEhCacheTest { |
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
66 |
1 |
@Test... |
67 |
|
public void testSampleConfig() throws Exception { |
68 |
|
|
69 |
1 |
final Node2BeanTransformer transformer = new Node2BeanTransformerImpl(); |
70 |
1 |
final Node2BeanProcessorImpl node2bean = new Node2BeanProcessorImpl(typeMapping, transformer); |
71 |
|
|
72 |
1 |
final Session session = SessionTestUtil.createSession("test", |
73 |
|
"/cfg/factory.class=" + EhCacheFactory.class.getName(), |
74 |
|
"/cfg/factory/caches/myTestCfg.diskExpiryThreadIntervalSeconds=1", |
75 |
|
"/cfg/factory/caches/myTestCfg.diskSpoolBufferSizeMB=2", |
76 |
|
"/cfg/factory/caches/myTestCfg.eternal=false", |
77 |
|
"/cfg/factory/caches/myTestCfg.maxElementsInMemory=3", |
78 |
|
"/cfg/factory/caches/myTestCfg.maxElementsOnDisk=4", |
79 |
|
"/cfg/factory/caches/myTestCfg.memoryStoreEvictionPolicy=FiFo", |
80 |
|
"/cfg/factory/caches/myTestCfg.timeToIdleSeconds=5", |
81 |
|
"/cfg/factory/caches/myTestCfg.timeToLiveSeconds=6", |
82 |
|
|
83 |
|
|
84 |
|
"/cfg/factory/caches/myTestCfg/persistence.strategy=localRestartable", |
85 |
|
"/cfg/factory/caches/myTestCfg/persistence.synchronousWrites=true", |
86 |
|
"" |
87 |
|
); |
88 |
|
|
89 |
|
|
90 |
1 |
final Object bean = node2bean.toBean(session.getNode("/cfg/factory")); |
91 |
|
|
92 |
|
|
93 |
1 |
assertTrue(bean instanceof EhCacheFactory); |
94 |
1 |
EhCacheFactory f = (EhCacheFactory) bean; |
95 |
1 |
final EhCacheConfiguration cfg = f.getCaches().get("myTestCfg"); |
96 |
1 |
assertEquals(1, cfg.getDiskExpiryThreadIntervalSeconds()); |
97 |
1 |
assertEquals(2, cfg.getDiskSpoolBufferSizeMB()); |
98 |
1 |
assertEquals(3, cfg.getMaxEntriesLocalHeap()); |
99 |
1 |
assertEquals(4, cfg.getMaxEntriesLocalDisk()); |
100 |
1 |
assertEquals(5, cfg.getTimeToIdleSeconds()); |
101 |
1 |
assertEquals(6, cfg.getTimeToLiveSeconds()); |
102 |
1 |
assertEquals(false, cfg.isEternal()); |
103 |
1 |
assertEquals(MemoryStoreEvictionPolicy.FIFO, cfg.getMemoryStoreEvictionPolicy()); |
104 |
|
|
105 |
1 |
assertEquals(true, cfg.getPersistenceConfiguration().getSynchronousWrites()); |
106 |
1 |
assertEquals(PersistenceConfiguration.Strategy.LOCALRESTARTABLE, cfg.getPersistenceConfiguration().getStrategy()); |
107 |
|
} |
108 |
|
|
109 |
|
private TypeMapping typeMapping; |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
111 |
1 |
@Before... |
112 |
|
public void setUp() throws Exception { |
113 |
1 |
super.setUp(); |
114 |
1 |
typeMapping = new TypeMappingImpl(); |
115 |
1 |
ComponentsTestUtil.setInstance(TypeMapping.class, typeMapping); |
116 |
1 |
ComponentsTestUtil.setInstance(CacheMonitor.class, cacheMonitor); |
117 |
1 |
ComponentsTestUtil.setInstance(ModuleManager.class, mock(ModuleManager.class)); |
118 |
1 |
ComponentsTestUtil.setInstance(MagnoliaInitPaths.class, mock(DefaultMagnoliaInitPaths.class)); |
119 |
1 |
ComponentsTestUtil.setInstance(MagnoliaConfigurationProperties.class, magnoliaConfigurationProperties); |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
122 |
1 |
@After... |
123 |
|
public void tearDown() throws Exception { |
124 |
1 |
super.tearDown(); |
125 |
1 |
MgnlContext.setInstance(null); |
126 |
|
} |
127 |
|
} |