1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal.cache.rendering; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.Collections; |
24 |
|
|
25 |
|
import org.junit.Assert; |
26 |
|
import org.junit.Before; |
27 |
|
import org.junit.Rule; |
28 |
|
import org.junit.Test; |
29 |
|
import org.xwiki.configuration.ConfigurationSource; |
30 |
|
import org.xwiki.model.internal.DefaultModelConfiguration; |
31 |
|
import org.xwiki.model.internal.DefaultModelContext; |
32 |
|
import org.xwiki.model.internal.reference.DefaultStringEntityReferenceSerializer; |
33 |
|
import org.xwiki.model.internal.reference.DefaultSymbolScheme; |
34 |
|
import org.xwiki.model.reference.DocumentReference; |
35 |
|
import org.xwiki.test.annotation.ComponentList; |
36 |
|
import org.xwiki.test.internal.MockConfigurationSource; |
37 |
|
|
38 |
|
import com.xpn.xwiki.internal.model.reference.CompactWikiStringEntityReferenceSerializer; |
39 |
|
import com.xpn.xwiki.internal.model.reference.CurrentEntityReferenceProvider; |
40 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
41 |
|
|
42 |
|
|
43 |
|
@link |
44 |
|
|
45 |
|
@version |
46 |
|
|
47 |
|
@ComponentList(value = { |
48 |
|
DefaultRenderingCacheConfiguration.class, |
49 |
|
DefaultModelContext.class, |
50 |
|
CompactWikiStringEntityReferenceSerializer.class, |
51 |
|
DefaultStringEntityReferenceSerializer.class, |
52 |
|
CurrentEntityReferenceProvider.class, |
53 |
|
DefaultModelConfiguration.class, |
54 |
|
DefaultSymbolScheme.class |
55 |
|
}) |
|
|
| 100% |
Uncovered Elements: 0 (42) |
Complexity: 10 |
Complexity Density: 0.31 |
|
56 |
|
public class DefaultRenderingCacheConfigurationTest |
57 |
|
{ |
58 |
|
@Rule |
59 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
60 |
|
|
61 |
|
private RenderingCacheConfiguration configuration; |
62 |
|
|
63 |
|
private MockConfigurationSource xwikipropertiesConfiguration; |
64 |
|
|
65 |
|
private MockConfigurationSource wikiConfiguration; |
66 |
|
|
67 |
|
private DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
69 |
9 |
@Before... |
70 |
|
public void before() throws Exception |
71 |
|
{ |
72 |
9 |
this.oldcore.getXWikiContext().setWikiId("wiki"); |
73 |
|
|
74 |
9 |
this.oldcore.getMocker().registerComponent(MockConfigurationSource.getDescriptor("xwikiproperties")); |
75 |
9 |
this.oldcore.getMocker().registerComponent(MockConfigurationSource.getDescriptor("wiki")); |
76 |
|
|
77 |
9 |
this.xwikipropertiesConfiguration = |
78 |
|
this.oldcore.getMocker().getInstance(ConfigurationSource.class, "xwikiproperties"); |
79 |
9 |
this.wikiConfiguration = this.oldcore.getMocker().getInstance(ConfigurationSource.class, "wiki"); |
80 |
|
|
81 |
9 |
this.configuration = this.oldcore.getMocker().getInstance(RenderingCacheConfiguration.class); |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
84 |
1 |
@Test... |
85 |
|
public void testIsCachedWithNoConfiguration() throws Exception |
86 |
|
{ |
87 |
1 |
Assert.assertFalse(this.configuration.isCached(this.documentReference)); |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
90 |
1 |
@Test... |
91 |
|
public void testIsCachedWhenDisabled() throws Exception |
92 |
|
{ |
93 |
1 |
this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", false); |
94 |
|
|
95 |
1 |
Assert.assertFalse(this.configuration.isCached(this.documentReference)); |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
98 |
1 |
@Test... |
99 |
|
public void testIsCachedWhenDisabledWithNoConfiguration() throws Exception |
100 |
|
{ |
101 |
1 |
this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true); |
102 |
|
|
103 |
1 |
Assert.assertFalse(this.configuration.isCached(this.documentReference)); |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
106 |
1 |
@Test... |
107 |
|
public void testIsCachedWithExactReference() throws Exception |
108 |
|
{ |
109 |
1 |
this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true); |
110 |
1 |
this.xwikipropertiesConfiguration.setProperty("core.renderingcache.documents", |
111 |
|
Collections.singletonList("wiki:space.page")); |
112 |
|
|
113 |
1 |
Assert.assertTrue(this.configuration.isCached(this.documentReference)); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
116 |
1 |
@Test... |
117 |
|
public void testIsCachedWithWrongReference() throws Exception |
118 |
|
{ |
119 |
1 |
this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true); |
120 |
1 |
this.xwikipropertiesConfiguration.setProperty("core.renderingcache.documents", |
121 |
|
Collections.singletonList("wrongreference")); |
122 |
|
|
123 |
1 |
Assert.assertFalse(this.configuration.isCached(this.documentReference)); |
124 |
|
} |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
126 |
1 |
@Test... |
127 |
|
public void testIsCachedWithOnePattern() throws Exception |
128 |
|
{ |
129 |
1 |
this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true); |
130 |
1 |
this.xwikipropertiesConfiguration.setProperty("core.renderingcache.documents", |
131 |
|
Collections.singletonList("wiki:space.*")); |
132 |
|
|
133 |
1 |
Assert.assertTrue(this.configuration.isCached(this.documentReference)); |
134 |
|
} |
135 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
136 |
1 |
@Test... |
137 |
|
public void testIsCachedWithSeveralPattern() throws Exception |
138 |
|
{ |
139 |
1 |
this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true); |
140 |
1 |
this.xwikipropertiesConfiguration.setProperty("core.renderingcache.documents", |
141 |
|
Arrays.asList("wrongreference", "wiki:space.*")); |
142 |
|
|
143 |
1 |
Assert.assertTrue(this.configuration.isCached(this.documentReference)); |
144 |
|
} |
145 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
146 |
1 |
@Test... |
147 |
|
public void testIsCachedWithSeveralPattern2() throws Exception |
148 |
|
{ |
149 |
1 |
this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true); |
150 |
1 |
this.xwikipropertiesConfiguration.setProperty("core.renderingcache.documents", |
151 |
|
Arrays.asList("wiki:space.*", "wrongreference")); |
152 |
|
|
153 |
1 |
Assert.assertTrue(this.configuration.isCached(this.documentReference)); |
154 |
|
} |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
156 |
1 |
@Test... |
157 |
|
public void testIsCachedWithWikiConfiguration() throws Exception |
158 |
|
{ |
159 |
1 |
this.xwikipropertiesConfiguration.setProperty("core.renderingcache.enabled", true); |
160 |
|
|
161 |
1 |
this.wikiConfiguration.setProperty("core.renderingcache.enabled", true); |
162 |
1 |
this.wikiConfiguration.setProperty("core.renderingcache.documents", |
163 |
|
Arrays.asList("wiki:space.*", "wrongreference")); |
164 |
|
|
165 |
1 |
Assert.assertTrue(this.configuration.isCached(this.documentReference)); |
166 |
|
|
167 |
1 |
this.wikiConfiguration.setProperty("core.renderingcache.documents", Arrays.asList("space.*", "wrongreference")); |
168 |
|
|
169 |
1 |
Assert.assertTrue(this.configuration.isCached(this.documentReference)); |
170 |
|
} |
171 |
|
} |