Integrated autogenerated classes with existing content
[arvados.git] / sdk / R / tests / testthat / test-Collection.R
index 63a402dba4e358045c4e0f75de0272d19679ece4..56e09f85ce80a095088cb0a7dcf05a1f01761881 100644 (file)
@@ -5,15 +5,11 @@ context("Collection")
 test_that(paste("constructor creates file tree from text content",
                 "retreived form REST service"), {
 
-
-    collectionContent <- c("animal",
-                           "animal/fish",
-                           "ball")
+    collectionContent <- c("animal", "animal/fish", "ball")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     root <- collection$get("")
 
@@ -24,14 +20,11 @@ test_that(paste("constructor creates file tree from text content",
 test_that(paste("add raises exception if passed argumet is not",
                 "ArvadosFile or Subcollection"), {
 
-    collectionContent <- c("animal",
-                           "animal/fish",
-                           "ball")
+    collectionContent <- c("animal", "animal/fish", "ball")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     newNumber <- 10
 
@@ -42,14 +35,11 @@ test_that(paste("add raises exception if passed argumet is not",
 
 test_that("add raises exception if relative path is not valid", {
 
-    collectionContent <- c("animal",
-                           "animal/fish",
-                           "ball")
+    collectionContent <- c("animal", "animal/fish", "ball")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     newPen <- ArvadosFile$new("pen")
 
@@ -58,17 +48,28 @@ test_that("add raises exception if relative path is not valid", {
                               fixed = TRUE))
 })
 
+test_that("add raises exception if content name is empty string", {
+
+    collectionContent <- c("animal", "animal/fish")
+    fakeREST <- FakeRESTService$new(collectionContent)
+
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
+
+    rootFolder <- Subcollection$new("")
+
+    expect_that(collection$add(rootFolder),
+                throws_error("Content has invalid name.", fixed = TRUE))
+})
+
 test_that(paste("add adds ArvadosFile or Subcollection",
                 "to local tree structure and remote REST service"), {
 
-    collectionContent <- c("animal",
-                           "animal/fish",
-                           "ball")
+    collectionContent <- c("animal", "animal/fish", "ball")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     newDog <- ArvadosFile$new("dog")
     collection$add(newDog, "animal")
@@ -82,14 +83,11 @@ test_that(paste("add adds ArvadosFile or Subcollection",
 
 test_that("create raises exception if passed argumet is not character vector", {
 
-    collectionContent <- c("animal",
-                           "animal/fish",
-                           "ball")
+    collectionContent <- c("animal", "animal/fish", "ball")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     expect_that(collection$create(10),
                 throws_error("Expected character vector, got (numeric).", 
@@ -101,11 +99,11 @@ test_that("create raises exception if relative path is not valid", {
     collectionContent <- c("animal",
                            "animal/fish",
                            "ball")
+
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     newPen <- ArvadosFile$new("pen")
 
@@ -117,14 +115,11 @@ test_that("create raises exception if relative path is not valid", {
 test_that(paste("create adds files specified by fileNames",
                 "to local tree structure and remote REST service"), {
 
-    collectionContent <- c("animal",
-                           "animal/fish",
-                           "ball")
+    collectionContent <- c("animal", "animal/fish", "ball")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     files <- c("dog", "cat")
     collection$create(files, "animal")
@@ -141,33 +136,37 @@ test_that(paste("create adds files specified by fileNames",
 
 test_that("remove raises exception if passed argumet is not character vector", {
 
-    collectionContent <- c("animal",
-                           "animal/fish",
-                           "ball")
+    collectionContent <- c("animal", "animal/fish", "ball")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     expect_that(collection$remove(10),
                 throws_error("Expected character vector, got (numeric).", 
                              fixed = TRUE))
 })
 
+test_that("remove raises exception if user tries to remove root folder", {
+
+    collectionContent <- c("animal", "animal/fish")
+    fakeREST <- FakeRESTService$new(collectionContent)
+
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
+
+    expect_that(collection$remove(""),
+                throws_error("You can't delete root folder.", fixed = TRUE))
+})
+
 test_that(paste("remove removes files specified by paths",
                 "from local tree structure and from remote REST service"), {
 
-    collectionContent <- c("animal",
-                           "animal/fish",
-                           "animal/dog",
-                           "animal/cat",
-                           "ball")
+    collectionContent <- c("animal", "animal/fish", "animal/dog", "animal/cat", "ball")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     collection$remove(c("animal/dog", "animal/cat"))
 
@@ -184,14 +183,11 @@ test_that(paste("remove removes files specified by paths",
 test_that(paste("move moves content to a new location inside file tree",
                 "and on REST service"), {
 
-    collectionContent <- c("animal",
-                           "animal/dog",
-                           "ball")
+    collectionContent <- c("animal", "animal/dog", "ball")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     collection$move("animal/dog", "dog")
 
@@ -205,14 +201,11 @@ test_that(paste("move moves content to a new location inside file tree",
 
 test_that("move raises exception if new location is not valid", {
 
-    collectionContent <- c("animal",
-                           "animal/fish",
-                           "ball")
+    collectionContent <- c("animal", "animal/fish", "ball")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     expect_that(collection$move("fish", "object"),
                 throws_error("Content you want to move doesn't exist in the collection.",
@@ -221,14 +214,11 @@ test_that("move raises exception if new location is not valid", {
 
 test_that("getFileListing returns sorted collection content received from REST service", {
 
-    collectionContent <- c("animal",
-                           "animal/fish",
-                           "ball")
+    collectionContent <- c("animal", "animal/fish", "ball")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     contentMatchExpected <- all(collection$getFileListing() == 
                                 c("animal", "animal/fish", "ball"))
@@ -241,14 +231,11 @@ test_that("getFileListing returns sorted collection content received from REST s
 
 test_that("get returns arvados file or subcollection from internal tree structure", {
 
-    collectionContent <- c("animal",
-                           "animal/fish",
-                           "ball")
+    collectionContent <- c("animal", "animal/fish", "ball")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     fish <- collection$get("animal/fish")
     fishIsNotNull <- !is.null(fish)