1 source("fakes/FakeRESTService.R")
5 test_that(paste("constructor creates file tree from text content",
6 "retreived form REST service"), {
8 collectionContent <- c("animal", "animal/fish", "ball")
9 fakeREST <- FakeRESTService$new(collectionContent)
11 api <- Arvados$new("myToken", "myHostName")
12 api$setRESTService(fakeREST)
13 collection <- Collection$new(api, "myUUID")
15 root <- collection$get("")
17 expect_that(fakeREST$getCollectionContentCallCount, equals(1))
18 expect_that(root$getName(), equals(""))
21 test_that(paste("add raises exception if passed argumet is not",
22 "ArvadosFile or Subcollection"), {
24 collectionContent <- c("animal", "animal/fish", "ball")
25 fakeREST <- FakeRESTService$new(collectionContent)
27 api <- Arvados$new("myToken", "myHostName")
28 api$setRESTService(fakeREST)
29 collection <- Collection$new(api, "myUUID")
33 expect_that(collection$add(newNumber),
34 throws_error(paste("Expected AravodsFile or Subcollection",
35 "object, got (numeric)."), fixed = TRUE))
38 test_that("add raises exception if relative path is not valid", {
40 collectionContent <- c("animal", "animal/fish", "ball")
41 fakeREST <- FakeRESTService$new(collectionContent)
43 api <- Arvados$new("myToken", "myHostName")
44 api$setRESTService(fakeREST)
45 collection <- Collection$new(api, "myUUID")
47 newPen <- ArvadosFile$new("pen")
49 expect_that(collection$add(newPen, "objects"),
50 throws_error("Subcollection objects doesn't exist.",
54 test_that("add raises exception if content name is empty string", {
56 collectionContent <- c("animal", "animal/fish")
57 fakeREST <- FakeRESTService$new(collectionContent)
59 api <- Arvados$new("myToken", "myHostName")
60 api$setRESTService(fakeREST)
61 collection <- Collection$new(api, "myUUID")
63 rootFolder <- Subcollection$new("")
65 expect_that(collection$add(rootFolder),
66 throws_error("Content has invalid name.", fixed = TRUE))
69 test_that(paste("add adds ArvadosFile or Subcollection",
70 "to local tree structure and remote REST service"), {
72 collectionContent <- c("animal", "animal/fish", "ball")
73 fakeREST <- FakeRESTService$new(collectionContent)
75 api <- Arvados$new("myToken", "myHostName")
76 api$setRESTService(fakeREST)
77 collection <- Collection$new(api, "myUUID")
79 newDog <- ArvadosFile$new("dog")
80 collection$add(newDog, "animal")
82 dog <- collection$get("animal/dog")
83 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
85 expect_that(dogExistsInCollection, is_true())
86 expect_that(fakeREST$createCallCount, equals(1))
89 test_that("create raises exception if passed argumet is not character vector", {
91 collectionContent <- c("animal", "animal/fish", "ball")
92 fakeREST <- FakeRESTService$new(collectionContent)
94 api <- Arvados$new("myToken", "myHostName")
95 api$setRESTService(fakeREST)
96 collection <- Collection$new(api, "myUUID")
98 expect_that(collection$create(10),
99 throws_error("Expected character vector, got (numeric).",
103 test_that("create raises exception if relative path is not valid", {
105 collectionContent <- c("animal",
109 fakeREST <- FakeRESTService$new(collectionContent)
111 api <- Arvados$new("myToken", "myHostName")
112 api$setRESTService(fakeREST)
113 collection <- Collection$new(api, "myUUID")
115 newPen <- ArvadosFile$new("pen")
117 expect_that(collection$create(newPen, "objects"),
118 throws_error("Subcollection objects doesn't exist.",
122 test_that(paste("create adds files specified by fileNames",
123 "to local tree structure and remote REST service"), {
125 collectionContent <- c("animal", "animal/fish", "ball")
126 fakeREST <- FakeRESTService$new(collectionContent)
128 api <- Arvados$new("myToken", "myHostName")
129 api$setRESTService(fakeREST)
130 collection <- Collection$new(api, "myUUID")
132 files <- c("dog", "cat")
133 collection$create(files, "animal")
135 dog <- collection$get("animal/dog")
136 cat <- collection$get("animal/cat")
137 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
138 catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
140 expect_that(dogExistsInCollection, is_true())
141 expect_that(catExistsInCollection, is_true())
142 expect_that(fakeREST$createCallCount, equals(2))
145 test_that("remove raises exception if passed argumet is not character vector", {
147 collectionContent <- c("animal", "animal/fish", "ball")
148 fakeREST <- FakeRESTService$new(collectionContent)
150 api <- Arvados$new("myToken", "myHostName")
151 api$setRESTService(fakeREST)
152 collection <- Collection$new(api, "myUUID")
154 expect_that(collection$remove(10),
155 throws_error("Expected character vector, got (numeric).",
159 test_that("remove raises exception if user tries to remove root folder", {
161 collectionContent <- c("animal", "animal/fish")
162 fakeREST <- FakeRESTService$new(collectionContent)
164 api <- Arvados$new("myToken", "myHostName")
165 api$setRESTService(fakeREST)
166 collection <- Collection$new(api, "myUUID")
168 expect_that(collection$remove(""),
169 throws_error("You can't delete root folder.", fixed = TRUE))
172 test_that(paste("remove removes files specified by paths",
173 "from local tree structure and from remote REST service"), {
175 collectionContent <- c("animal", "animal/fish", "animal/dog", "animal/cat", "ball")
176 fakeREST <- FakeRESTService$new(collectionContent)
178 api <- Arvados$new("myToken", "myHostName")
179 api$setRESTService(fakeREST)
180 collection <- Collection$new(api, "myUUID")
182 collection$remove(c("animal/dog", "animal/cat"))
184 dog <- collection$get("animal/dog")
185 cat <- collection$get("animal/dog")
186 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
187 catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
189 expect_that(dogExistsInCollection, is_false())
190 expect_that(catExistsInCollection, is_false())
191 expect_that(fakeREST$deleteCallCount, equals(2))
194 test_that(paste("move moves content to a new location inside file tree",
195 "and on REST service"), {
197 collectionContent <- c("animal", "animal/dog", "ball")
198 fakeREST <- FakeRESTService$new(collectionContent)
200 api <- Arvados$new("myToken", "myHostName")
201 api$setRESTService(fakeREST)
202 collection <- Collection$new(api, "myUUID")
204 collection$move("animal/dog", "dog")
206 dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
207 dogExistsOnNewLocation <- !is.null(collection$get("dog"))
209 expect_that(dogIsNullOnOldLocation, is_true())
210 expect_that(dogExistsOnNewLocation, is_true())
211 expect_that(fakeREST$moveCallCount, equals(1))
214 test_that("move raises exception if new location is not valid", {
216 collectionContent <- c("animal", "animal/fish", "ball")
217 fakeREST <- FakeRESTService$new(collectionContent)
219 api <- Arvados$new("myToken", "myHostName")
220 api$setRESTService(fakeREST)
221 collection <- Collection$new(api, "myUUID")
223 expect_that(collection$move("fish", "object"),
224 throws_error("Content you want to move doesn't exist in the collection.",
228 test_that("getFileListing returns sorted collection content received from REST service", {
230 collectionContent <- c("animal", "animal/fish", "ball")
231 fakeREST <- FakeRESTService$new(collectionContent)
233 api <- Arvados$new("myToken", "myHostName")
234 api$setRESTService(fakeREST)
235 collection <- Collection$new(api, "myUUID")
237 contentMatchExpected <- all(collection$getFileListing() ==
238 c("animal", "animal/fish", "ball"))
240 expect_that(contentMatchExpected, is_true())
241 #2 calls because Collection$new calls getFileListing once
242 expect_that(fakeREST$getCollectionContentCallCount, equals(2))
246 test_that("get returns arvados file or subcollection from internal tree structure", {
248 collectionContent <- c("animal", "animal/fish", "ball")
249 fakeREST <- FakeRESTService$new(collectionContent)
251 api <- Arvados$new("myToken", "myHostName")
252 api$setRESTService(fakeREST)
253 collection <- Collection$new(api, "myUUID")
255 fish <- collection$get("animal/fish")
256 fishIsNotNull <- !is.null(fish)
258 expect_that(fishIsNotNull, is_true())
259 expect_that(fish$getName(), equals("fish"))