@@ -14,16 +14,13 @@ import at.bitfire.dav4jvm.exception.HttpException
14
14
import at.bitfire.dav4jvm.property.webdav.GetETag
15
15
import at.bitfire.dav4jvm.property.webdav.NS_WEBDAV
16
16
import at.bitfire.dav4jvm.property.webdav.SyncToken
17
+ import mockwebserver3.MockResponse
18
+ import mockwebserver3.MockWebServer
17
19
import okhttp3.MediaType.Companion.toMediaType
18
20
import okhttp3.OkHttpClient
19
21
import okhttp3.RequestBody.Companion.toRequestBody
20
- import okhttp3.mockwebserver.MockResponse
21
- import okhttp3.mockwebserver.MockWebServer
22
22
import org.junit.After
23
- import org.junit.Assert.assertEquals
24
- import org.junit.Assert.assertFalse
25
- import org.junit.Assert.assertTrue
26
- import org.junit.Assert.fail
23
+ import org.junit.Assert.*
27
24
import org.junit.Before
28
25
import org.junit.Test
29
26
import java.net.HttpURLConnection
@@ -42,7 +39,7 @@ class DavCollectionTest {
42
39
fun startServer () = mockServer.start()
43
40
44
41
@After
45
- fun stopServer () = mockServer.shutdown ()
42
+ fun stopServer () = mockServer.close ()
46
43
47
44
48
45
/* *
@@ -53,58 +50,62 @@ class DavCollectionTest {
53
50
val url = sampleUrl()
54
51
val collection = DavCollection (httpClient, url)
55
52
56
- mockServer.enqueue(MockResponse ()
57
- .setResponseCode(207 )
53
+ mockServer.enqueue(
54
+ MockResponse .Builder ()
55
+ .code(207 )
58
56
.setHeader(" Content-Type" , " text/xml; charset=\" utf-8\" " )
59
- .setBody(" <?xml version=\" 1.0\" encoding=\" utf-8\" ?>\n " +
60
- " <D:multistatus xmlns:D=\" DAV:\" >\n " +
61
- " <D:response>\n " +
62
- " <D:href\n " +
63
- " >${sampleUrl()} test.doc</D:href>\n " +
64
- " <D:propstat>\n " +
65
- " <D:prop>\n " +
66
- " <D:getetag>\" 00001-abcd1\" </D:getetag>\n " +
67
- " <R:bigbox xmlns:R=\" urn:ns.example.com:boxschema\" >\n " +
68
- " <R:BoxType>Box type A</R:BoxType>\n " +
69
- " </R:bigbox>\n " +
70
- " </D:prop>\n " +
71
- " <D:status>HTTP/1.1 200 OK</D:status>\n " +
72
- " </D:propstat>\n " +
73
- " </D:response>\n " +
74
- " <D:response>\n " +
75
- " <D:href\n " +
76
- " >${sampleUrl()} vcard.vcf</D:href>\n " +
77
- " <D:propstat>\n " +
78
- " <D:prop>\n " +
79
- " <D:getetag>\" 00002-abcd1\" </D:getetag>\n " +
80
- " </D:prop>\n " +
81
- " <D:status>HTTP/1.1 200 OK</D:status>\n " +
82
- " </D:propstat>\n " +
83
- " <D:propstat>\n " +
84
- " <D:prop>\n " +
85
- " <R:bigbox xmlns:R=\" urn:ns.example.com:boxschema\" />\n " +
86
- " </D:prop>\n " +
87
- " <D:status>HTTP/1.1 404 Not Found</D:status>\n " +
88
- " </D:propstat>\n " +
89
- " </D:response>\n " +
90
- " <D:response>\n " +
91
- " <D:href\n " +
92
- " >${sampleUrl()} calendar.ics</D:href>\n " +
93
- " <D:propstat>\n " +
94
- " <D:prop>\n " +
95
- " <D:getetag>\" 00003-abcd1\" </D:getetag>\n " +
96
- " </D:prop>\n " +
97
- " <D:status>HTTP/1.1 200 OK</D:status>\n " +
98
- " </D:propstat>\n " +
99
- " <D:propstat>\n " +
100
- " <D:prop>\n " +
101
- " <R:bigbox xmlns:R=\" urn:ns.example.com:boxschema\" />\n " +
102
- " </D:prop>\n " +
103
- " <D:status>HTTP/1.1 404 Not Found</D:status>\n " +
104
- " </D:propstat>\n " +
105
- " </D:response>\n " +
106
- " <D:sync-token>http://example.com/ns/sync/1234</D:sync-token>\n " +
107
- " </D:multistatus>" )
57
+ .body(
58
+ " <?xml version=\" 1.0\" encoding=\" utf-8\" ?>\n " +
59
+ " <D:multistatus xmlns:D=\" DAV:\" >\n " +
60
+ " <D:response>\n " +
61
+ " <D:href\n " +
62
+ " >${sampleUrl()} test.doc</D:href>\n " +
63
+ " <D:propstat>\n " +
64
+ " <D:prop>\n " +
65
+ " <D:getetag>\" 00001-abcd1\" </D:getetag>\n " +
66
+ " <R:bigbox xmlns:R=\" urn:ns.example.com:boxschema\" >\n " +
67
+ " <R:BoxType>Box type A</R:BoxType>\n " +
68
+ " </R:bigbox>\n " +
69
+ " </D:prop>\n " +
70
+ " <D:status>HTTP/1.1 200 OK</D:status>\n " +
71
+ " </D:propstat>\n " +
72
+ " </D:response>\n " +
73
+ " <D:response>\n " +
74
+ " <D:href\n " +
75
+ " >${sampleUrl()} vcard.vcf</D:href>\n " +
76
+ " <D:propstat>\n " +
77
+ " <D:prop>\n " +
78
+ " <D:getetag>\" 00002-abcd1\" </D:getetag>\n " +
79
+ " </D:prop>\n " +
80
+ " <D:status>HTTP/1.1 200 OK</D:status>\n " +
81
+ " </D:propstat>\n " +
82
+ " <D:propstat>\n " +
83
+ " <D:prop>\n " +
84
+ " <R:bigbox xmlns:R=\" urn:ns.example.com:boxschema\" />\n " +
85
+ " </D:prop>\n " +
86
+ " <D:status>HTTP/1.1 404 Not Found</D:status>\n " +
87
+ " </D:propstat>\n " +
88
+ " </D:response>\n " +
89
+ " <D:response>\n " +
90
+ " <D:href\n " +
91
+ " >${sampleUrl()} calendar.ics</D:href>\n " +
92
+ " <D:propstat>\n " +
93
+ " <D:prop>\n " +
94
+ " <D:getetag>\" 00003-abcd1\" </D:getetag>\n " +
95
+ " </D:prop>\n " +
96
+ " <D:status>HTTP/1.1 200 OK</D:status>\n " +
97
+ " </D:propstat>\n " +
98
+ " <D:propstat>\n " +
99
+ " <D:prop>\n " +
100
+ " <R:bigbox xmlns:R=\" urn:ns.example.com:boxschema\" />\n " +
101
+ " </D:prop>\n " +
102
+ " <D:status>HTTP/1.1 404 Not Found</D:status>\n " +
103
+ " </D:propstat>\n " +
104
+ " </D:response>\n " +
105
+ " <D:sync-token>http://example.com/ns/sync/1234</D:sync-token>\n " +
106
+ " </D:multistatus>"
107
+ )
108
+ .build()
108
109
)
109
110
var nrCalled = 0
110
111
val result = collection.reportChanges(null , false , null , GetETag .NAME ) { response, relation ->
@@ -147,40 +148,44 @@ class DavCollectionTest {
147
148
val url = sampleUrl()
148
149
val collection = DavCollection (httpClient, url)
149
150
150
- mockServer.enqueue(MockResponse ()
151
- .setResponseCode(207 )
151
+ mockServer.enqueue(
152
+ MockResponse .Builder ()
153
+ .code(207 )
152
154
.setHeader(" Content-Type" , " text/xml; charset=\" utf-8\" " )
153
- .setBody(" <?xml version=\" 1.0\" encoding=\" utf-8\" ?>\n " +
154
- " <D:multistatus xmlns:D=\" DAV:\" >\n " +
155
- " <D:response>\n " +
156
- " <D:href>${sampleUrl()} test.doc</D:href>\n " +
157
- " <D:propstat>\n " +
158
- " <D:prop>\n " +
159
- " <D:getetag>\" 00001-abcd1\" </D:getetag>\n " +
160
- " </D:prop>\n " +
161
- " <D:status>HTTP/1.1 200 OK</D:status>\n " +
162
- " </D:propstat>\n " +
163
- " </D:response>\n " +
164
- " <D:response>\n " +
165
- " <D:href>${sampleUrl()} vcard.vcf</D:href>\n " +
166
- " <D:propstat>\n " +
167
- " <D:prop>\n " +
168
- " <D:getetag>\" 00002-abcd1\" </D:getetag>\n " +
169
- " </D:prop>\n " +
170
- " <D:status>HTTP/1.1 200 OK</D:status>\n " +
171
- " </D:propstat>\n " +
172
- " </D:response>\n " +
173
- " <D:response>\n " +
174
- " <D:href>${sampleUrl()} removed.txt</D:href>\n " +
175
- " <D:status>HTTP/1.1 404 Not Found</D:status>\n " +
176
- " </D:response>" +
177
- " <D:response>\n " +
178
- " <D:href>${sampleUrl()} </D:href>\n " +
179
- " <D:status>HTTP/1.1 507 Insufficient Storage</D:status>\n " +
180
- " <D:error><D:number-of-matches-within-limits/></D:error>\n " +
181
- " </D:response>" +
182
- " <D:sync-token>http://example.com/ns/sync/1233</D:sync-token>\n " +
183
- " </D:multistatus>" )
155
+ .body(
156
+ " <?xml version=\" 1.0\" encoding=\" utf-8\" ?>\n " +
157
+ " <D:multistatus xmlns:D=\" DAV:\" >\n " +
158
+ " <D:response>\n " +
159
+ " <D:href>${sampleUrl()} test.doc</D:href>\n " +
160
+ " <D:propstat>\n " +
161
+ " <D:prop>\n " +
162
+ " <D:getetag>\" 00001-abcd1\" </D:getetag>\n " +
163
+ " </D:prop>\n " +
164
+ " <D:status>HTTP/1.1 200 OK</D:status>\n " +
165
+ " </D:propstat>\n " +
166
+ " </D:response>\n " +
167
+ " <D:response>\n " +
168
+ " <D:href>${sampleUrl()} vcard.vcf</D:href>\n " +
169
+ " <D:propstat>\n " +
170
+ " <D:prop>\n " +
171
+ " <D:getetag>\" 00002-abcd1\" </D:getetag>\n " +
172
+ " </D:prop>\n " +
173
+ " <D:status>HTTP/1.1 200 OK</D:status>\n " +
174
+ " </D:propstat>\n " +
175
+ " </D:response>\n " +
176
+ " <D:response>\n " +
177
+ " <D:href>${sampleUrl()} removed.txt</D:href>\n " +
178
+ " <D:status>HTTP/1.1 404 Not Found</D:status>\n " +
179
+ " </D:response>" +
180
+ " <D:response>\n " +
181
+ " <D:href>${sampleUrl()} </D:href>\n " +
182
+ " <D:status>HTTP/1.1 507 Insufficient Storage</D:status>\n " +
183
+ " <D:error><D:number-of-matches-within-limits/></D:error>\n " +
184
+ " </D:response>" +
185
+ " <D:sync-token>http://example.com/ns/sync/1233</D:sync-token>\n " +
186
+ " </D:multistatus>"
187
+ )
188
+ .build()
184
189
)
185
190
var nrCalled = 0
186
191
val result = collection.reportChanges(null , false , null , GetETag .NAME ) { response, relation ->
@@ -227,13 +232,17 @@ class DavCollectionTest {
227
232
val url = sampleUrl()
228
233
val collection = DavCollection (httpClient, url)
229
234
230
- mockServer.enqueue(MockResponse ()
231
- .setResponseCode(507 )
235
+ mockServer.enqueue(
236
+ MockResponse .Builder ()
237
+ .code(507 )
232
238
.setHeader(" Content-Type" , " text/xml; charset=\" utf-8\" " )
233
- .setBody(" <?xml version=\" 1.0\" encoding=\" utf-8\" ?>\n " +
234
- " <D:error xmlns:D=\" DAV:\" >\n " +
235
- " <D:number-of-matches-within-limits/>\n " +
236
- " </D:error>" )
239
+ .body(
240
+ " <?xml version=\" 1.0\" encoding=\" utf-8\" ?>\n " +
241
+ " <D:error xmlns:D=\" DAV:\" >\n " +
242
+ " <D:number-of-matches-within-limits/>\n " +
243
+ " </D:error>"
244
+ )
245
+ .build()
237
246
)
238
247
239
248
try {
@@ -252,7 +261,7 @@ class DavCollectionTest {
252
261
val dav = DavCollection (httpClient, url)
253
262
254
263
// 201 Created
255
- mockServer.enqueue(MockResponse ().setResponseCode (HttpURLConnection .HTTP_CREATED ))
264
+ mockServer.enqueue(MockResponse . Builder ().code (HttpURLConnection .HTTP_CREATED ).build( ))
256
265
var called = false
257
266
dav.post(sampleText.toRequestBody(" text/plain" .toMediaType())) { response ->
258
267
assertEquals(" POST" , mockServer.takeRequest().method)
0 commit comments