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.setup; |
35 |
|
|
36 |
|
import static info.magnolia.test.hamcrest.NodeMatchers.hasProperty; |
37 |
|
import static org.hamcrest.CoreMatchers.not; |
38 |
|
import static org.junit.Assert.assertThat; |
39 |
|
import static org.mockito.Mockito.*; |
40 |
|
|
41 |
|
import info.magnolia.context.WebContext; |
42 |
|
import info.magnolia.jcr.util.NodeTypes; |
43 |
|
import info.magnolia.jcr.util.NodeUtil; |
44 |
|
import info.magnolia.module.InstallContext; |
45 |
|
import info.magnolia.module.cache.AbstractCacheModule; |
46 |
|
import info.magnolia.module.cache.CacheModule; |
47 |
|
import info.magnolia.module.cache.cachepolicy.result.CachePolicyResultProvider; |
48 |
|
import info.magnolia.module.cache.filter.CacheFilter; |
49 |
|
import info.magnolia.module.cache.mbean.CacheMonitor; |
50 |
|
import info.magnolia.repository.RepositoryConstants; |
51 |
|
import info.magnolia.test.mock.jcr.MockNode; |
52 |
|
|
53 |
|
import javax.inject.Provider; |
54 |
|
import javax.jcr.Node; |
55 |
|
import javax.jcr.Session; |
56 |
|
|
57 |
|
import org.junit.Before; |
58 |
|
import org.junit.Test; |
59 |
|
|
60 |
|
|
61 |
|
@link |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (38) |
Complexity: 4 |
Complexity Density: 0.12 |
|
63 |
|
public class MigrateCacheFilterConfigurationTaskTest { |
64 |
|
|
65 |
|
private InstallContext context; |
66 |
|
|
67 |
|
private MigrateCacheFilterConfigurationTask task; |
68 |
|
|
69 |
|
private Node cacheFilters; |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
71 |
3 |
@Before... |
72 |
|
public void setUp() throws Exception { |
73 |
3 |
context = mock(InstallContext.class); |
74 |
3 |
task = new MigrateCacheFilterConfigurationTask(); |
75 |
3 |
Session jcrSession = mock(Session.class); |
76 |
3 |
when(context.getJCRSession(RepositoryConstants.CONFIG)).thenReturn(jcrSession); |
77 |
3 |
Node rootNode = new MockNode(); |
78 |
3 |
when(jcrSession.getRootNode()).thenReturn(rootNode); |
79 |
3 |
Node filters = NodeUtil.createPath(jcrSession.getRootNode(), "/server/filters", NodeTypes.ContentNode.NAME); |
80 |
3 |
when(jcrSession.nodeExists("/server/filters")).thenReturn(true); |
81 |
3 |
when(jcrSession.getNode("/server/filters")).thenReturn(filters); |
82 |
3 |
cacheFilters = filters.addNode("cache"); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
85 |
1 |
@Test... |
86 |
|
public void testOneFilterSetup() throws Exception { |
87 |
|
|
88 |
1 |
cacheFilters.setProperty("cacheConfigurationName", "default"); |
89 |
1 |
cacheFilters.setProperty("class", "info.magnolia.module.cache.filter.CacheFilter"); |
90 |
|
|
91 |
|
|
92 |
1 |
task.execute(context); |
93 |
|
|
94 |
|
|
95 |
1 |
assertThat(cacheFilters, hasProperty("defaultContentCachingConfigurationName", AbstractCacheModule.DEFAULT_CACHE_CONFIG)); |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
98 |
1 |
@Test... |
99 |
|
public void testMultiFilterSetup() throws Exception { |
100 |
1 |
Node filter1 = cacheFilters.addNode("filter1", NodeTypes.ContentNode.NAME); |
101 |
1 |
filter1.setProperty("cacheConfigurationName", "default"); |
102 |
1 |
filter1.setProperty("class", "info.magnolia.module.cache.filter.CacheFilter"); |
103 |
1 |
Node filter2 = cacheFilters.addNode("filter2", NodeTypes.ContentNode.NAME); |
104 |
1 |
filter2.setProperty("cacheConfigurationName", "non-default"); |
105 |
1 |
filter2.setProperty("class", "info.magnolia.module.cache.filter.CacheFilter"); |
106 |
1 |
Node filter3 = cacheFilters.addNode("filter3", NodeTypes.ContentNode.NAME); |
107 |
1 |
filter3.setProperty(AbstractCacheModule.DEFAULT_CACHE_CONFIG, AbstractCacheModule.DEFAULT_CACHE_CONFIG); |
108 |
1 |
filter3.setProperty("class", "info.magnolia.module.cache.filter.CacheFilter"); |
109 |
1 |
Node filter4 = cacheFilters.addNode("filter4", NodeTypes.ContentNode.NAME); |
110 |
1 |
filter4.setProperty("class", "info.magnolia.module.cache.filter.DummyFilter"); |
111 |
|
|
112 |
|
|
113 |
1 |
task.execute(context); |
114 |
|
|
115 |
|
|
116 |
1 |
assertThat(filter1, hasProperty("defaultContentCachingConfigurationName", AbstractCacheModule.DEFAULT_CACHE_CONFIG)); |
117 |
1 |
assertThat(filter2, hasProperty("defaultContentCachingConfigurationName", "non-default")); |
118 |
1 |
assertThat(filter3, hasProperty("defaultContentCachingConfigurationName", AbstractCacheModule.DEFAULT_CACHE_CONFIG)); |
119 |
1 |
assertThat(filter4, not(hasProperty("defaultContentCachingConfigurationName", AbstractCacheModule.DEFAULT_CACHE_CONFIG))); |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
122 |
1 |
@Test... |
123 |
|
public void testCustomFilterSetup() throws Exception { |
124 |
|
|
125 |
1 |
cacheFilters.setProperty("cacheConfigurationName", "custom"); |
126 |
1 |
cacheFilters.setProperty("class", "info.magnolia.module.cache.setup.MigrateCacheFilterConfigurationTaskTest$DummyCacheFilter"); |
127 |
|
|
128 |
|
|
129 |
1 |
task.execute(context); |
130 |
|
|
131 |
|
|
132 |
1 |
assertThat(cacheFilters, hasProperty("defaultContentCachingConfigurationName", "custom")); |
133 |
|
} |
134 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
135 |
|
private class DummyCacheFilter extends CacheFilter { |
136 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
137 |
0 |
public DummyCacheFilter(Provider<WebContext> webContextProvider, CacheModule cacheModule, CacheMonitor cacheMonitor, Provider<CachePolicyResultProvider> cachePolicyResultProvider) {... |
138 |
0 |
super(webContextProvider, cacheModule, cacheMonitor, cachePolicyResultProvider); |
139 |
|
} |
140 |
|
} |
141 |
|
} |