1 source("fakes/FakeRESTService.R")
5 test_that("constructor raises error if file name is empty string", {
7 expect_that(ArvadosFile$new(""), throws_error("Invalid name."))
10 test_that("getFileListing always returns file name", {
12 dog <- ArvadosFile$new("dog")
14 expect_that(dog$getFileListing(), equals("dog"))
17 test_that("get always returns NULL", {
19 dog <- ArvadosFile$new("dog")
21 responseIsNull <- is.null(dog$get("something"))
22 expect_that(responseIsNull, is_true())
25 test_that("getFirst always returns NULL", {
27 dog <- ArvadosFile$new("dog")
29 responseIsNull <- is.null(dog$getFirst())
30 expect_that(responseIsNull, is_true())
33 test_that(paste("getSizeInBytes returns zero if arvadosFile",
34 "is not part of a collection"), {
36 dog <- ArvadosFile$new("dog")
38 expect_that(dog$getSizeInBytes(), equals(0))
41 test_that(paste("getSizeInBytes delegates size calculation",
42 "to REST service class"), {
44 collectionContent <- c("animal", "animal/fish")
46 fakeREST <- FakeRESTService$new(collectionContent, returnSize)
48 collection <- Collection$new("fakeUUID")
49 collection$setRESTService(fakeREST)
50 fish <- collection$get("animal/fish")
52 resourceSize <- fish$getSizeInBytes()
54 expect_that(resourceSize, equals(100))
57 test_that("getRelativePath returns path relative to the tree root", {
59 animal <- Subcollection$new("animal")
60 fish <- Subcollection$new("fish")
61 shark <- ArvadosFile$new("shark")
66 expect_that(shark$getRelativePath(), equals("animal/fish/shark"))
69 test_that("read raises exception if file doesn't belong to a collection", {
71 dog <- ArvadosFile$new("dog")
73 expect_that(dog$read(),
74 throws_error("ArvadosFile doesn't belong to any collection."))
77 test_that("read raises exception offset or length is negative number", {
80 collectionContent <- c("animal", "animal/fish")
81 fakeREST <- FakeRESTService$new(collectionContent)
83 collection <- Collection$new("fakeUUID")
84 collection$setRESTService(fakeREST)
85 fish <- collection$get("animal/fish")
87 expect_that(fish$read(contentType = "text", offset = -1),
88 throws_error("Offset and length must be positive values."))
89 expect_that(fish$read(contentType = "text", length = -1),
90 throws_error("Offset and length must be positive values."))
91 expect_that(fish$read(contentType = "text", offset = -1, length = -1),
92 throws_error("Offset and length must be positive values."))
95 test_that("read delegates reading operation to REST service class", {
97 collectionContent <- c("animal", "animal/fish")
98 readContent <- "my file"
99 fakeREST <- FakeRESTService$new(collectionContent, readContent)
101 collection <- Collection$new("fakeUUID")
102 collection$setRESTService(fakeREST)
103 fish <- collection$get("animal/fish")
105 fileContent <- fish$read("text")
107 expect_that(fileContent, equals("my file"))
108 expect_that(fakeREST$readCallCount, equals(1))
111 test_that(paste("connection delegates connection creation ro RESTService class",
112 "which returns curl connection opened in read mode when",
113 "'r' of 'rb' is passed as argument"), {
115 collectionContent <- c("animal", "animal/fish")
116 fakeREST <- FakeRESTService$new(collectionContent)
118 collection <- Collection$new("fakeUUID")
119 collection$setRESTService(fakeREST)
120 fish <- collection$get("animal/fish")
122 connection <- fish$connection("r")
124 expect_that(fakeREST$getConnectionCallCount, equals(1))
127 test_that(paste("connection returns textConnection opened",
128 "in write mode when 'w' is passed as argument"), {
130 collectionContent <- c("animal", "animal/fish")
131 fakeREST <- FakeRESTService$new(collectionContent)
133 collection <- Collection$new("fakeUUID")
134 collection$setRESTService(fakeREST)
135 fish <- collection$get("animal/fish")
137 connection <- fish$connection("w")
139 writeLines("file", connection)
140 writeLines("content", connection)
142 writeResult <- textConnectionValue(connection)
144 expect_that(writeResult[1], equals("file"))
145 expect_that(writeResult[2], equals("content"))
148 test_that("flush sends data stored in a connection to a REST server", {
151 collectionContent <- c("animal", "animal/fish")
152 fakeREST <- FakeRESTService$new(collectionContent)
154 collection <- Collection$new("fakeUUID")
155 collection$setRESTService(fakeREST)
156 fish <- collection$get("animal/fish")
158 connection <- fish$connection("w")
160 writeLines("file content", connection)
164 expect_that(fakeREST$writeBuffer, equals("file content"))
167 test_that("write raises exception if file doesn't belong to a collection", {
169 dog <- ArvadosFile$new("dog")
171 expect_that(dog$write(),
172 throws_error("ArvadosFile doesn't belong to any collection."))
175 test_that("write delegates writing operation to REST service class", {
178 collectionContent <- c("animal", "animal/fish")
179 fakeREST <- FakeRESTService$new(collectionContent)
181 collection <- Collection$new("fakeUUID")
182 collection$setRESTService(fakeREST)
183 fish <- collection$get("animal/fish")
185 fileContent <- fish$write("new file content")
187 expect_that(fakeREST$writeBuffer, equals("new file content"))
190 test_that(paste("move raises exception if arvados file",
191 "doesn't belong to any collection"), {
193 animal <- ArvadosFile$new("animal")
195 expect_that(animal$move("new/location"),
196 throws_error("ArvadosFile doesn't belong to any collection"))
199 test_that(paste("move raises exception if newLocationInCollection",
200 "parameter is invalid"), {
203 collectionContent <- c("animal",
209 fakeREST <- FakeRESTService$new(collectionContent)
211 collection <- Collection$new("fakeUUID")
212 collection$setRESTService(fakeREST)
213 dog <- collection$get("animal/dog")
215 expect_that(dog$move("objects/dog"),
216 throws_error("Unable to get destination subcollection"))
219 test_that("move raises exception if new location contains content with the same name", {
222 collectionContent <- c("animal",
228 fakeREST <- FakeRESTService$new(collectionContent)
230 collection <- Collection$new("fakeUUID")
231 collection$setRESTService(fakeREST)
232 dog <- collection$get("animal/dog")
234 expect_that(dog$move("dog"),
235 throws_error("Destination already contains content with same name."))
239 test_that("move moves arvados file inside collection tree", {
242 collectionContent <- c("animal",
248 fakeREST <- FakeRESTService$new(collectionContent)
250 collection <- Collection$new("fakeUUID")
251 collection$setRESTService(fakeREST)
252 dog <- collection$get("animal/dog")
255 dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
256 dogExistsOnNewLocation <- !is.null(collection$get("dog"))
258 expect_that(dogIsNullOnOldLocation, is_true())
259 expect_that(dogExistsOnNewLocation, is_true())