1 source("fakes/FakeRESTService.R")
5 test_that(paste("constructor creates file tree from text content",
6 "retreived form REST service"), {
9 collectionContent <- c("animal",
12 fakeREST <- FakeRESTService$new(collectionContent)
14 api <- Arvados$new("myToken", "myHostName")
15 api$setRESTService(fakeREST)
16 collection <- Collection$new(api, "myUUID")
18 root <- collection$get("")
20 expect_that(fakeREST$getCollectionContentCallCount, equals(1))
21 expect_that(root$getName(), equals(""))
24 test_that(paste("add raises exception if passed argumet is not",
25 "ArvadosFile or Subcollection"), {
27 collectionContent <- c("animal",
30 fakeREST <- FakeRESTService$new(collectionContent)
32 api <- Arvados$new("myToken", "myHostName")
33 api$setRESTService(fakeREST)
34 collection <- Collection$new(api, "myUUID")
38 expect_that(collection$add(newNumber),
39 throws_error(paste("Expected AravodsFile or Subcollection",
40 "object, got (numeric)."), fixed = TRUE))
43 test_that("add raises exception if relative path is not valid", {
45 collectionContent <- c("animal",
48 fakeREST <- FakeRESTService$new(collectionContent)
50 api <- Arvados$new("myToken", "myHostName")
51 api$setRESTService(fakeREST)
52 collection <- Collection$new(api, "myUUID")
54 newPen <- ArvadosFile$new("pen")
56 expect_that(collection$add(newPen, "objects"),
57 throws_error("Subcollection objects doesn't exist.",
61 test_that(paste("add adds ArvadosFile or Subcollection",
62 "to local tree structure and remote REST service"), {
64 collectionContent <- c("animal",
67 fakeREST <- FakeRESTService$new(collectionContent)
69 api <- Arvados$new("myToken", "myHostName")
70 api$setRESTService(fakeREST)
71 collection <- Collection$new(api, "myUUID")
73 newDog <- ArvadosFile$new("dog")
74 collection$add(newDog, "animal")
76 dog <- collection$get("animal/dog")
77 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
79 expect_that(dogExistsInCollection, is_true())
80 expect_that(fakeREST$createCallCount, equals(1))
83 test_that("create raises exception if passed argumet is not character vector", {
85 collectionContent <- c("animal",
88 fakeREST <- FakeRESTService$new(collectionContent)
90 api <- Arvados$new("myToken", "myHostName")
91 api$setRESTService(fakeREST)
92 collection <- Collection$new(api, "myUUID")
94 expect_that(collection$create(10),
95 throws_error("Expected character vector, got (numeric).",
99 test_that("create raises exception if relative path is not valid", {
101 collectionContent <- c("animal",
104 fakeREST <- FakeRESTService$new(collectionContent)
106 api <- Arvados$new("myToken", "myHostName")
107 api$setRESTService(fakeREST)
108 collection <- Collection$new(api, "myUUID")
110 newPen <- ArvadosFile$new("pen")
112 expect_that(collection$create(newPen, "objects"),
113 throws_error("Subcollection objects doesn't exist.",
117 test_that(paste("create adds files specified by fileNames",
118 "to local tree structure and remote REST service"), {
120 collectionContent <- c("animal",
123 fakeREST <- FakeRESTService$new(collectionContent)
125 api <- Arvados$new("myToken", "myHostName")
126 api$setRESTService(fakeREST)
127 collection <- Collection$new(api, "myUUID")
129 files <- c("dog", "cat")
130 collection$create(files, "animal")
132 dog <- collection$get("animal/dog")
133 cat <- collection$get("animal/cat")
134 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
135 catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
137 expect_that(dogExistsInCollection, is_true())
138 expect_that(catExistsInCollection, is_true())
139 expect_that(fakeREST$createCallCount, equals(2))
142 test_that("remove raises exception if passed argumet is not character vector", {
144 collectionContent <- c("animal",
147 fakeREST <- FakeRESTService$new(collectionContent)
149 api <- Arvados$new("myToken", "myHostName")
150 api$setRESTService(fakeREST)
151 collection <- Collection$new(api, "myUUID")
153 expect_that(collection$remove(10),
154 throws_error("Expected character vector, got (numeric).",
158 test_that(paste("remove removes files specified by paths",
159 "from local tree structure and from remote REST service"), {
161 collectionContent <- c("animal",
166 fakeREST <- FakeRESTService$new(collectionContent)
168 api <- Arvados$new("myToken", "myHostName")
169 api$setRESTService(fakeREST)
170 collection <- Collection$new(api, "myUUID")
172 collection$remove(c("animal/dog", "animal/cat"))
174 dog <- collection$get("animal/dog")
175 cat <- collection$get("animal/dog")
176 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
177 catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
179 expect_that(dogExistsInCollection, is_false())
180 expect_that(catExistsInCollection, is_false())
181 expect_that(fakeREST$deleteCallCount, equals(2))
184 test_that(paste("move moves content to a new location inside file tree",
185 "and on REST service"), {
187 collectionContent <- c("animal",
190 fakeREST <- FakeRESTService$new(collectionContent)
192 api <- Arvados$new("myToken", "myHostName")
193 api$setRESTService(fakeREST)
194 collection <- Collection$new(api, "myUUID")
196 collection$move("animal/dog", "dog")
198 dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
199 dogExistsOnNewLocation <- !is.null(collection$get("dog"))
201 expect_that(dogIsNullOnOldLocation, is_true())
202 expect_that(dogExistsOnNewLocation, is_true())
203 expect_that(fakeREST$moveCallCount, equals(1))
206 test_that("move raises exception if new location is not valid", {
208 collectionContent <- c("animal",
211 fakeREST <- FakeRESTService$new(collectionContent)
213 api <- Arvados$new("myToken", "myHostName")
214 api$setRESTService(fakeREST)
215 collection <- Collection$new(api, "myUUID")
217 expect_that(collection$move("fish", "object"),
218 throws_error("Element you want to move doesn't exist in the collection.",
222 test_that("getFileListing returns collection content received from REST service", {
224 collectionContent <- c("animal",
227 fakeREST <- FakeRESTService$new(collectionContent)
229 api <- Arvados$new("myToken", "myHostName")
230 api$setRESTService(fakeREST)
231 collection <- Collection$new(api, "myUUID")
233 contentMatchExpected <- all(collection$getFileListing() ==
234 c("animal", "animal/fish", "ball"))
236 expect_that(contentMatchExpected, is_true())
237 #2 calls because Collection$new calls getFileListing once
238 expect_that(fakeREST$getCollectionContentCallCount, equals(2))
242 test_that("get returns arvados file or subcollection from internal tree structure", {
244 collectionContent <- c("animal",
247 fakeREST <- FakeRESTService$new(collectionContent)
249 api <- Arvados$new("myToken", "myHostName")
250 api$setRESTService(fakeREST)
251 collection <- Collection$new(api, "myUUID")
253 fish <- collection$get("animal/fish")
254 fishIsNotNull <- !is.null(fish)
256 expect_that(fishIsNotNull, is_true())
257 expect_that(fish$getName(), equals("fish"))