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.io.ByteArrayInputStream; |
23 |
|
import java.io.File; |
24 |
|
import java.net.URL; |
25 |
|
import java.util.Arrays; |
26 |
|
|
27 |
|
import org.apache.commons.io.FileUtils; |
28 |
|
import org.jmock.Mock; |
29 |
|
import org.xwiki.model.reference.DocumentReference; |
30 |
|
|
31 |
|
import com.xpn.xwiki.XWiki; |
32 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
33 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
34 |
|
import com.xpn.xwiki.test.AbstractBridgedXWikiComponentTestCase; |
35 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (30) |
Complexity: 3 |
Complexity Density: 0.11 |
|
36 |
|
public class ExportURLFactoryTest extends AbstractBridgedXWikiComponentTestCase |
37 |
|
{ |
38 |
|
private Mock mockXWiki; |
39 |
|
|
40 |
|
|
41 |
|
private File tmpDir; |
42 |
|
|
43 |
|
|
44 |
|
private ExportURLFactory urlFactory; |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
|
46 |
1 |
@Override... |
47 |
|
protected void setUp() throws Exception |
48 |
|
{ |
49 |
1 |
super.setUp(); |
50 |
|
|
51 |
1 |
this.mockXWiki = mock(XWiki.class); |
52 |
1 |
this.mockXWiki.stubs().method("getWebAppPath").will(returnValue("/xwiki")); |
53 |
1 |
this.mockXWiki.stubs().method("Param").will(returnValue(null)); |
54 |
1 |
getContext().setWiki((XWiki) this.mockXWiki.proxy()); |
55 |
1 |
getContext().setURL(new URL("http://www.xwiki.org/")); |
56 |
|
|
57 |
|
|
58 |
1 |
Mock mockXWikiResquest = mock(XWikiRequest.class, new Class[] {}, new Object[] {}); |
59 |
1 |
mockXWikiResquest.stubs().method("getScheme").will(returnValue("http")); |
60 |
1 |
mockXWikiResquest.stubs().method("isSecure").will(returnValue(false)); |
61 |
1 |
mockXWikiResquest.stubs().method("getServletPath").will(returnValue("/bin")); |
62 |
1 |
mockXWikiResquest.stubs().method("getContextPath").will(returnValue("/xwiki")); |
63 |
1 |
mockXWikiResquest.stubs().method("getHeader").will(returnValue(null)); |
64 |
1 |
getContext().setRequest((XWikiRequest) mockXWikiResquest.proxy()); |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
1 |
this.tmpDir = new File(System.getProperty("java.io.tmpdir"), "xwikitests"); |
69 |
1 |
this.tmpDir.mkdirs(); |
70 |
1 |
new File(this.tmpDir, "attachment").mkdir(); |
71 |
|
|
72 |
1 |
this.urlFactory = new ExportURLFactory(); |
73 |
1 |
this.urlFactory.init(null, this.tmpDir, getContext()); |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
@link |
79 |
|
|
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
81 |
1 |
public void testCreateAttachmentURL() throws Exception... |
82 |
|
{ |
83 |
|
|
84 |
1 |
XWikiDocument doc = new XWikiDocument( |
85 |
|
new DocumentReference("xwiki", Arrays.asList(" Space1 ", "Space2"), "New Page")); |
86 |
1 |
XWikiAttachment attachment = new XWikiAttachment(doc, "img .jpg"); |
87 |
1 |
attachment.setContent(new ByteArrayInputStream("test".getBytes())); |
88 |
1 |
doc.getAttachmentList().add(attachment); |
89 |
1 |
this.mockXWiki.stubs().method("getDocument").will(returnValue(doc)); |
90 |
|
|
91 |
1 |
URL url = this.urlFactory.createAttachmentURL("img .jpg", " Space1 .Space2", "Pa ge", "view", "", "x", |
92 |
|
getContext()); |
93 |
1 |
assertEquals(new URL("file://attachment/x/+Space1+/Space2/Pa+ge/img+%252Ejpg"), url); |
94 |
|
} |
95 |
|
|
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
97 |
1 |
@Override... |
98 |
|
protected void tearDown() throws Exception |
99 |
|
{ |
100 |
1 |
FileUtils.deleteDirectory(this.tmpDir); |
101 |
1 |
super.tearDown(); |
102 |
|
} |
103 |
|
} |