1 source("fakes/FakeArvados.R")
3 context("REST service")
5 test_that("create calls REST service properly", {
7 expectedURL <- "https://webdavHost/c=aaaaa-j7d0g-ccccccccccccccc/file"
8 fakeHttp <- FakeHttpRequest$new(expectedURL)
9 fakeHttpParser <- FakeHttpParser$new()
11 arv <- FakeArvados$new("token",
13 "https://webdavHost/",
17 REST <- RESTService$new(arv)
19 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
20 REST$create("file", uuid)
22 expect_that(fakeHttp$URLIsProperlyConfigured, is_true())
23 expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
24 expect_that(fakeHttp$numberOfPUTRequests, equals(1))
27 test_that("create raises exception if server response code is not between 200 and 300", {
30 response$status_code <- 404
31 fakeHttp <- FakeHttpRequest$new(serverResponse = response)
33 arv <- FakeArvados$new("token",
35 "https://webdavHost/",
39 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
40 REST <- RESTService$new(arv)
42 expect_that(REST$create("file", uuid),
43 throws_error("Server code: 404"))
46 test_that("delete calls REST service properly", {
48 expectedURL <- "https://webdavHost/c=aaaaa-j7d0g-ccccccccccccccc/file"
49 fakeHttp <- FakeHttpRequest$new(expectedURL)
50 fakeHttpParser <- FakeHttpParser$new()
52 arv <- FakeArvados$new("token",
54 "https://webdavHost/",
58 REST <- RESTService$new(arv)
60 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
61 REST$delete("file", uuid)
63 expect_that(fakeHttp$URLIsProperlyConfigured, is_true())
64 expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
65 expect_that(fakeHttp$numberOfDELETERequests, equals(1))
68 test_that("delete raises exception if server response code is not between 200 and 300", {
71 response$status_code <- 404
72 fakeHttp <- FakeHttpRequest$new(serverResponse = response)
74 arv <- FakeArvados$new("token",
76 "https://webdavHost/",
80 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
81 REST <- RESTService$new(arv)
83 expect_that(REST$delete("file", uuid),
84 throws_error("Server code: 404"))
87 test_that("move calls REST service properly", {
89 expectedURL <- "https://webdavHost/c=aaaaa-j7d0g-ccccccccccccccc/file"
90 fakeHttp <- FakeHttpRequest$new(expectedURL)
91 fakeHttpParser <- FakeHttpParser$new()
93 arv <- FakeArvados$new("token",
95 "https://webdavHost/",
99 REST <- RESTService$new(arv)
101 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
102 REST$move("file", "newDestination/file", uuid)
104 expect_that(fakeHttp$URLIsProperlyConfigured, is_true())
105 expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
106 expect_that(fakeHttp$requestHeaderContainsDestinationField, is_true())
107 expect_that(fakeHttp$numberOfMOVERequests, equals(1))
110 test_that("move raises exception if server response code is not between 200 and 300", {
113 response$status_code <- 404
114 fakeHttp <- FakeHttpRequest$new(serverResponse = response)
116 arv <- FakeArvados$new("token",
118 "https://webdavHost/",
120 FakeHttpParser$new())
122 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
123 REST <- RESTService$new(arv)
125 expect_that(REST$move("file", "newDestination/file", uuid),
126 throws_error("Server code: 404"))
129 test_that("getCollectionContent retreives correct content from WebDAV server", {
131 expectedURL <- "https://webdavHost/c=aaaaa-j7d0g-ccccccccccccccc"
132 returnContent <- c("animal", "animal/dog", "ball")
134 fakeHttp <- FakeHttpRequest$new(expectedURL, returnContent)
135 fakeHttpParser <- FakeHttpParser$new()
137 arv <- FakeArvados$new("token",
139 "https://webdavHost/",
143 REST <- RESTService$new(arv)
145 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
146 returnResult <- REST$getCollectionContent(uuid)
147 returnedContentMatchExpected <- all.equal(returnResult,
148 c("animal", "animal/dog", "ball"))
150 expect_that(returnedContentMatchExpected, is_true())
151 expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
154 test_that("getCollectionContent raises exception if server returns empty response", {
157 fakeHttp <- FakeHttpRequest$new(serverResponse = response)
159 arv <- FakeArvados$new("token",
161 "https://webdavHost/",
163 FakeHttpParser$new())
165 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
166 REST <- RESTService$new(arv)
168 expect_that(REST$getCollectionContent(uuid),
169 throws_error("Response is empty, request may be misconfigured"))
172 test_that("getCollectionContent parses server response", {
174 fakeHttp <- FakeHttpRequest$new()
175 fakeHttpParser <- FakeHttpParser$new()
177 arv <- FakeArvados$new("token",
179 "https://webdavHost/",
183 REST <- RESTService$new(arv)
185 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
186 REST$getCollectionContent(uuid)
188 expect_that(fakeHttpParser$parserCallCount, equals(1))
191 test_that("getResourceSize calls REST service properly", {
193 expectedURL <- "https://webdavHost/c=aaaaa-j7d0g-ccccccccccccccc/file"
194 expectedContent <- c("6", "2", "931", "12003")
195 fakeHttp <- FakeHttpRequest$new(expectedURL, expectedContent)
196 fakeHttpParser <- FakeHttpParser$new()
198 arv <- FakeArvados$new("token",
200 "https://webdavHost/",
204 REST <- RESTService$new(arv)
206 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
207 returnResult <- REST$getResourceSize("file", uuid)
208 returnedContentMatchExpected <- all.equal(returnResult,
209 as.numeric(expectedContent))
211 expect_that(fakeHttp$URLIsProperlyConfigured, is_true())
212 expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
213 expect_that(returnedContentMatchExpected, is_true())
216 test_that("getResourceSize raises exception if server returns empty response", {
219 fakeHttp <- FakeHttpRequest$new(serverResponse = response)
221 arv <- FakeArvados$new("token",
223 "https://webdavHost/",
225 FakeHttpParser$new())
227 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
228 REST <- RESTService$new(arv)
230 expect_that(REST$getResourceSize("file", uuid),
231 throws_error("Response is empty, request may be misconfigured"))
234 test_that("getResourceSize parses server response", {
236 fakeHttp <- FakeHttpRequest$new()
237 fakeHttpParser <- FakeHttpParser$new()
239 arv <- FakeArvados$new("token",
241 "https://webdavHost/",
245 REST <- RESTService$new(arv)
247 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
248 REST$getResourceSize("file", uuid)
250 expect_that(fakeHttpParser$parserCallCount, equals(1))
253 test_that("read calls REST service properly", {
255 expectedURL <- "https://webdavHost/c=aaaaa-j7d0g-ccccccccccccccc/file"
256 serverResponse <- list()
257 serverResponse$status_code <- 200
258 serverResponse$content <- "file content"
260 fakeHttp <- FakeHttpRequest$new(expectedURL, serverResponse)
261 fakeHttpParser <- FakeHttpParser$new()
263 arv <- FakeArvados$new("token",
265 "https://webdavHost/",
269 REST <- RESTService$new(arv)
271 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
272 returnResult <- REST$read("file", uuid, "text", 1024, 512)
274 expect_that(fakeHttp$URLIsProperlyConfigured, is_true())
275 expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
276 expect_that(fakeHttp$requestHeaderContainsRangeField, is_true())
277 expect_that(returnResult, equals("file content"))
280 test_that("read raises exception if server response code is not between 200 and 300", {
283 response$status_code <- 404
284 fakeHttp <- FakeHttpRequest$new(serverResponse = response)
286 arv <- FakeArvados$new("token",
288 "https://webdavHost/",
290 FakeHttpParser$new())
292 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
293 REST <- RESTService$new(arv)
295 expect_that(REST$read("file", uuid),
296 throws_error("Server code: 404"))
299 test_that("read raises exception if contentType is not valid", {
301 fakeHttp <- FakeHttpRequest$new()
303 arv <- FakeArvados$new("token",
305 "https://webdavHost/",
307 FakeHttpParser$new())
309 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
310 REST <- RESTService$new(arv)
312 expect_that(REST$read("file", uuid, "some invalid content type"),
313 throws_error("Invalid contentType. Please use text or raw."))
316 test_that("read parses server response", {
318 fakeHttp <- FakeHttpRequest$new()
319 fakeHttpParser <- FakeHttpParser$new()
321 arv <- FakeArvados$new("token",
323 "https://webdavHost/",
327 REST <- RESTService$new(arv)
329 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
330 REST$getCollectionContent(uuid)
332 expect_that(fakeHttpParser$parserCallCount, equals(1))
335 test_that("write calls REST service properly", {
337 expectedURL <- "https://webdavHost/c=aaaaa-j7d0g-ccccccccccccccc/file"
338 fakeHttp <- FakeHttpRequest$new(expectedURL)
339 fakeHttpParser <- FakeHttpParser$new()
341 arv <- FakeArvados$new("token",
343 "https://webdavHost/",
347 REST <- RESTService$new(arv)
349 fileContent <- "new file content"
350 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
351 REST$write("file", uuid, fileContent, "text/html")
353 expect_that(fakeHttp$URLIsProperlyConfigured, is_true())
354 expect_that(fakeHttp$requestBodyIsProvided, is_true())
355 expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
356 expect_that(fakeHttp$requestHeaderContainsContentTypeField, is_true())
359 test_that("write raises exception if server response code is not between 200 and 300", {
362 response$status_code <- 404
363 fakeHttp <- FakeHttpRequest$new(serverResponse = response)
365 arv <- FakeArvados$new("token",
367 "https://webdavHost/",
369 FakeHttpParser$new())
371 uuid <- "aaaaa-j7d0g-ccccccccccccccc"
372 fileContent <- "new file content"
373 REST <- RESTService$new(arv)
375 expect_that(REST$write("file", uuid, fileContent, "text/html"),
376 throws_error("Server code: 404"))