Sys.setenv(ARVADOS_API_TOKEN = authToken)
hostName <- Sys.getenv("ARVADOS_API_HOST");
- token <- Sys.getenv("ARVADOS_API_TOKEN");
+ token <- Sys.getenv("ARVADOS_API_TOKEN");
if(hostName == "" | token == "")
- stop(paste0("Please provide host name and authentification token",
- " or set ARVADOS_API_HOST and ARVADOS_API_TOKEN",
- " environment variables."))
+ stop(paste("Please provide host name and authentification token",
+ "or set ARVADOS_API_HOST and ARVADOS_API_TOKEN",
+ "environment variables."))
private$REST <- RESTService$new(token, hostName, NULL,
HttpRequest$new(), HttpParser$new())
names(body) <- c("group")
body$group <- newContent
- updatedProject <- private$REST$updateResource("groups",
- uuid, body)
+ updatedProject <- private$REST$updateResource("groups", uuid, body)
updatedProject
},
filters[[length(filters) + 1]] <- list("group_class", "=", "project")
- projects <- private$REST$listResources("groups", filters,
- limit, offset)
+ projects <- private$REST$listResources("groups", filters, limit, offset)
projects
},
#' @export print.Arvados
print.Arvados = function(arvados)
{
- cat(paste0("Type: ", "\"", "Arvados", "\""), sep = "\n")
+ cat(paste0("Type: ", "\"", "Arvados", "\""), sep = "\n")
cat(paste0("Host: ", "\"", arvados$getHostName(), "\""), sep = "\n")
- cat(paste0("Token: ", "\"", arvados$getToken(), "\"") , sep = "\n")
+ cat(paste0("Token: ", "\"", arvados$getToken(), "\""), sep = "\n")
}
initialize = function(name)
{
- private$name <- name
- private$http <- HttpRequest$new()
- private$httpParser <- HttpParser$new()
+ if(name == "")
+ stop("Invalid name.")
+
+ private$name <- name
},
getName = function() private$name,
if(is.null(private$collection))
stop("ArvadosFile doesn't belong to any collection")
-
newLocation <- trimFromEnd(newLocation, "/")
nameAndPath <- splitToPathAndName(newLocation)
size = NULL,
parent = NULL,
collection = NULL,
- http = NULL,
- httpParser = NULL,
buffer = NULL,
attachToNewParent = function(newParent)
relativePath <- paste0("/", relativePath)
}
- cat(paste0("Type: ", "\"", "ArvadosFile", "\""), sep = "\n")
+ cat(paste0("Type: ", "\"", "ArvadosFile", "\""), sep = "\n")
cat(paste0("Name: ", "\"", arvadosFile$getName(), "\""), sep = "\n")
- cat(paste0("Relative path: ", "\"", relativePath, "\"") , sep = "\n")
- cat(paste0("Collection: ", "\"", collection, "\""), sep = "\n")
+ cat(paste0("Relative path: ", "\"", relativePath, "\""), sep = "\n")
+ cat(paste0("Collection: ", "\"", collection, "\""), sep = "\n")
}
if("ArvadosFile" %in% class(content) ||
"Subcollection" %in% class(content))
{
+
+ if(content$getName() == "")
+ stop("Content has invalid name.")
+
subcollection$add(content)
content
}
stop(paste("File", filePath, "doesn't exist."))
parent <- file$getParent()
+
+ if(is.null(parent))
+ stop("You can't delete root folder.")
+
parent$remove(file$getName())
})
+
+ "Content removed"
}
else
{
print.Collection = function(collection)
{
cat(paste0("Type: ", "\"", "Arvados Collection", "\""), sep = "\n")
- cat(paste0("uuid: ", "\"", collection$uuid, "\""), sep = "\n")
+ cat(paste0("uuid: ", "\"", collection$uuid, "\""), sep = "\n")
}
if(serverResponse$status_code < 200 || serverResponse$status_code >= 300)
stop(paste("Server code:", serverResponse$status_code))
- paste("File deleted:", relativePath)
+ serverResponse
},
move = function(from, to, uuid)
if("ArvadosFile" %in% class(content) ||
"Subcollection" %in% class(content))
{
+ if(content$getName() == "")
+ stop("Content has invalid name.")
+
childWithSameName <- self$get(content$getName())
+
if(!is.null(childWithSameName))
stop(paste("Subcollection already contains ArvadosFile",
"or Subcollection with same name."))
{
REST <- private$collection$getRESTService()
REST$delete(child$getRelativePath(), private$collection$uuid)
+
child$setCollection(NULL)
}
getFileListing = function(fullPath = TRUE)
{
content <- private$getContentAsCharVector(fullPath)
-
content[order(tolower(content))]
},
}
content
-
}
),
cat(paste0("Type: ", "\"", "Arvados Subcollection", "\""), sep = "\n")
cat(paste0("Name: ", "\"", subCollection$getName(), "\""), sep = "\n")
- cat(paste0("Relative path: ", "\"", relativePath, "\"") , sep = "\n")
- cat(paste0("Collection: ", "\"", collection, "\""), sep = "\n")
+ cat(paste0("Relative path: ", "\"", relativePath, "\""), sep = "\n")
+ cat(paste0("Collection: ", "\"", collection, "\""), sep = "\n")
}
context("ArvadosFile")
+test_that("constructor raises error if file name is empty string", {
+
+ expect_that(ArvadosFile$new(""), throws_error("Invalid name."))
+})
+
test_that("getFileListing always returns file name", {
dog <- ArvadosFile$new("dog")
"animal/dog",
"animal/fish/shark",
"ball")
+
fakeREST <- FakeRESTService$new(collectionContent)
api <- Arvados$new("myToken", "myHostName")
"animal/dog",
"animal/fish/shark",
"dog")
+
fakeREST <- FakeRESTService$new(collectionContent)
api <- Arvados$new("myToken", "myHostName")
"animal/dog",
"animal/fish/shark",
"ball")
+
fakeREST <- FakeRESTService$new(collectionContent)
api <- Arvados$new("myToken", "myHostName")
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")
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")
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")
fixed = TRUE))
})
+test_that("add raises exception if content name is empty string", {
+
+ collectionContent <- c("animal", "animal/fish")
+ fakeREST <- FakeRESTService$new(collectionContent)
+
+ api <- Arvados$new("myToken", "myHostName")
+ api$setRESTService(fakeREST)
+ collection <- Collection$new(api, "myUUID")
+
+ 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")
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")
collectionContent <- c("animal",
"animal/fish",
"ball")
+
fakeREST <- FakeRESTService$new(collectionContent)
api <- Arvados$new("myToken", "myHostName")
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")
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")
fixed = TRUE))
})
+test_that("remove raises exception if user tries to remove root folder", {
+
+ collectionContent <- c("animal", "animal/fish")
+ fakeREST <- FakeRESTService$new(collectionContent)
+
+ api <- Arvados$new("myToken", "myHostName")
+ api$setRESTService(fakeREST)
+ collection <- Collection$new(api, "myUUID")
+
+ 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")
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")
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")
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")
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")
expect_that(animalContainsDog, is_true())
})
+test_that("add raises exception if content name is empty string", {
+
+ animal <- Subcollection$new("animal")
+ rootFolder <- Subcollection$new("")
+
+ expect_that(animal$add(rootFolder),
+ throws_error("Content has invalid name.", fixed = TRUE))
+})
+
test_that(paste("add raises exception if ArvadosFile/Subcollection",
"with same name already exists in the subcollection"), {