1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.test.page; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.apache.commons.lang.StringUtils; |
26 |
|
import org.junit.After; |
27 |
|
import org.junit.Before; |
28 |
|
import org.junit.Rule; |
29 |
|
import org.xwiki.cache.Cache; |
30 |
|
import org.xwiki.cache.CacheManager; |
31 |
|
import org.xwiki.cache.config.CacheConfiguration; |
32 |
|
import org.xwiki.context.Execution; |
33 |
|
import org.xwiki.context.ExecutionContext; |
34 |
|
import org.xwiki.context.ExecutionContextManager; |
35 |
|
import org.xwiki.environment.Environment; |
36 |
|
import org.xwiki.job.event.status.JobProgressManager; |
37 |
|
import org.xwiki.management.JMXBeanRegistration; |
38 |
|
import org.xwiki.model.reference.DocumentReference; |
39 |
|
import org.xwiki.model.reference.SpaceReference; |
40 |
|
import org.xwiki.query.Query; |
41 |
|
import org.xwiki.rendering.internal.transformation.MutableRenderingContext; |
42 |
|
import org.xwiki.rendering.syntax.Syntax; |
43 |
|
import org.xwiki.rendering.transformation.RenderingContext; |
44 |
|
import org.xwiki.resource.internal.entity.EntityResourceActionLister; |
45 |
|
import org.xwiki.test.annotation.AfterComponent; |
46 |
|
import org.xwiki.test.annotation.BeforeComponent; |
47 |
|
import org.xwiki.test.mockito.MockitoComponentManagerRule; |
48 |
|
import org.xwiki.velocity.VelocityManager; |
49 |
|
|
50 |
|
import com.xpn.xwiki.XWiki; |
51 |
|
import com.xpn.xwiki.XWikiContext; |
52 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
53 |
|
import com.xpn.xwiki.internal.cache.rendering.RenderingCache; |
54 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
55 |
|
import com.xpn.xwiki.web.XWikiServletRequestStub; |
56 |
|
import com.xpn.xwiki.web.XWikiServletResponseStub; |
57 |
|
|
58 |
|
import static org.mockito.ArgumentMatchers.any; |
59 |
|
import static org.mockito.ArgumentMatchers.eq; |
60 |
|
import static org.mockito.Mockito.mock; |
61 |
|
import static org.mockito.Mockito.when; |
62 |
|
|
63 |
|
|
64 |
|
@link |
65 |
|
|
66 |
|
|
67 |
|
@version |
68 |
|
@since |
69 |
|
|
70 |
|
@PageComponentList |
|
|
| 64.6% |
Uncovered Elements: 17 (48) |
Complexity: 8 |
Complexity Density: 0.2 |
|
71 |
|
public class PageTest |
72 |
|
{ |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
@Rule |
77 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
protected XWikiServletRequestStub request; |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
protected XWikiServletResponseStub response; |
88 |
|
|
89 |
|
|
90 |
|
@link |
91 |
|
|
92 |
|
protected XWiki xwiki; |
93 |
|
|
94 |
|
|
95 |
|
@link |
96 |
|
|
97 |
|
protected XWikiContext context; |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
@link |
102 |
|
|
103 |
|
protected MockitoComponentManagerRule mocker = oldcore.getMocker(); |
104 |
|
|
105 |
|
|
106 |
|
@link |
107 |
|
|
108 |
|
@throws |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
110 |
7 |
@BeforeComponent... |
111 |
|
public void setUpComponentsForPageTest() throws Exception |
112 |
|
{ |
113 |
7 |
mocker.registerMockComponent(JMXBeanRegistration.class); |
114 |
7 |
mocker.registerMockComponent(Environment.class); |
115 |
7 |
mocker.registerMockComponent(JobProgressManager.class); |
116 |
7 |
mocker.registerMockComponent(RenderingCache.class); |
117 |
7 |
mocker.registerMockComponent(EntityResourceActionLister.class); |
118 |
|
|
119 |
7 |
CacheManager cacheManager = mocker.registerMockComponent(CacheManager.class); |
120 |
7 |
when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(mock(Cache.class)); |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
@link |
125 |
|
@link |
126 |
|
|
127 |
|
|
128 |
|
@throws |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
130 |
7 |
@AfterComponent... |
131 |
|
public void configureComponentsBeforeOldcoreRuleForPageTest() throws Exception |
132 |
|
{ |
133 |
|
|
134 |
7 |
ExecutionContext ec = new ExecutionContext(); |
135 |
7 |
mocker.<Execution>getInstance(Execution.class).setContext(ec); |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
@param |
140 |
|
@return |
141 |
|
@throws |
142 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
143 |
0 |
protected XWikiDocument loadPage(DocumentReference documentReference) throws Exception... |
144 |
|
{ |
145 |
0 |
List<String> path = new ArrayList<>(); |
146 |
0 |
for (SpaceReference spaceReference : documentReference.getSpaceReferences()) { |
147 |
0 |
path.add(spaceReference.getName()); |
148 |
|
} |
149 |
0 |
path.add(documentReference.getName() + ".xml"); |
150 |
0 |
XWikiDocument document = new XWikiDocument(documentReference); |
151 |
0 |
document.fromXML(getClass().getClassLoader().getResourceAsStream(StringUtils.join(path, '/'))); |
152 |
0 |
this.xwiki.saveDocument(document, "registering document", true, this.context); |
153 |
0 |
return document; |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
@param |
158 |
|
@return |
159 |
|
@throws |
160 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
161 |
0 |
protected String renderPage(DocumentReference reference) throws Exception... |
162 |
|
{ |
163 |
0 |
XWikiDocument doc = loadPage(reference); |
164 |
|
|
165 |
|
|
166 |
0 |
context.setDoc(doc); |
167 |
|
|
168 |
0 |
return doc.getRenderedContent(this.context); |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
@param |
176 |
|
@throws |
177 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
178 |
0 |
protected void setOutputSyntax(Syntax syntax) throws Exception... |
179 |
|
{ |
180 |
0 |
MutableRenderingContext renderingContext = mocker.getInstance(RenderingContext.class); |
181 |
0 |
renderingContext.push(renderingContext.getTransformation(), renderingContext.getXDOM(), |
182 |
|
renderingContext.getDefaultSyntax(), "test", renderingContext.isRestricted(), syntax); |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
@throws |
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
|
190 |
7 |
@Before... |
191 |
|
public void setUpForPageTest() throws Exception |
192 |
|
{ |
193 |
|
|
194 |
7 |
context = oldcore.getXWikiContext(); |
195 |
7 |
xwiki = oldcore.getSpyXWiki(); |
196 |
|
|
197 |
|
|
198 |
7 |
when(oldcore.getQueryManager().createQuery(any(String.class), any(String.class))).thenReturn(mock(Query.class)); |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
7 |
request = new XWikiServletRequestStub(); |
205 |
7 |
request.setScheme("http"); |
206 |
7 |
context.setRequest(request); |
207 |
|
|
208 |
7 |
response = new XWikiServletResponseStub(); |
209 |
7 |
context.setResponse(response); |
210 |
|
|
211 |
7 |
ExecutionContextManager ecm = mocker.getInstance(ExecutionContextManager.class); |
212 |
7 |
ecm.initialize(oldcore.getExecutionContext()); |
213 |
|
|
214 |
|
|
215 |
7 |
when(oldcore.getMockRightService().hasAccessLevel(eq("view"), eq("XWiki.XWikiGuest"), any(), |
216 |
|
eq(context))).thenReturn(true); |
217 |
|
|
218 |
|
|
219 |
7 |
URLFactorySetup.setUp(xwiki, context); |
220 |
|
|
221 |
|
|
222 |
7 |
LocalizationSetup.setUp(mocker); |
223 |
|
|
224 |
|
|
225 |
7 |
SkinExtensionSetup.setUp(xwiki, context); |
226 |
|
} |
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
@throws |
232 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
233 |
7 |
@After... |
234 |
|
public void tearDown() throws Exception |
235 |
|
{ |
236 |
7 |
MutableRenderingContext renderingContext = mocker.getInstance(RenderingContext.class); |
237 |
7 |
renderingContext.pop(); |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
@param |
244 |
|
@param |
245 |
|
@throws |
246 |
|
@since |
247 |
|
|
|
|
| 50% |
Uncovered Elements: 1 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
248 |
4 |
protected void registerVelocityTool(String name, Object tool) throws Exception... |
249 |
|
{ |
250 |
4 |
VelocityManager velocityManager = this.oldcore.getMocker().getInstance(VelocityManager.class); |
251 |
0 |
velocityManager.getVelocityContext().put(name, tool); |
252 |
|
} |
253 |
|
} |