1 source("fakes/FakeRESTService.R")
5 test_that(paste("constructor creates file tree from text content",
6 "retreived form REST service"), {
8 api <- Arvados$new("myToken", "myHostName")
9 api$setHttpClient(FakeHttpRequest$new())
10 api$setHttpParser(FakeHttpParser$new())
12 collectionContent <- c("animal",
16 fakeREST <- FakeRESTService$new(collectionContent)
17 api$setRESTService(fakeREST)
18 collection <- Collection$new(api, "myUUID")
20 root <- collection$get("")
22 expect_that(fakeREST$getCollectionContentCallCount, equals(1))
23 expect_that(root$getName(), equals(""))
26 test_that(paste("add raises exception if passed argumet is not",
27 "ArvadosFile or Subcollection"), {
29 api <- Arvados$new("myToken", "myHostName")
30 api$setHttpClient(FakeHttpRequest$new())
31 api$setHttpParser(FakeHttpParser$new())
33 collectionContent <- c("animal",
37 fakeREST <- FakeRESTService$new(collectionContent)
38 api$setRESTService(fakeREST)
39 collection <- Collection$new(api, "myUUID")
43 expect_that(collection$add(newNumber),
44 throws_error(paste("Expected AravodsFile or Subcollection",
45 "object, got (numeric)."), fixed = TRUE))
48 test_that("add raises exception if relative path is not valid", {
50 api <- Arvados$new("myToken", "myHostName")
51 api$setHttpClient(FakeHttpRequest$new())
52 api$setHttpParser(FakeHttpParser$new())
54 collectionContent <- c("animal",
58 fakeREST <- FakeRESTService$new(collectionContent)
59 api$setRESTService(fakeREST)
60 collection <- Collection$new(api, "myUUID")
62 newPen <- ArvadosFile$new("pen")
64 expect_that(collection$add(newPen, "objects"),
65 throws_error("Subcollection objects doesn't exist.",
69 test_that(paste("add adds ArvadosFile or Subcollection",
70 "to local tree structure and remote REST service"), {
72 api <- Arvados$new("myToken", "myHostName")
73 api$setHttpClient(FakeHttpRequest$new())
74 api$setHttpParser(FakeHttpParser$new())
76 collectionContent <- c("animal",
80 fakeREST <- FakeRESTService$new(collectionContent)
81 api$setRESTService(fakeREST)
82 collection <- Collection$new(api, "myUUID")
84 newDog <- ArvadosFile$new("dog")
85 collection$add(newDog, "animal")
87 dog <- collection$get("animal/dog")
88 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
90 expect_that(dogExistsInCollection, is_true())
91 expect_that(fakeREST$createCallCount, equals(1))
94 test_that("create raises exception if passed argumet is not character vector", {
96 api <- Arvados$new("myToken", "myHostName")
97 api$setHttpClient(FakeHttpRequest$new())
98 api$setHttpParser(FakeHttpParser$new())
100 collectionContent <- c("animal",
104 fakeREST <- FakeRESTService$new(collectionContent)
105 api$setRESTService(fakeREST)
106 collection <- Collection$new(api, "myUUID")
108 expect_that(collection$create(10),
109 throws_error("Expected character vector, got (numeric).",
113 test_that("create raises exception if relative path is not valid", {
115 api <- Arvados$new("myToken", "myHostName")
116 api$setHttpClient(FakeHttpRequest$new())
117 api$setHttpParser(FakeHttpParser$new())
119 collectionContent <- c("animal",
123 fakeREST <- FakeRESTService$new(collectionContent)
124 api$setRESTService(fakeREST)
125 collection <- Collection$new(api, "myUUID")
127 newPen <- ArvadosFile$new("pen")
129 expect_that(collection$create(newPen, "objects"),
130 throws_error("Subcollection objects doesn't exist.",
134 test_that(paste("create adds files specified by fileNames",
135 "to local tree structure and remote REST service"), {
137 api <- Arvados$new("myToken", "myHostName")
138 api$setHttpClient(FakeHttpRequest$new())
139 api$setHttpParser(FakeHttpParser$new())
141 collectionContent <- c("animal",
145 fakeREST <- FakeRESTService$new(collectionContent)
146 api$setRESTService(fakeREST)
147 collection <- Collection$new(api, "myUUID")
149 files <- c("dog", "cat")
150 collection$create(files, "animal")
152 dog <- collection$get("animal/dog")
153 cat <- collection$get("animal/cat")
154 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
155 catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
157 expect_that(dogExistsInCollection, is_true())
158 expect_that(catExistsInCollection, is_true())
159 expect_that(fakeREST$createCallCount, equals(2))
162 test_that("remove raises exception if passed argumet is not character vector", {
164 api <- Arvados$new("myToken", "myHostName")
165 api$setHttpClient(FakeHttpRequest$new())
166 api$setHttpParser(FakeHttpParser$new())
168 collectionContent <- c("animal",
172 fakeREST <- FakeRESTService$new(collectionContent)
173 api$setRESTService(fakeREST)
174 collection <- Collection$new(api, "myUUID")
176 expect_that(collection$remove(10),
177 throws_error("Expected character vector, got (numeric).",
181 test_that(paste("remove removes files specified by paths",
182 "from local tree structure and from remote REST service"), {
184 api <- Arvados$new("myToken", "myHostName")
185 api$setHttpClient(FakeHttpRequest$new())
186 api$setHttpParser(FakeHttpParser$new())
188 collectionContent <- c("animal",
194 fakeREST <- FakeRESTService$new(collectionContent)
195 api$setRESTService(fakeREST)
196 collection <- Collection$new(api, "myUUID")
198 collection$remove(c("animal/dog", "animal/cat"))
200 dog <- collection$get("animal/dog")
201 cat <- collection$get("animal/dog")
202 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
203 catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
205 expect_that(dogExistsInCollection, is_false())
206 expect_that(catExistsInCollection, is_false())
207 expect_that(fakeREST$deleteCallCount, equals(2))
210 test_that(paste("move moves content to a new location inside file tree",
211 "and on REST service"), {
213 api <- Arvados$new("myToken", "myHostName")
214 api$setHttpClient(FakeHttpRequest$new())
215 api$setHttpParser(FakeHttpParser$new())
217 collectionContent <- c("animal",
221 fakeREST <- FakeRESTService$new(collectionContent)
222 api$setRESTService(fakeREST)
223 collection <- Collection$new(api, "myUUID")
225 collection$move("animal/dog", "dog")
227 dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
228 dogExistsOnNewLocation <- !is.null(collection$get("dog"))
230 expect_that(dogIsNullOnOldLocation, is_true())
231 expect_that(dogExistsOnNewLocation, is_true())
232 expect_that(fakeREST$moveCallCount, equals(1))
235 test_that("move raises exception if new location is not valid", {
237 api <- Arvados$new("myToken", "myHostName")
238 api$setHttpClient(FakeHttpRequest$new())
239 api$setHttpParser(FakeHttpParser$new())
241 collectionContent <- c("animal",
245 fakeREST <- FakeRESTService$new(collectionContent)
246 api$setRESTService(fakeREST)
247 collection <- Collection$new(api, "myUUID")
249 expect_that(collection$move("fish", "object"),
250 throws_error("Element you want to move doesn't exist in the collection.",
254 test_that("getFileListing returns collection content received from REST service", {
256 api <- Arvados$new("myToken", "myHostName")
257 api$setHttpClient(FakeHttpRequest$new())
258 api$setHttpParser(FakeHttpParser$new())
260 collectionContent <- c("animal",
264 fakeREST <- FakeRESTService$new(collectionContent)
265 api$setRESTService(fakeREST)
266 collection <- Collection$new(api, "myUUID")
268 contentMatchExpected <- all(collection$getFileListing() ==
269 c("animal", "animal/fish", "ball"))
271 expect_that(contentMatchExpected, is_true())
272 #2 calls because Collection$new calls getFileListing once
273 expect_that(fakeREST$getCollectionContentCallCount, equals(2))
277 test_that("get returns arvados file or subcollection from internal tree structure", {
279 api <- Arvados$new("myToken", "myHostName")
280 api$setHttpClient(FakeHttpRequest$new())
281 api$setHttpParser(FakeHttpParser$new())
283 collectionContent <- c("animal",
287 fakeREST <- FakeRESTService$new(collectionContent)
288 api$setRESTService(fakeREST)
289 collection <- Collection$new(api, "myUUID")
291 fish <- collection$get("animal/fish")
292 fishIsNotNull <- !is.null(fish)
294 expect_that(fishIsNotNull, is_true())
295 expect_that(fish$getName(), equals("fish"))