1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.webdav.test; |
21 |
|
|
22 |
|
import java.io.ByteArrayInputStream; |
23 |
|
|
24 |
|
import org.apache.commons.httpclient.methods.GetMethod; |
25 |
|
import org.apache.commons.httpclient.methods.InputStreamRequestEntity; |
26 |
|
import org.apache.commons.httpclient.methods.PutMethod; |
27 |
|
import org.apache.jackrabbit.webdav.DavServletResponse; |
28 |
|
import org.apache.webdav.lib.methods.DeleteMethod; |
29 |
|
import org.apache.webdav.lib.methods.MkcolMethod; |
30 |
|
import org.apache.webdav.lib.methods.MoveMethod; |
31 |
|
import org.junit.Test; |
32 |
|
|
33 |
|
import static org.junit.Assert.*; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (143) |
Complexity: 6 |
Complexity Density: 0.04 |
|
40 |
|
public class DefaultWebDAVTest extends AbstractWebDAVTest |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
45 |
1 |
@Test... |
46 |
|
public void testCreateAndDeleteSpace() throws Exception |
47 |
|
{ |
48 |
1 |
String spaceUrl = SPACES + "/TestSpace"; |
49 |
1 |
DeleteMethod deleteMethod = new DeleteMethod(); |
50 |
1 |
deleteMethod.setDoAuthentication(true); |
51 |
1 |
MkcolMethod mkColMethod = new MkcolMethod(); |
52 |
1 |
mkColMethod.setDoAuthentication(true); |
53 |
|
|
54 |
1 |
deleteMethod.setPath(spaceUrl); |
55 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
56 |
1 |
mkColMethod.setPath(spaceUrl); |
57 |
1 |
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod)); |
58 |
1 |
deleteMethod.setPath(spaceUrl); |
59 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
65 |
1 |
@Test... |
66 |
|
public void testRenameSpace() throws Exception |
67 |
|
{ |
68 |
1 |
String spaceUrl = SPACES + "/TestSpace"; |
69 |
1 |
String relativeDestinationPath = "/xwiki/webdav/spaces/RenamedTestSpace"; |
70 |
1 |
String movedSpaceUrl = SPACES + "/RenamedTestSpace"; |
71 |
1 |
DeleteMethod deleteMethod = new DeleteMethod(); |
72 |
1 |
deleteMethod.setDoAuthentication(true); |
73 |
1 |
MkcolMethod mkColMethod = new MkcolMethod(); |
74 |
1 |
mkColMethod.setDoAuthentication(true); |
75 |
1 |
MoveMethod moveMethod = new MoveMethod(); |
76 |
1 |
moveMethod.setDoAuthentication(true); |
77 |
|
|
78 |
1 |
deleteMethod.setPath(spaceUrl); |
79 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
80 |
1 |
deleteMethod.setPath(movedSpaceUrl); |
81 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
82 |
1 |
mkColMethod.setPath(spaceUrl); |
83 |
1 |
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod)); |
84 |
1 |
moveMethod.setPath(spaceUrl); |
85 |
1 |
moveMethod.setDestination(relativeDestinationPath); |
86 |
1 |
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(moveMethod)); |
87 |
1 |
deleteMethod.setPath(movedSpaceUrl); |
88 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
94 |
1 |
@Test... |
95 |
|
public void testCreateAndDeletePage() throws Exception |
96 |
|
{ |
97 |
1 |
String spaceUrl = SPACES + "/TestSpace"; |
98 |
1 |
String pageUrl = spaceUrl + "/TestPage"; |
99 |
1 |
DeleteMethod deleteMethod = new DeleteMethod(); |
100 |
1 |
deleteMethod.setDoAuthentication(true); |
101 |
1 |
MkcolMethod mkColMethod = new MkcolMethod(); |
102 |
1 |
mkColMethod.setDoAuthentication(true); |
103 |
|
|
104 |
1 |
deleteMethod.setPath(spaceUrl); |
105 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
106 |
1 |
mkColMethod.setPath(spaceUrl); |
107 |
1 |
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod)); |
108 |
1 |
mkColMethod.setPath(pageUrl); |
109 |
1 |
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod)); |
110 |
1 |
deleteMethod.setPath(pageUrl); |
111 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
112 |
1 |
deleteMethod.setPath(spaceUrl); |
113 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
119 |
1 |
@Test... |
120 |
|
public void testGetPageWikiContent() throws Exception |
121 |
|
{ |
122 |
1 |
String spaceUrl = SPACES + "/TestSpace"; |
123 |
1 |
String pageUrl = spaceUrl + "/TestPage"; |
124 |
1 |
String wikiTextFileUrl = pageUrl + "/wiki.txt"; |
125 |
1 |
String wikiXMLFileUrl = pageUrl + "/wiki.xml"; |
126 |
1 |
DeleteMethod deleteMethod = new DeleteMethod(); |
127 |
1 |
deleteMethod.setDoAuthentication(true); |
128 |
1 |
MkcolMethod mkColMethod = new MkcolMethod(); |
129 |
1 |
mkColMethod.setDoAuthentication(true); |
130 |
1 |
GetMethod getMethod = new GetMethod(); |
131 |
1 |
getMethod.setDoAuthentication(true); |
132 |
|
|
133 |
1 |
deleteMethod.setPath(spaceUrl); |
134 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
135 |
1 |
mkColMethod.setPath(spaceUrl); |
136 |
1 |
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod)); |
137 |
1 |
mkColMethod.setPath(pageUrl); |
138 |
1 |
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod)); |
139 |
1 |
getMethod.setPath(wikiTextFileUrl); |
140 |
1 |
assertEquals(DavServletResponse.SC_OK, getHttpClient().executeMethod(getMethod)); |
141 |
1 |
assertTrue(getMethod.getResponseBodyAsStream().read() != -1); |
142 |
1 |
getMethod.setPath(wikiXMLFileUrl); |
143 |
1 |
assertEquals(DavServletResponse.SC_OK, getHttpClient().executeMethod(getMethod)); |
144 |
1 |
assertTrue(getMethod.getResponseBodyAsStream().read() != -1); |
145 |
1 |
deleteMethod.setPath(pageUrl); |
146 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
147 |
1 |
deleteMethod.setPath(spaceUrl); |
148 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
154 |
1 |
@Test... |
155 |
|
public void testUpdatePageWikiContent() throws Exception |
156 |
|
{ |
157 |
1 |
String spaceUrl = SPACES + "/TestSpace"; |
158 |
1 |
String pageUrl = spaceUrl + "/TestPage"; |
159 |
1 |
String wikiTextFileUrl = pageUrl + "/wiki.txt"; |
160 |
1 |
String wikiXMLFileUrl = pageUrl + "/wiki.xml"; |
161 |
1 |
String newContent = "New Content"; |
162 |
1 |
DeleteMethod deleteMethod = new DeleteMethod(); |
163 |
1 |
deleteMethod.setDoAuthentication(true); |
164 |
1 |
MkcolMethod mkColMethod = new MkcolMethod(); |
165 |
1 |
mkColMethod.setDoAuthentication(true); |
166 |
1 |
PutMethod putMethod = new PutMethod(); |
167 |
1 |
putMethod.setDoAuthentication(true); |
168 |
1 |
GetMethod getMethod = new GetMethod(); |
169 |
1 |
getMethod.setDoAuthentication(true); |
170 |
|
|
171 |
1 |
deleteMethod.setPath(spaceUrl); |
172 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
173 |
1 |
mkColMethod.setPath(spaceUrl); |
174 |
1 |
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod)); |
175 |
1 |
mkColMethod.setPath(pageUrl); |
176 |
1 |
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod)); |
177 |
1 |
putMethod.setPath(wikiTextFileUrl); |
178 |
1 |
putMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(newContent.getBytes()))); |
179 |
|
|
180 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(putMethod)); |
181 |
1 |
getMethod.setPath(wikiTextFileUrl); |
182 |
1 |
assertEquals(DavServletResponse.SC_OK, getHttpClient().executeMethod(getMethod)); |
183 |
1 |
assertEquals(newContent, getMethod.getResponseBodyAsString()); |
184 |
1 |
putMethod.setPath(wikiXMLFileUrl); |
185 |
1 |
putMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(newContent.getBytes()))); |
186 |
|
|
187 |
1 |
assertEquals(DavServletResponse.SC_METHOD_NOT_ALLOWED, getHttpClient().executeMethod(putMethod)); |
188 |
1 |
deleteMethod.setPath(pageUrl); |
189 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
190 |
1 |
deleteMethod.setPath(spaceUrl); |
191 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
197 |
1 |
@Test... |
198 |
|
public void testMakingAttachment() throws Exception |
199 |
|
{ |
200 |
1 |
String spaceUrl = SPACES + "/TestSpace"; |
201 |
1 |
String pageUrl = spaceUrl + "/TestPage"; |
202 |
1 |
String attachmentUrl = pageUrl + "/attachment.txt"; |
203 |
1 |
String attachmentContent = "Attachment Content"; |
204 |
1 |
DeleteMethod deleteMethod = new DeleteMethod(); |
205 |
1 |
deleteMethod.setDoAuthentication(true); |
206 |
1 |
MkcolMethod mkColMethod = new MkcolMethod(); |
207 |
1 |
mkColMethod.setDoAuthentication(true); |
208 |
1 |
PutMethod putMethod = new PutMethod(); |
209 |
1 |
putMethod.setDoAuthentication(true); |
210 |
1 |
GetMethod getMethod = new GetMethod(); |
211 |
1 |
getMethod.setDoAuthentication(true); |
212 |
|
|
213 |
1 |
deleteMethod.setPath(spaceUrl); |
214 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
215 |
1 |
mkColMethod.setPath(spaceUrl); |
216 |
1 |
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod)); |
217 |
1 |
mkColMethod.setPath(pageUrl); |
218 |
1 |
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod)); |
219 |
1 |
getMethod.setPath(attachmentUrl); |
220 |
1 |
assertEquals(DavServletResponse.SC_NOT_FOUND, getHttpClient().executeMethod(getMethod)); |
221 |
1 |
putMethod.setPath(attachmentUrl); |
222 |
1 |
putMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(attachmentContent |
223 |
|
.getBytes()))); |
224 |
1 |
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(putMethod)); |
225 |
1 |
getMethod.setPath(attachmentUrl); |
226 |
1 |
assertEquals(DavServletResponse.SC_OK, getHttpClient().executeMethod(getMethod)); |
227 |
1 |
assertEquals(attachmentContent, getMethod.getResponseBodyAsString()); |
228 |
1 |
deleteMethod.setPath(attachmentUrl); |
229 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
230 |
1 |
deleteMethod.setPath(pageUrl); |
231 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
232 |
1 |
deleteMethod.setPath(spaceUrl); |
233 |
1 |
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod)); |
234 |
|
} |
235 |
|
} |