1 source("fakes/FakeRESTService.R")
5 test_that("getFileListing always returns file name", {
7 dog <- ArvadosFile$new("dog")
9 expect_that(dog$getFileListing(), equals("dog"))
12 test_that("get always returns NULL", {
14 dog <- ArvadosFile$new("dog")
16 responseIsNull <- is.null(dog$get("something"))
17 expect_that(responseIsNull, is_true())
20 test_that("getFirst always returns NULL", {
22 dog <- ArvadosFile$new("dog")
24 responseIsNull <- is.null(dog$getFirst())
25 expect_that(responseIsNull, is_true())
28 test_that(paste("getSizeInBytes returns zero if arvadosFile",
29 "is not part of a collection"), {
31 dog <- ArvadosFile$new("dog")
33 expect_that(dog$getSizeInBytes(), equals(0))
36 test_that(paste("getSizeInBytes delegates size calculation",
37 "to REST service class"), {
39 api <- Arvados$new("myToken", "myHostName")
40 api$setHttpClient(FakeHttpRequest$new())
41 api$setHttpParser(FakeHttpParser$new())
43 collectionContent <- c("animal", "animal/fish")
46 fakeREST <- FakeRESTService$new(collectionContent, returnSize)
47 api$setRESTService(fakeREST)
48 collection <- Collection$new(api, "myUUID")
49 fish <- collection$get("animal/fish")
51 resourceSize <- fish$getSizeInBytes()
53 expect_that(resourceSize, equals(100))
56 test_that("getRelativePath returns path relative to the tree root", {
58 animal <- Subcollection$new("animal")
59 fish <- Subcollection$new("fish")
60 shark <- ArvadosFile$new("shark")
65 expect_that(shark$getRelativePath(), equals("animal/fish/shark"))
68 test_that("read raises exception if file doesn't belong to a collection", {
70 dog <- ArvadosFile$new("dog")
72 expect_that(dog$read(),
73 throws_error("ArvadosFile doesn't belong to any collection."))
76 test_that("read raises exception offset or length is negative number", {
78 api <- Arvados$new("myToken", "myHostName")
79 api$setHttpClient(FakeHttpRequest$new())
80 api$setHttpParser(FakeHttpParser$new())
82 collectionContent <- c("animal", "animal/fish")
84 fakeREST <- FakeRESTService$new(collectionContent)
85 api$setRESTService(fakeREST)
86 collection <- Collection$new(api, "myUUID")
87 fish <- collection$get("animal/fish")
89 expect_that(fish$read(contentType = "text", offset = -1),
90 throws_error("Offset and length must be positive values."))
91 expect_that(fish$read(contentType = "text", length = -1),
92 throws_error("Offset and length must be positive values."))
93 expect_that(fish$read(contentType = "text", offset = -1, length = -1),
94 throws_error("Offset and length must be positive values."))
97 test_that("read delegates reading operation to REST service class", {
99 api <- Arvados$new("myToken", "myHostName")
100 api$setHttpClient(FakeHttpRequest$new())
101 api$setHttpParser(FakeHttpParser$new())
103 collectionContent <- c("animal", "animal/fish")
104 readContent <- "my file"
106 fakeREST <- FakeRESTService$new(collectionContent, readContent)
107 api$setRESTService(fakeREST)
108 collection <- Collection$new(api, "myUUID")
109 fish <- collection$get("animal/fish")
111 fileContent <- fish$read("text")
113 expect_that(fileContent, equals("my file"))
114 expect_that(fakeREST$readCallCount, equals(1))
117 test_that(paste("connect returns textConnection opened",
118 "in read mode when 'r' is passed as argument"), {
120 api <- Arvados$new("myToken", "myHostName")
121 api$setHttpClient(FakeHttpRequest$new())
122 api$setHttpParser(FakeHttpParser$new())
124 collectionContent <- c("animal", "animal/fish")
125 readContent <- "file content"
127 fakeREST <- FakeRESTService$new(collectionContent, readContent)
128 api$setRESTService(fakeREST)
129 collection <- Collection$new(api, "myUUID")
130 fish <- collection$get("animal/fish")
132 connection <- fish$connection("r")
134 expect_that(readLines(connection), equals("file content"))
137 test_that(paste("connect returns textConnection opened",
138 "in write mode when 'w' is passed as argument"), {
140 api <- Arvados$new("myToken", "myHostName")
141 api$setHttpClient(FakeHttpRequest$new())
142 api$setHttpParser(FakeHttpParser$new())
144 collectionContent <- c("animal", "animal/fish")
146 fakeREST <- FakeRESTService$new(collectionContent)
147 api$setRESTService(fakeREST)
148 collection <- Collection$new(api, "myUUID")
149 fish <- collection$get("animal/fish")
151 connection <- fish$connection("w")
153 writeLines("file", connection)
154 writeLines("content", connection)
156 writeResult <- textConnectionValue(connection)
158 expect_that(writeResult[1], equals("file"))
159 expect_that(writeResult[2], equals("content"))
162 test_that("flush sends data stored in a connection to a REST server", {
164 api <- Arvados$new("myToken", "myHostName")
165 api$setHttpClient(FakeHttpRequest$new())
166 api$setHttpParser(FakeHttpParser$new())
168 collectionContent <- c("animal", "animal/fish")
170 fakeREST <- FakeRESTService$new(collectionContent)
171 api$setRESTService(fakeREST)
172 collection <- Collection$new(api, "myUUID")
173 fish <- collection$get("animal/fish")
175 connection <- fish$connection("w")
177 writeLines("file content", connection)
181 expect_that(fakeREST$writeBuffer, equals("file content"))
184 test_that("write raises exception if file doesn't belong to a collection", {
186 dog <- ArvadosFile$new("dog")
188 expect_that(dog$write(),
189 throws_error("ArvadosFile doesn't belong to any collection."))
192 test_that("write delegates writing operation to REST service class", {
194 api <- Arvados$new("myToken", "myHostName")
195 api$setHttpClient(FakeHttpRequest$new())
196 api$setHttpParser(FakeHttpParser$new())
198 collectionContent <- c("animal", "animal/fish")
200 fakeREST <- FakeRESTService$new(collectionContent)
201 api$setRESTService(fakeREST)
202 collection <- Collection$new(api, "myUUID")
203 fish <- collection$get("animal/fish")
205 fileContent <- fish$write("new file content")
207 expect_that(fakeREST$writeBuffer, equals("new file content"))
210 test_that(paste("move raises exception if arvados file",
211 "doesn't belong to any collection"), {
213 animal <- ArvadosFile$new("animal")
215 expect_that(animal$move("new/location"),
216 throws_error("ArvadosFile doesn't belong to any collection"))
219 test_that(paste("move raises exception if newLocationInCollection",
220 "parameter is invalid"), {
222 api <- Arvados$new("myToken", "myHostName")
223 api$setHttpClient(FakeHttpRequest$new())
224 api$setHttpParser(FakeHttpParser$new())
226 collectionContent <- c("animal",
232 fakeREST <- FakeRESTService$new(collectionContent)
233 api$setRESTService(fakeREST)
235 collection <- Collection$new(api, "myUUID")
236 dog <- collection$get("animal/dog")
238 expect_that(dog$move("objects/dog"),
239 throws_error("Unable to get destination subcollection"))
242 test_that("move raises exception if new location contains content with the same name", {
244 api <- Arvados$new("myToken", "myHostName")
245 api$setHttpClient(FakeHttpRequest$new())
246 api$setHttpParser(FakeHttpParser$new())
248 collectionContent <- c("animal",
254 fakeREST <- FakeRESTService$new(collectionContent)
255 api$setRESTService(fakeREST)
256 collection <- Collection$new(api, "myUUID")
257 dog <- collection$get("animal/dog")
259 expect_that(dog$move("dog"),
260 throws_error("Destination already contains content with same name."))
264 test_that("move moves arvados file inside collection tree", {
266 api <- Arvados$new("myToken", "myHostName")
267 api$setHttpClient(FakeHttpRequest$new())
268 api$setHttpParser(FakeHttpParser$new())
270 collectionContent <- c("animal",
276 fakeREST <- FakeRESTService$new(collectionContent)
277 api$setRESTService(fakeREST)
278 collection <- Collection$new(api, "myUUID")
279 dog <- collection$get("animal/dog")
282 dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
283 dogExistsOnNewLocation <- !is.null(collection$get("dog"))
285 expect_that(dogIsNullOnOldLocation, is_true())
286 expect_that(dogExistsOnNewLocation, is_true())