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.HttpClient; |
25 |
|
import org.apache.commons.httpclient.HttpMethod; |
26 |
|
import org.apache.commons.httpclient.UsernamePasswordCredentials; |
27 |
|
import org.apache.commons.httpclient.auth.AuthScope; |
28 |
|
import org.apache.commons.httpclient.methods.DeleteMethod; |
29 |
|
import org.apache.commons.httpclient.methods.GetMethod; |
30 |
|
import org.apache.commons.httpclient.methods.InputStreamRequestEntity; |
31 |
|
import org.apache.commons.httpclient.methods.PutMethod; |
32 |
|
import org.apache.webdav.lib.methods.MkcolMethod; |
33 |
|
import org.apache.webdav.lib.methods.MoveMethod; |
34 |
|
import org.apache.webdav.lib.methods.PropFindMethod; |
35 |
|
import org.junit.Before; |
36 |
|
|
37 |
|
import static org.junit.Assert.*; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (48) |
Complexity: 9 |
Complexity Density: 0.23 |
|
45 |
|
public class AbstractWebDAVTest |
46 |
|
{ |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
public static final String ROOT = "http://localhost:8080/xwiki/webdav"; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
public static final String HOME = ROOT + "/home"; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
public static final String SPACES = ROOT + "/spaces"; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
public static final String ATTACHMENTS = ROOT + "/attachments"; |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
public static final String ORPHANS = ROOT + "/orphans"; |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
public static final String WHATSNEW = ROOT + "/whatsnew"; |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
public static String[] BASE_VIEWS = new String[] {SPACES, ATTACHMENTS, HOME, ORPHANS, WHATSNEW}; |
81 |
|
|
82 |
|
|
83 |
|
@link |
84 |
|
|
85 |
|
private HttpClient client; |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
90 |
15 |
@Before... |
91 |
|
public void setUp() throws Exception |
92 |
|
{ |
93 |
15 |
client = new HttpClient(); |
94 |
15 |
client.getState().setCredentials( |
95 |
|
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME), |
96 |
|
new UsernamePasswordCredentials("superadmin", "pass")); |
97 |
15 |
client.getHttpConnectionManager().getParams().setConnectionTimeout(10000); |
98 |
15 |
client.getParams().setAuthenticationPreemptive(true); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
@return@link |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
77 |
protected HttpClient getHttpClient()... |
105 |
|
{ |
106 |
77 |
return client; |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
@link |
111 |
|
|
112 |
|
@param@link |
113 |
|
@param |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
115 |
40 |
protected void testMethod(HttpMethod method, int expect) throws Exception... |
116 |
|
{ |
117 |
40 |
int status = getHttpClient().executeMethod(method); |
118 |
40 |
assertEquals(expect, status); |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
@param |
125 |
|
@param@link |
126 |
|
@param |
127 |
|
@return@link |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
129 |
1 |
protected HttpMethod propFind(String url, int depth, int expect) throws Exception... |
130 |
|
{ |
131 |
1 |
PropFindMethod propFindMethod = new PropFindMethod(url); |
132 |
1 |
propFindMethod.setDoAuthentication(true); |
133 |
1 |
propFindMethod.setDepth(depth); |
134 |
1 |
testMethod(propFindMethod, expect); |
135 |
1 |
return propFindMethod; |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
@param |
142 |
|
@param |
143 |
|
@return@link |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
145 |
5 |
protected HttpMethod mkCol(String url, int expect) throws Exception... |
146 |
|
{ |
147 |
5 |
MkcolMethod mkColMethod = new MkcolMethod(); |
148 |
5 |
mkColMethod.setDoAuthentication(true); |
149 |
5 |
mkColMethod.setPath(url); |
150 |
5 |
testMethod(mkColMethod, expect); |
151 |
5 |
return mkColMethod; |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
@param |
158 |
|
@param@link |
159 |
|
@param |
160 |
|
@return@link |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
162 |
3 |
protected HttpMethod put(String url, String content, int expect) throws Exception... |
163 |
|
{ |
164 |
3 |
PutMethod putMethod = new PutMethod(); |
165 |
3 |
putMethod.setDoAuthentication(true); |
166 |
3 |
putMethod.setPath(url); |
167 |
3 |
putMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(content.getBytes()))); |
168 |
3 |
testMethod(putMethod, expect); |
169 |
3 |
return putMethod; |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
@param |
176 |
|
@param |
177 |
|
@return@link |
178 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
179 |
11 |
protected HttpMethod delete(String url, int expect) throws Exception... |
180 |
|
{ |
181 |
11 |
DeleteMethod deleteMethod = new DeleteMethod(); |
182 |
11 |
deleteMethod.setDoAuthentication(true); |
183 |
11 |
deleteMethod.setPath(url); |
184 |
11 |
testMethod(deleteMethod, expect); |
185 |
11 |
return deleteMethod; |
186 |
|
} |
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
@param |
192 |
|
@param@link |
193 |
|
@param |
194 |
|
@return@link |
195 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
196 |
16 |
protected HttpMethod move(String url, String destination, int expect) throws Exception... |
197 |
|
{ |
198 |
16 |
MoveMethod moveMethod = new MoveMethod(); |
199 |
16 |
moveMethod.setDoAuthentication(true); |
200 |
16 |
moveMethod.setPath(url); |
201 |
16 |
moveMethod.setDestination(destination); |
202 |
16 |
testMethod(moveMethod, expect); |
203 |
16 |
return moveMethod; |
204 |
|
} |
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
@param |
210 |
|
@param |
211 |
|
@return@link |
212 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
213 |
4 |
protected HttpMethod get(String url, int expect) throws Exception... |
214 |
|
{ |
215 |
4 |
GetMethod getMethod = new GetMethod(); |
216 |
4 |
getMethod.setDoAuthentication(true); |
217 |
4 |
getMethod.setPath(url); |
218 |
4 |
testMethod(getMethod, expect); |
219 |
4 |
return getMethod; |
220 |
|
} |
221 |
|
} |