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 collection <- Collection$new("fakeUUID")
12 collection$setRESTService(fakeREST)
14 root <- collection$get("")
16 expect_that(fakeREST$getCollectionContentCallCount, equals(1))
17 expect_that(root$getName(), equals(""))
20 test_that(paste("add raises exception if passed argumet is not",
21 "ArvadosFile or Subcollection"), {
23 collectionContent <- c("animal", "animal/fish", "ball")
24 fakeREST <- FakeRESTService$new(collectionContent)
26 collection <- Collection$new("fakeUUID")
27 collection$setRESTService(fakeREST)
31 expect_that(collection$add(newNumber),
32 throws_error(paste("Expected AravodsFile or Subcollection",
33 "object, got (numeric)."), fixed = TRUE))
36 test_that("add raises exception if relative path is not valid", {
38 collectionContent <- c("animal", "animal/fish", "ball")
39 fakeREST <- FakeRESTService$new(collectionContent)
41 collection <- Collection$new("fakeUUID")
42 collection$setRESTService(fakeREST)
44 newPen <- ArvadosFile$new("pen")
46 expect_that(collection$add(newPen, "objects"),
47 throws_error("Subcollection objects doesn't exist.",
51 test_that("add raises exception if content name is empty string", {
53 collectionContent <- c("animal", "animal/fish")
54 fakeREST <- FakeRESTService$new(collectionContent)
56 collection <- Collection$new("fakeUUID")
57 collection$setRESTService(fakeREST)
59 rootFolder <- Subcollection$new("")
61 expect_that(collection$add(rootFolder),
62 throws_error("Content has invalid name.", fixed = TRUE))
65 test_that(paste("add adds ArvadosFile or Subcollection",
66 "to local tree structure and remote REST service"), {
68 collectionContent <- c("animal", "animal/fish", "ball")
69 fakeREST <- FakeRESTService$new(collectionContent)
71 collection <- Collection$new("fakeUUID")
72 collection$setRESTService(fakeREST)
74 newDog <- ArvadosFile$new("dog")
75 collection$add(newDog, "animal")
77 dog <- collection$get("animal/dog")
78 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
80 expect_that(dogExistsInCollection, is_true())
81 expect_that(fakeREST$createCallCount, equals(1))
84 test_that("create raises exception if passed argumet is not character vector", {
86 collectionContent <- c("animal", "animal/fish", "ball")
87 fakeREST <- FakeRESTService$new(collectionContent)
89 collection <- Collection$new("fakeUUID")
90 collection$setRESTService(fakeREST)
92 expect_that(collection$create(10),
93 throws_error("Expected character vector, got (numeric).",
97 test_that("create raises exception if relative path is not valid", {
99 collectionContent <- c("animal",
103 fakeREST <- FakeRESTService$new(collectionContent)
105 collection <- Collection$new("fakeUUID")
106 collection$setRESTService(fakeREST)
108 newPen <- ArvadosFile$new("pen")
110 expect_that(collection$create(newPen, "objects"),
111 throws_error("Subcollection objects doesn't exist.",
115 test_that(paste("create adds files specified by fileNames",
116 "to local tree structure and remote REST service"), {
118 collectionContent <- c("animal", "animal/fish", "ball")
119 fakeREST <- FakeRESTService$new(collectionContent)
121 collection <- Collection$new("fakeUUID")
122 collection$setRESTService(fakeREST)
124 files <- c("dog", "cat")
125 collection$create(files, "animal")
127 dog <- collection$get("animal/dog")
128 cat <- collection$get("animal/cat")
129 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
130 catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
132 expect_that(dogExistsInCollection, is_true())
133 expect_that(catExistsInCollection, is_true())
134 expect_that(fakeREST$createCallCount, equals(2))
137 test_that("remove raises exception if passed argumet is not character vector", {
139 collectionContent <- c("animal", "animal/fish", "ball")
140 fakeREST <- FakeRESTService$new(collectionContent)
142 collection <- Collection$new("fakeUUID")
143 collection$setRESTService(fakeREST)
145 expect_that(collection$remove(10),
146 throws_error("Expected character vector, got (numeric).",
150 test_that("remove raises exception if user tries to remove root folder", {
152 collectionContent <- c("animal", "animal/fish")
153 fakeREST <- FakeRESTService$new(collectionContent)
155 collection <- Collection$new("fakeUUID")
156 collection$setRESTService(fakeREST)
158 expect_that(collection$remove(""),
159 throws_error("You can't delete root folder.", fixed = TRUE))
162 test_that(paste("remove removes files specified by paths",
163 "from local tree structure and from remote REST service"), {
165 collectionContent <- c("animal", "animal/fish", "animal/dog", "animal/cat", "ball")
166 fakeREST <- FakeRESTService$new(collectionContent)
168 collection <- Collection$new("fakeUUID")
169 collection$setRESTService(fakeREST)
171 collection$remove(c("animal/dog", "animal/cat"))
173 dog <- collection$get("animal/dog")
174 cat <- collection$get("animal/dog")
175 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
176 catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
178 expect_that(dogExistsInCollection, is_false())
179 expect_that(catExistsInCollection, is_false())
180 expect_that(fakeREST$deleteCallCount, equals(2))
183 test_that(paste("move moves content to a new location inside file tree",
184 "and on REST service"), {
186 collectionContent <- c("animal", "animal/dog", "ball")
187 fakeREST <- FakeRESTService$new(collectionContent)
189 collection <- Collection$new("fakeUUID")
190 collection$setRESTService(fakeREST)
192 collection$move("animal/dog", "dog")
194 dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
195 dogExistsOnNewLocation <- !is.null(collection$get("dog"))
197 expect_that(dogIsNullOnOldLocation, is_true())
198 expect_that(dogExistsOnNewLocation, is_true())
199 expect_that(fakeREST$moveCallCount, equals(1))
202 test_that("move raises exception if new location is not valid", {
204 collectionContent <- c("animal", "animal/fish", "ball")
205 fakeREST <- FakeRESTService$new(collectionContent)
207 collection <- Collection$new("fakeUUID")
208 collection$setRESTService(fakeREST)
210 expect_that(collection$move("fish", "object"),
211 throws_error("Content you want to move doesn't exist in the collection.",
215 test_that("getFileListing returns sorted collection content received from REST service", {
217 collectionContent <- c("animal", "animal/fish", "ball")
218 fakeREST <- FakeRESTService$new(collectionContent)
220 collection <- Collection$new("fakeUUID")
221 collection$setRESTService(fakeREST)
223 contentMatchExpected <- all(collection$getFileListing() ==
224 c("animal", "animal/fish", "ball"))
226 expect_that(contentMatchExpected, is_true())
227 #2 calls because Collection$new calls getFileListing once
228 expect_that(fakeREST$getCollectionContentCallCount, equals(2))
232 test_that("get returns arvados file or subcollection from internal tree structure", {
234 collectionContent <- c("animal", "animal/fish", "ball")
235 fakeREST <- FakeRESTService$new(collectionContent)
237 collection <- Collection$new("fakeUUID")
238 collection$setRESTService(fakeREST)
240 fish <- collection$get("animal/fish")
241 fishIsNotNull <- !is.null(fish)
243 expect_that(fishIsNotNull, is_true())
244 expect_that(fish$getName(), equals("fish"))