1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.web; |
21 |
|
|
22 |
|
import java.net.MalformedURLException; |
23 |
|
import java.net.URL; |
24 |
|
import java.util.Arrays; |
25 |
|
import java.util.HashMap; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import org.junit.Before; |
29 |
|
import org.junit.Rule; |
30 |
|
import org.junit.Test; |
31 |
|
import org.mockito.invocation.InvocationOnMock; |
32 |
|
import org.mockito.stubbing.Answer; |
33 |
|
import org.xwiki.model.reference.DocumentReference; |
34 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
35 |
|
import org.xwiki.resource.internal.entity.EntityResourceActionLister; |
36 |
|
import org.xwiki.test.annotation.BeforeComponent; |
37 |
|
|
38 |
|
import com.xpn.xwiki.XWikiContext; |
39 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
40 |
|
import com.xpn.xwiki.objects.BaseObject; |
41 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
42 |
|
import com.xpn.xwiki.test.reference.ReferenceComponentList; |
43 |
|
|
44 |
|
import static org.junit.Assert.assertEquals; |
45 |
|
import static org.mockito.ArgumentMatchers.any; |
46 |
|
import static org.mockito.Mockito.doReturn; |
47 |
|
import static org.mockito.Mockito.mock; |
48 |
|
import static org.mockito.Mockito.when; |
49 |
|
|
50 |
|
|
51 |
|
@link |
52 |
|
|
53 |
|
@version |
54 |
|
|
55 |
|
@ReferenceComponentList |
|
|
| 100% |
Uncovered Elements: 0 (205) |
Complexity: 35 |
Complexity Density: 0.21 |
|
56 |
|
public class XWikiServletURLFactoryTest |
57 |
|
{ |
58 |
|
private static final String MAIN_WIKI_NAME = "xwiki"; |
59 |
|
|
60 |
|
@Rule |
61 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
62 |
|
|
63 |
|
private XWikiServletURLFactory urlFactory; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
@link |
71 |
|
|
72 |
|
private boolean secure; |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
@link |
78 |
|
|
79 |
|
private final Map<String, String> httpHeaders = new HashMap<>(); |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
81 |
29 |
@BeforeComponent... |
82 |
|
public void beforeComponent() throws Exception |
83 |
|
{ |
84 |
29 |
EntityResourceActionLister actionLister = |
85 |
|
this.oldcore.getMocker().registerMockComponent(EntityResourceActionLister.class); |
86 |
29 |
when(actionLister.listActions()).thenReturn(Arrays.asList("view")); |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
|
89 |
29 |
@Before... |
90 |
|
public void before() throws Exception |
91 |
|
{ |
92 |
29 |
doReturn("DefaultSpace").when(this.oldcore.getSpyXWiki()).getDefaultSpace(any(XWikiContext.class)); |
93 |
|
|
94 |
|
|
95 |
29 |
XWikiRequest mockXWikiRequest = mock(XWikiRequest.class); |
96 |
29 |
when(mockXWikiRequest.getScheme()).thenReturn("http"); |
97 |
29 |
when(mockXWikiRequest.isSecure()).then(new Answer<Boolean>() |
98 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
99 |
46 |
@Override... |
100 |
|
public Boolean answer(InvocationOnMock invocation) throws Throwable |
101 |
|
{ |
102 |
46 |
return secure; |
103 |
|
} |
104 |
|
}); |
105 |
29 |
when(mockXWikiRequest.getServletPath()).thenReturn(""); |
106 |
29 |
when(mockXWikiRequest.getContextPath()).thenReturn("/xwiki"); |
107 |
29 |
when(mockXWikiRequest.getHeader(any())).then(new Answer<String>() |
108 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
109 |
42 |
@Override... |
110 |
|
public String answer(InvocationOnMock invocation) throws Throwable |
111 |
|
{ |
112 |
42 |
return httpHeaders.get(invocation.getArgument(0)); |
113 |
|
} |
114 |
|
}); |
115 |
29 |
this.oldcore.getXWikiContext().setRequest(mockXWikiRequest); |
116 |
|
|
117 |
|
|
118 |
29 |
XWikiResponse xwikiResponse = mock(XWikiResponse.class); |
119 |
29 |
when(xwikiResponse.encodeURL(any())).then(new Answer<String>() |
120 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
121 |
33 |
@Override... |
122 |
|
public String answer(InvocationOnMock invocation) throws Throwable |
123 |
|
{ |
124 |
33 |
return invocation.getArgument(0); |
125 |
|
} |
126 |
|
}); |
127 |
29 |
this.oldcore.getXWikiContext().setResponse(xwikiResponse); |
128 |
|
|
129 |
|
|
130 |
29 |
createWiki("wiki1"); |
131 |
29 |
createWiki("wiki2"); |
132 |
|
|
133 |
29 |
this.oldcore.getXWikiContext().setURL(new URL("http://127.0.0.1/xwiki/view/InitialSpace/InitialPage")); |
134 |
|
|
135 |
29 |
this.urlFactory = new XWikiServletURLFactory(); |
136 |
29 |
this.urlFactory.init(this.oldcore.getXWikiContext()); |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
@param |
143 |
|
@throws |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
145 |
58 |
private void createWiki(String wikiName) throws Exception... |
146 |
|
{ |
147 |
58 |
String wikiDocName = "XWikiServer" + wikiName.substring(0, 1).toUpperCase() + wikiName.substring(1); |
148 |
58 |
XWikiDocument wikiDoc = this.oldcore.getSpyXWiki() |
149 |
|
.getDocument(new DocumentReference(MAIN_WIKI_NAME, "XWiki", wikiDocName), this.oldcore.getXWikiContext()); |
150 |
58 |
BaseObject wikiObj = |
151 |
|
wikiDoc.newXObject(new LocalDocumentReference("XWiki", "XWikiServerClass"), this.oldcore.getXWikiContext()); |
152 |
58 |
wikiObj.setStringValue("server", wikiName + "server"); |
153 |
58 |
this.oldcore.getSpyXWiki().saveDocument(wikiDoc, this.oldcore.getXWikiContext()); |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
158 |
1 |
@Test... |
159 |
|
public void createURLOnMainWiki() throws MalformedURLException |
160 |
|
{ |
161 |
1 |
URL url = this.urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "xwiki", |
162 |
|
this.oldcore.getXWikiContext()); |
163 |
1 |
assertEquals(new URL("http://127.0.0.1/xwiki/bin/view/Space/Page?param1=1#anchor"), url); |
164 |
|
} |
165 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
166 |
1 |
@Test... |
167 |
|
public void createURLOnSubWiki() throws MalformedURLException |
168 |
|
{ |
169 |
1 |
URL url = this.urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "wiki1", |
170 |
|
this.oldcore.getXWikiContext()); |
171 |
1 |
assertEquals(new URL("http://127.0.0.1/xwiki/wiki/wiki1server/view/Space/Page?param1=1#anchor"), url); |
172 |
|
} |
173 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
174 |
1 |
@Test... |
175 |
|
public void createURLOnSubWikiInVirtualMode() throws MalformedURLException |
176 |
|
{ |
177 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual", "1"); |
178 |
|
|
179 |
1 |
URL url = this.urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "wiki1", |
180 |
|
this.oldcore.getXWikiContext()); |
181 |
1 |
assertEquals(new URL("http://127.0.0.1/xwiki/wiki/wiki1server/view/Space/Page?param1=1#anchor"), url); |
182 |
|
} |
183 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
184 |
1 |
@Test... |
185 |
|
public void createURLOnMainWikiInPathMode() throws MalformedURLException |
186 |
|
{ |
187 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual.usepath", "1"); |
188 |
|
|
189 |
1 |
URL url = this.urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "xwiki", |
190 |
|
this.oldcore.getXWikiContext()); |
191 |
1 |
assertEquals(new URL("http://127.0.0.1/xwiki/bin/view/Space/Page?param1=1#anchor"), url); |
192 |
|
} |
193 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
194 |
1 |
@Test... |
195 |
|
public void createURLOnSubWikiInPathMode() throws MalformedURLException |
196 |
|
{ |
197 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual.usepath", "1"); |
198 |
|
|
199 |
1 |
URL url = this.urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "wiki1", |
200 |
|
this.oldcore.getXWikiContext()); |
201 |
1 |
assertEquals(new URL("http://127.0.0.1/xwiki/wiki/wiki1server/view/Space/Page?param1=1#anchor"), url); |
202 |
|
} |
203 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
204 |
1 |
@Test... |
205 |
|
public void createURLOnSubWikiInVirtualModeInPathMode() throws MalformedURLException |
206 |
|
{ |
207 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual", "1"); |
208 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual.usepath", "1"); |
209 |
|
|
210 |
1 |
secure = true; |
211 |
|
|
212 |
1 |
this.oldcore.getXWikiContext().setURL(new URL("https://localhost:8080/xwiki/view/Main/")); |
213 |
|
|
214 |
1 |
urlFactory.init(this.oldcore.getXWikiContext()); |
215 |
|
|
216 |
1 |
URL url = this.urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "wiki1", |
217 |
|
this.oldcore.getXWikiContext()); |
218 |
1 |
assertEquals(new URL("https://localhost:8080/xwiki/wiki/wiki1server/view/Space/Page?param1=1#anchor"), url); |
219 |
1 |
assertEquals("/xwiki/wiki/wiki1server/view/Space/Page?param1=1#anchor", |
220 |
|
urlFactory.getURL(url, this.oldcore.getXWikiContext())); |
221 |
|
} |
222 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
223 |
1 |
@Test... |
224 |
|
public void createURLOnMainWikiInDomainMode() throws MalformedURLException |
225 |
|
{ |
226 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual.usepath", "0"); |
227 |
|
|
228 |
1 |
URL url = this.urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "xwiki", |
229 |
|
this.oldcore.getXWikiContext()); |
230 |
1 |
assertEquals(new URL("http://127.0.0.1/xwiki/bin/view/Space/Page?param1=1#anchor"), url); |
231 |
|
} |
232 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
233 |
1 |
@Test... |
234 |
|
public void createURLOnSubWikiInDomainMode() throws MalformedURLException |
235 |
|
{ |
236 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual.usepath", "0"); |
237 |
|
|
238 |
1 |
URL url = this.urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "wiki1", |
239 |
|
this.oldcore.getXWikiContext()); |
240 |
1 |
assertEquals(new URL("http://wiki1server/xwiki/bin/view/Space/Page?param1=1#anchor"), url); |
241 |
|
} |
242 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
243 |
1 |
@Test... |
244 |
|
public void createURLOnSubWikiInVirtualModeInDomainMode() throws MalformedURLException |
245 |
|
{ |
246 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual", "1"); |
247 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual.usepath", "0"); |
248 |
|
|
249 |
1 |
URL url = this.urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "wiki1", |
250 |
|
this.oldcore.getXWikiContext()); |
251 |
1 |
assertEquals(new URL("http://wiki1server/xwiki/bin/view/Space/Page?param1=1#anchor"), url); |
252 |
|
} |
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
@throws |
258 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
259 |
1 |
@Test... |
260 |
|
public void createURLOnMainWikiInDomainModeInReverseProxyMode() throws MalformedURLException |
261 |
|
{ |
262 |
1 |
secure = true; |
263 |
1 |
httpHeaders.put("x-forwarded-host", "www.xwiki.org"); |
264 |
|
|
265 |
1 |
urlFactory.init(this.oldcore.getXWikiContext()); |
266 |
|
|
267 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual.usepath", "0"); |
268 |
|
|
269 |
1 |
URL url = urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "xwiki", |
270 |
|
this.oldcore.getXWikiContext()); |
271 |
1 |
assertEquals(new URL("https://www.xwiki.org/xwiki/bin/view/Space/Page?param1=1#anchor"), url); |
272 |
1 |
assertEquals("/xwiki/bin/view/Space/Page?param1=1#anchor", |
273 |
|
urlFactory.getURL(url, this.oldcore.getXWikiContext())); |
274 |
|
} |
275 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
276 |
1 |
@Test... |
277 |
|
public void createURLOnSubWikiInDomainModeInReverseProxyMode() throws MalformedURLException |
278 |
|
{ |
279 |
1 |
httpHeaders.put("x-forwarded-host", "www.xwiki.org"); |
280 |
|
|
281 |
1 |
urlFactory.init(this.oldcore.getXWikiContext()); |
282 |
|
|
283 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual.usepath", "0"); |
284 |
|
|
285 |
1 |
URL url = urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "wiki1", |
286 |
|
this.oldcore.getXWikiContext()); |
287 |
1 |
assertEquals(new URL("http://wiki1server/xwiki/bin/view/Space/Page?param1=1#anchor"), url); |
288 |
|
|
289 |
1 |
assertEquals("http://wiki1server/xwiki/bin/view/Space/Page?param1=1#anchor", |
290 |
|
urlFactory.getURL(url, this.oldcore.getXWikiContext())); |
291 |
|
} |
292 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
293 |
1 |
@Test... |
294 |
|
public void createURLOnSubWikiInVirtualModeInDomainModeInReverseProxyMode() throws MalformedURLException |
295 |
|
{ |
296 |
1 |
secure = true; |
297 |
1 |
httpHeaders.put("x-forwarded-host", "www.xwiki.org"); |
298 |
|
|
299 |
1 |
urlFactory.init(this.oldcore.getXWikiContext()); |
300 |
|
|
301 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual", "1"); |
302 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual.usepath", "0"); |
303 |
|
|
304 |
1 |
URL url = urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "wiki1", |
305 |
|
this.oldcore.getXWikiContext()); |
306 |
1 |
assertEquals(new URL("https://wiki1server/xwiki/bin/view/Space/Page?param1=1#anchor"), url); |
307 |
|
|
308 |
1 |
assertEquals("https://wiki1server/xwiki/bin/view/Space/Page?param1=1#anchor", |
309 |
|
urlFactory.getURL(url, this.oldcore.getXWikiContext())); |
310 |
|
} |
311 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
312 |
1 |
@Test... |
313 |
|
public void createURLOnMainWikiInPathModeInReverseProxyMode() throws MalformedURLException |
314 |
|
{ |
315 |
1 |
httpHeaders.put("x-forwarded-host", "www.xwiki.org"); |
316 |
|
|
317 |
1 |
urlFactory.init(this.oldcore.getXWikiContext()); |
318 |
|
|
319 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual.usepath", "1"); |
320 |
|
|
321 |
1 |
URL url = urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "xwiki", |
322 |
|
this.oldcore.getXWikiContext()); |
323 |
1 |
assertEquals(new URL("http://www.xwiki.org/xwiki/bin/view/Space/Page?param1=1#anchor"), url); |
324 |
1 |
assertEquals("/xwiki/bin/view/Space/Page?param1=1#anchor", |
325 |
|
urlFactory.getURL(url, this.oldcore.getXWikiContext())); |
326 |
|
} |
327 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
328 |
1 |
@Test... |
329 |
|
public void createURLOnSubWikiInPathModeInReverseProxyMode() throws MalformedURLException |
330 |
|
{ |
331 |
1 |
secure = true; |
332 |
1 |
httpHeaders.put("x-forwarded-host", "www.xwiki.org"); |
333 |
|
|
334 |
1 |
urlFactory.init(this.oldcore.getXWikiContext()); |
335 |
|
|
336 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual.usepath", "1"); |
337 |
|
|
338 |
1 |
URL url = urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "wiki1", |
339 |
|
this.oldcore.getXWikiContext()); |
340 |
1 |
assertEquals(new URL("https://www.xwiki.org/xwiki/wiki/wiki1server/view/Space/Page?param1=1#anchor"), url); |
341 |
1 |
assertEquals("/xwiki/wiki/wiki1server/view/Space/Page?param1=1#anchor", |
342 |
|
urlFactory.getURL(url, this.oldcore.getXWikiContext())); |
343 |
|
} |
344 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
345 |
1 |
@Test... |
346 |
|
public void createURLOnSubWikiInVirtualModeInPathModeInReverseProxyMode() throws MalformedURLException |
347 |
|
{ |
348 |
1 |
httpHeaders.put("x-forwarded-host", "www.xwiki.org:8080"); |
349 |
|
|
350 |
1 |
urlFactory.init(this.oldcore.getXWikiContext()); |
351 |
|
|
352 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual", "1"); |
353 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual.usepath", "1"); |
354 |
|
|
355 |
1 |
URL url = urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "wiki1", |
356 |
|
this.oldcore.getXWikiContext()); |
357 |
1 |
assertEquals(new URL("http://www.xwiki.org:8080/xwiki/wiki/wiki1server/view/Space/Page?param1=1#anchor"), url); |
358 |
1 |
assertEquals("/xwiki/wiki/wiki1server/view/Space/Page?param1=1#anchor", |
359 |
|
urlFactory.getURL(url, this.oldcore.getXWikiContext())); |
360 |
|
} |
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
366 |
1 |
@Test... |
367 |
|
public void getURLWhenRequestWikiAndContextWikiAreDifferent() throws MalformedURLException |
368 |
|
{ |
369 |
1 |
this.oldcore.getXWikiContext().setURL(new URL("http://wiki1server/xwiki/view/InitialSpace/InitialPage")); |
370 |
|
|
371 |
1 |
urlFactory.init(this.oldcore.getXWikiContext()); |
372 |
|
|
373 |
1 |
this.oldcore.getXWikiContext().setWikiId("wiki2"); |
374 |
|
|
375 |
1 |
String url = |
376 |
|
urlFactory.getURL(new URL("http://wiki1server/xwiki/bin/view/Space/Page"), this.oldcore.getXWikiContext()); |
377 |
1 |
assertEquals("/xwiki/bin/view/Space/Page", url); |
378 |
|
|
379 |
1 |
url = |
380 |
|
urlFactory.getURL(new URL("http://wiki2server/xwiki/bin/view/Space/Page"), this.oldcore.getXWikiContext()); |
381 |
1 |
assertEquals("http://wiki2server/xwiki/bin/view/Space/Page", url); |
382 |
|
} |
383 |
|
|
384 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
385 |
1 |
@Test... |
386 |
|
public void getURLWithEmptyPathReturnsSlash() throws MalformedURLException |
387 |
|
{ |
388 |
1 |
this.oldcore.getXWikiContext().setURL(new URL("http://wiki1server/xwiki/view/InitialSpace/InitialPage")); |
389 |
|
|
390 |
1 |
this.urlFactory.init(this.oldcore.getXWikiContext()); |
391 |
|
|
392 |
1 |
String url = this.urlFactory.getURL(new URL("http://wiki1server/"), this.oldcore.getXWikiContext()); |
393 |
1 |
assertEquals("/", url); |
394 |
|
} |
395 |
|
|
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
400 |
1 |
@Test... |
401 |
|
public void getServerURLFromVirtualWithXWikiDotHomeEnabled() throws MalformedURLException |
402 |
|
{ |
403 |
1 |
this.oldcore.getXWikiContext() |
404 |
|
.setURL(new URL("http://virtual1.mywiki.tld/xwiki/view/InitialSpace/InitialPage")); |
405 |
1 |
this.oldcore.getXWikiContext().setWikiId("subwiki"); |
406 |
|
|
407 |
|
|
408 |
|
|
409 |
1 |
this.oldcore.getXWikiContext().setOriginalWikiId("subwiki"); |
410 |
|
|
411 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.home", "http://mainwiki.mywiki.tld/"); |
412 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual", "1"); |
413 |
1 |
urlFactory.init(this.oldcore.getXWikiContext()); |
414 |
1 |
assertEquals("http://mainwiki.mywiki.tld/", |
415 |
|
urlFactory.getServerURL("xwiki", this.oldcore.getXWikiContext()).toString()); |
416 |
|
} |
417 |
|
|
418 |
|
|
419 |
|
|
420 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
421 |
1 |
@Test... |
422 |
|
public void createURLWhenWikiDotHomeParameterFromVirtualWiki() throws MalformedURLException |
423 |
|
{ |
424 |
1 |
this.oldcore.getXWikiContext() |
425 |
|
.setURL(new URL("http://virtual1.mywiki.tld/xwiki/view/InitialSpace/InitialPage")); |
426 |
1 |
this.oldcore.getXWikiContext().setWikiId("subwiki"); |
427 |
|
|
428 |
|
|
429 |
|
|
430 |
1 |
this.oldcore.getXWikiContext().setOriginalWikiId("subwiki"); |
431 |
|
|
432 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.home", "http://mainwiki.mywiki.tld/"); |
433 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.virtual", "1"); |
434 |
|
|
435 |
|
|
436 |
1 |
urlFactory.init(this.oldcore.getXWikiContext()); |
437 |
|
|
438 |
|
|
439 |
1 |
URL url = |
440 |
|
urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", null, this.oldcore.getXWikiContext()); |
441 |
1 |
assertEquals(new URL("http://virtual1.mywiki.tld/xwiki/bin/view/Space/Page?param1=1#anchor"), url); |
442 |
|
|
443 |
1 |
assertEquals("/xwiki/bin/view/Space/Page?param1=1#anchor", |
444 |
|
urlFactory.getURL(url, this.oldcore.getXWikiContext())); |
445 |
|
|
446 |
|
|
447 |
1 |
url = urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "xwiki", |
448 |
|
this.oldcore.getXWikiContext()); |
449 |
1 |
assertEquals(new URL("http://mainwiki.mywiki.tld/xwiki/bin/view/Space/Page?param1=1#anchor"), url); |
450 |
1 |
assertEquals("http://mainwiki.mywiki.tld/xwiki/bin/view/Space/Page?param1=1#anchor", |
451 |
|
urlFactory.getURL(url, this.oldcore.getXWikiContext())); |
452 |
|
} |
453 |
|
|
454 |
|
|
455 |
|
|
456 |
|
|
457 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
458 |
1 |
@Test... |
459 |
|
public void getServerURLNonVirtualModeWithXWikiDotHomeEnabled() throws MalformedURLException |
460 |
|
{ |
461 |
1 |
this.oldcore.getXWikiContext().setURL(new URL("http://127.0.0.1:8080/xwiki/view/InitialSpace/InitialPage")); |
462 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.home", "http://mainwiki.mywiki.tld/"); |
463 |
1 |
urlFactory.init(this.oldcore.getXWikiContext()); |
464 |
|
|
465 |
1 |
assertEquals("http://mainwiki.mywiki.tld", |
466 |
|
urlFactory.getServerURL("xwiki", this.oldcore.getXWikiContext()).toString()); |
467 |
1 |
assertEquals("http://mainwiki.mywiki.tld", |
468 |
|
urlFactory.getServerURL(null, this.oldcore.getXWikiContext()).toString()); |
469 |
|
} |
470 |
|
|
471 |
|
|
472 |
|
|
473 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
474 |
1 |
@Test... |
475 |
|
public void createURLWhenXWikiDotHomeParameterNonVirtualMode() throws MalformedURLException |
476 |
|
{ |
477 |
|
|
478 |
|
|
479 |
1 |
this.oldcore.getXWikiContext().setURL(new URL("http://localhost:8080/xwiki/view/InitialSpace/InitialPage")); |
480 |
1 |
this.oldcore.getMockXWikiCfg().setProperty("xwiki.home", "http://mainwiki.mywiki.tld/"); |
481 |
|
|
482 |
1 |
urlFactory.init(this.oldcore.getXWikiContext()); |
483 |
|
|
484 |
|
|
485 |
|
|
486 |
1 |
URL url = |
487 |
|
urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", null, this.oldcore.getXWikiContext()); |
488 |
1 |
assertEquals(new URL("http://mainwiki.mywiki.tld/xwiki/bin/view/Space/Page?param1=1#anchor"), url); |
489 |
1 |
assertEquals("/xwiki/bin/view/Space/Page?param1=1#anchor", |
490 |
|
urlFactory.getURL(url, this.oldcore.getXWikiContext())); |
491 |
|
|
492 |
|
|
493 |
1 |
url = urlFactory.createURL("Space", "Page", "view", "param1=1", "anchor", "xwiki", |
494 |
|
this.oldcore.getXWikiContext()); |
495 |
1 |
assertEquals(new URL("http://mainwiki.mywiki.tld/xwiki/bin/view/Space/Page?param1=1#anchor"), url); |
496 |
1 |
assertEquals("/xwiki/bin/view/Space/Page?param1=1#anchor", |
497 |
|
urlFactory.getURL(url, this.oldcore.getXWikiContext())); |
498 |
|
} |
499 |
|
|
500 |
|
|
501 |
|
|
502 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
503 |
1 |
@Test... |
504 |
|
public void normalizeURL() throws Exception |
505 |
|
{ |
506 |
1 |
assertEquals(new URL("http://www.xwiki.org/xwiki/bin/view/Blog/Bug+Fixing+Day+35?language=en"), |
507 |
|
XWikiServletURLFactory.normalizeURL("http://www.xwiki.org/xwiki/bin/view/Blog/Bug+Fixing+Day+35" |
508 |
|
+ ";jsessionid=0AF95AFB8997826B936C0397DF6A0C7F?language=en", this.oldcore.getXWikiContext())); |
509 |
|
} |
510 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
511 |
1 |
@Test... |
512 |
|
public void createURLWithNestedSpaces() throws Exception |
513 |
|
{ |
514 |
1 |
URL url = this.urlFactory.createURL("Space1.Space2", "Page", this.oldcore.getXWikiContext()); |
515 |
1 |
assertEquals(new URL("http://127.0.0.1/xwiki/bin/view/Space1/Space2/Page"), url); |
516 |
|
} |
517 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
518 |
1 |
@Test... |
519 |
|
public void createAttachmentURLWhenViewRevAndRevSpecifiedAndIsNotContextDoc() throws Exception |
520 |
|
{ |
521 |
1 |
XWikiContext xwikiContext = this.oldcore.getXWikiContext(); |
522 |
1 |
xwikiContext.put("rev", "1.0"); |
523 |
1 |
xwikiContext.setAction("viewrev"); |
524 |
1 |
xwikiContext.setDoc(new XWikiDocument(new DocumentReference("currentwiki", "currentspace", "currentpage"))); |
525 |
1 |
URL url = this.urlFactory.createAttachmentURL("file", "space", "page", "viewrev", null, xwikiContext); |
526 |
1 |
assertEquals(new URL("http://127.0.0.1/xwiki/bin/viewrev/space/page/file"), url); |
527 |
|
} |
528 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
529 |
1 |
@Test... |
530 |
|
public void createAttachmentURLWhenViewRevAndRevSpecifiedAndIsContextDocAndAttachmentDoesntExist() |
531 |
|
throws Exception |
532 |
|
{ |
533 |
1 |
XWikiContext xwikiContext = this.oldcore.getXWikiContext(); |
534 |
1 |
xwikiContext.put("rev", "1.0"); |
535 |
1 |
xwikiContext.setAction("viewrev"); |
536 |
|
|
537 |
1 |
XWikiDocument document = new XWikiDocument(new DocumentReference("currentwiki", "currentspace", "currentpage")); |
538 |
1 |
this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext()); |
539 |
|
|
540 |
1 |
xwikiContext.setDoc(document); |
541 |
1 |
xwikiContext.setWikiId("currentwiki"); |
542 |
|
|
543 |
1 |
URL url = |
544 |
|
this.urlFactory.createAttachmentURL("file", "currentspace", "currentpage", "viewrev", null, xwikiContext); |
545 |
1 |
assertEquals(new URL("http://127.0.0.1/xwiki/bin/viewattachrev/currentspace/currentpage/file"), url); |
546 |
|
} |
547 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
548 |
1 |
@Test... |
549 |
|
public void createURLWhenShowViewActionFalse() throws Exception |
550 |
|
{ |
551 |
1 |
doReturn(false).when(this.oldcore.getSpyXWiki()).showViewAction(any(XWikiContext.class)); |
552 |
|
|
553 |
1 |
URL url = this.urlFactory.createURL("Space", "Page", "view", this.oldcore.getXWikiContext()); |
554 |
1 |
assertEquals(new URL("http://127.0.0.1/xwiki/bin/Space/Page"), url); |
555 |
|
} |
556 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
557 |
1 |
@Test... |
558 |
|
public void createURLWhenShowViewActionFalseAndSpaceIsNamedAfterAnAction() throws Exception |
559 |
|
{ |
560 |
1 |
doReturn(false).when(this.oldcore.getSpyXWiki()).showViewAction(any(XWikiContext.class)); |
561 |
|
|
562 |
1 |
URL url = this.urlFactory.createURL("view.space2", "page", "view", this.oldcore.getXWikiContext()); |
563 |
1 |
assertEquals(new URL("http://127.0.0.1/xwiki/bin/view/view/space2/page"), url); |
564 |
|
} |
565 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
566 |
1 |
@Test... |
567 |
|
public void createResourceURL() throws Exception |
568 |
|
{ |
569 |
|
|
570 |
1 |
URL url = this.urlFactory.createResourceURL("o;ne/t?w&o/t=hr#e e", false, this.oldcore.getXWikiContext()); |
571 |
1 |
assertEquals(new URL("http://127.0.0.1/xwiki/resources/o;ne/t%3Fw&o/t=hr%23e%20e"), url); |
572 |
|
} |
573 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
574 |
1 |
@Test... |
575 |
|
public void createURLWhenCharactersNeedToBeEncoded() throws Exception |
576 |
|
{ |
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
|
581 |
|
|
582 |
1 |
URL url = this.urlFactory.createURL("a b.c+d'", "e f", "view", "g=h%20i", "j k+l", this.oldcore.getXWikiContext()); |
583 |
|
|
584 |
1 |
assertEquals("http://127.0.0.1/xwiki/bin/view/a%20b/c%2Bd%27/e%20f?g=h%20i#j%20k%2Bl", url.toString()); |
585 |
|
} |
586 |
|
} |