Integrated autogenerated classes with existing content
authorFuad Muhic <fmuhic@capeannenterprises.com>
Thu, 22 Feb 2018 15:22:49 +0000 (16:22 +0100)
committerFuad Muhic <fmuhic@capeannenterprises.com>
Thu, 22 Feb 2018 15:22:49 +0000 (16:22 +0100)
Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic@capeannenterprises.com>

12 files changed:
sdk/R/NAMESPACE
sdk/R/R/Arvados.R [deleted file]
sdk/R/R/Collection.R
sdk/R/R/RESTService.R
sdk/R/R/autoGenAPI.R
sdk/R/man/Arvados.Rd [deleted file]
sdk/R/man/print.Arvados.Rd [deleted file]
sdk/R/tests/testthat/test-Arvados.R [deleted file]
sdk/R/tests/testthat/test-ArvadosFile.R
sdk/R/tests/testthat/test-Collection.R
sdk/R/tests/testthat/test-RESTService.R
sdk/R/tests/testthat/test-Subcollection.R

index fcee9109ea34708fa1a5241fe84f5acfc18f09fc..e6cf09b53b3222993054181cf2df188095837ca9 100644 (file)
@@ -1,11 +1,57 @@
 # Generated by roxygen2: do not edit by hand
 
-S3method(print,Arvados)
 S3method(print,ArvadosFile)
 S3method(print,Collection)
 S3method(print,Subcollection)
+export(ApiClient)
+export(ApiClientAuthorization)
+export(ApiClientAuthorizationList)
+export(ApiClientList)
 export(Arvados)
 export(ArvadosFile)
+export(AuthorizedKey)
+export(AuthorizedKeyList)
 export(Collection)
+export(CollectionList)
+export(Container)
+export(ContainerList)
+export(ContainerRequest)
+export(ContainerRequestList)
+export(Group)
+export(GroupList)
+export(Human)
+export(HumanList)
+export(Job)
+export(JobList)
+export(JobTask)
+export(JobTaskList)
+export(KeepDisk)
+export(KeepDiskList)
+export(KeepService)
+export(KeepServiceList)
+export(Link)
+export(LinkList)
+export(Log)
+export(LogList)
+export(Node)
+export(NodeList)
+export(PipelineInstance)
+export(PipelineInstanceList)
+export(PipelineTemplate)
+export(PipelineTemplateList)
+export(Repository)
+export(RepositoryList)
+export(Specimen)
+export(SpecimenList)
 export(Subcollection)
+export(Trait)
+export(TraitList)
+export(User)
+export(UserAgreement)
+export(UserAgreementList)
+export(UserList)
+export(VirtualMachine)
+export(VirtualMachineList)
+export(Workflow)
+export(WorkflowList)
 export(generateAPI)
diff --git a/sdk/R/R/Arvados.R b/sdk/R/R/Arvados.R
deleted file mode 100644 (file)
index 8b0e92b..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-source("./R/RESTService.R")
-source("./R/HttpRequest.R")
-source("./R/HttpParser.R")
-
-#' Arvados
-#' 
-#' Arvados class gives users ability to manipulate collections and projects.
-#' 
-#' @section Usage:
-#' \preformatted{arv = Arvados$new(authToken = NULL, hostName = NULL, numRetries = 0)}
-#'
-#' @section Arguments:
-#' \describe{
-#'   \item{authToken}{Authentification token. If not specified ARVADOS_API_TOKEN environment variable will be used.}
-#'   \item{hostName}{Host name. If not specified ARVADOS_API_HOST environment variable will be used.}
-#'   \item{numRetries}{Number which specifies how many times to retry failed service requests.}
-#' }
-#' 
-#' @section Methods:
-#' \describe{
-#'   \item{getToken()}{Returns authentification token currently in use.}
-#'   \item{getHostName()}{Returns host name currently in use.}
-#'   \item{getNumRetries()}{Returns number which specifies how many times to retry failed service requests.}
-#'   \item{setNumRetries(newNumOfRetries)}{Sets number which specifies how many times to retry failed service requests.}
-#'   \item{getCollection(uuid)}{Get collection with specified UUID.}
-#'   \item{listCollections(filters = NULL, limit = 100, offset = 0)}{Returns list of collections based on filters parameter.}
-#'   \item{listAllCollections(filters = NULL)}{Lists all collections, based on filters parameter, even if the number of items is greater than maximum API limit.}
-#'   \item{deleteCollection(uuid)}{Deletes collection with specified UUID.}
-#'   \item{updateCollection(uuid, newContent)}{Updates collection with specified UUID.}
-#'   \item{createCollection(content)}{Creates new collection.}
-#'   \item{getProject(uuid)}{Get project with specified UUID.}
-#'   \item{listProjects(filters = NULL, limit = 100, offset = 0)}{Returns list of projects based on filters parameter.}
-#'   \item{listAllProjects(filters = NULL)}{Lists all projects, based on filters parameter, even if the number of items is greater than maximum API limit.}
-#'   \item{deleteProject(uuid)}{Deletes project with specified UUID.}
-#'   \item{updateProject(uuid, newContent)}{Updates project with specified UUID.}
-#'   \item{createProject(content)}{Creates new project.}
-#' }
-#'
-#' @name Arvados
-#' @examples
-#' \dontrun{
-#' arv <- Arvados$new("your Arvados token", "example.arvadosapi.com")
-#'
-#' collection <- arv$getCollection("uuid")
-#'
-#' collectionList <- arv$listCollections(list(list("name", "like", "Test%")))
-#' collectionList <- arv$listAllCollections(list(list("name", "like", "Test%")))
-#'
-#' deletedCollection <- arv$deleteCollection("uuid")
-#'
-#' updatedCollection <- arv$updateCollection("uuid", list(name = "New name",
-#'                                                        description = "New description"))
-#'
-#' createdCollection <- arv$createCollection(list(name = "Example",
-#'                                                description = "This is a test collection"))
-#' }
-NULL
-
-#' @export
-Arvados <- R6::R6Class(
-
-    "Arvados",
-
-    public = list(
-
-        initialize = function(authToken = NULL, hostName = NULL, numRetries = 0)
-        {
-            if(!is.null(hostName))
-               Sys.setenv(ARVADOS_API_HOST = hostName)
-
-            if(!is.null(authToken))
-                Sys.setenv(ARVADOS_API_TOKEN = authToken)
-
-            hostName  <- Sys.getenv("ARVADOS_API_HOST");
-            token     <- Sys.getenv("ARVADOS_API_TOKEN");
-
-            if(hostName == "" | token == "")
-                stop(paste("Please provide host name and authentification token",
-                           "or set ARVADOS_API_HOST and ARVADOS_API_TOKEN",
-                           "environment variables."))
-
-            private$numRetries  <- numRetries
-            private$REST  <- RESTService$new(token, hostName,
-                                             HttpRequest$new(), HttpParser$new(),
-                                             numRetries)
-
-            private$token <- private$REST$token
-            private$host  <- private$REST$hostName
-        },
-
-        getToken          = function() private$REST$token,
-        getHostName       = function() private$REST$hostName,
-        getWebDavHostName = function() private$REST$getWebDavHostName(),
-        getRESTService    = function() private$REST,
-        setRESTService    = function(newRESTService) private$REST <- newRESTService,
-
-        getNumRetries = function() private$REST$numRetries,
-        setNumRetries = function(newNumOfRetries)
-        {
-            private$REST$setNumRetries(newNumOfRetries)
-        },
-
-        getCollection = function(uuid)
-        {
-            collection <- private$REST$getResource("collections", uuid)
-            collection
-        },
-
-        listCollections = function(filters = NULL, limit = 100, offset = 0)
-        {
-            if(!is.null(filters))
-                names(filters) <- c("collection")
-
-            collections <- private$REST$listResources("collections", filters,
-                                                      limit, offset)
-            collections
-        },
-
-        listAllCollections = function(filters = NULL)
-        {
-            if(!is.null(filters))
-                names(filters) <- c("collection")
-
-            collectionURL <- paste0(private$host, "collections")
-            allCollection <- private$REST$fetchAllItems(collectionURL, filters)
-            allCollection
-        },
-
-        deleteCollection = function(uuid)
-        {
-            removedCollection <- private$REST$deleteResource("collections", uuid)
-            removedCollection
-        },
-
-        updateCollection = function(uuid, newContent)
-        {
-            body <- list(list())
-            names(body) <- c("collection")
-            body$collection <- newContent
-
-            updatedCollection <- private$REST$updateResource("collections",
-                                                             uuid, body)
-            updatedCollection
-        },
-
-        createCollection = function(content)
-        {
-            body <- list(list())
-            names(body) <- c("collection")
-            body$collection <- content
-
-            newCollection <- private$REST$createResource("collections", body)
-            newCollection
-        },
-
-        getProject = function(uuid)
-        {
-            project <- private$REST$getResource("groups", uuid)
-            project
-        },
-
-        createProject = function(content)
-        {
-            body <- list(list())
-            names(body) <- c("group")
-            body$group <- c("group_class" = "project", content)
-
-            newProject <- private$REST$createResource("groups", body)
-            newProject
-        },
-
-        updateProject = function(uuid, newContent)
-        {
-            body <- list(list())
-            names(body) <- c("group")
-            body$group <- newContent
-
-            updatedProject <- private$REST$updateResource("groups", uuid, body)
-            updatedProject
-        },
-
-        listProjects = function(filters = NULL, limit = 100, offset = 0)
-        {
-            if(!is.null(filters))
-                names(filters) <- c("groups")
-
-            filters[[length(filters) + 1]] <- list("group_class", "=", "project")
-
-            projects <- private$REST$listResources("groups", filters, limit, offset)
-            projects
-        },
-
-        listAllProjects = function(filters = NULL)
-        {
-            if(!is.null(filters))
-                names(filters) <- c("groups")
-
-            filters[[length(filters) + 1]] <- list("group_class", "=", "project")
-
-            projectURL <- paste0(private$host, "groups")
-
-            result <- private$REST$fetchAllItems(projectURL, filters)
-            result
-        },
-
-        deleteProject = function(uuid)
-        {
-            removedProject <- private$REST$deleteResource("groups", uuid)
-            removedProject
-        }
-    ),
-
-    private = list(
-
-        token      = NULL,
-        host       = NULL,
-        REST       = NULL,
-        numRetries = NULL
-    ),
-
-    cloneable = FALSE
-)
-
-#' print.Arvados
-#'
-#' Custom print function for Arvados class
-#'
-#' @param x Instance of Arvados class
-#' @param ... Optional arguments.
-#' @export 
-print.Arvados = function(x, ...)
-{
-    cat(paste0("Type:  ", "\"", "Arvados",       "\""), sep = "\n")
-    cat(paste0("Host:  ", "\"", x$getHostName(), "\""), sep = "\n")
-    cat(paste0("Token: ", "\"", x$getToken(),    "\""), sep = "\n")
-}
index ed5b4f4b968d0b9a9b1b570682af587942c29ea2..37b2fb9cc2b302a62215352b695d38b2f2001f81 100644 (file)
@@ -53,22 +53,74 @@ Collection <- R6::R6Class(
 
     public = list(
 
-        api  = NULL,
-        uuid = NULL,
-
-        initialize = function(api, uuid)
+               uuid                     = NULL,
+               etag                     = NULL,
+               owner_uuid               = NULL,
+               created_at               = NULL,
+               modified_by_client_uuid  = NULL,
+               modified_by_user_uuid    = NULL,
+               modified_at              = NULL,
+               portable_data_hash       = NULL,
+               replication_desired      = NULL,
+               replication_confirmed_at = NULL,
+               replication_confirmed    = NULL,
+               updated_at               = NULL,
+               manifest_text            = NULL,
+               name                     = NULL,
+               description              = NULL,
+               properties               = NULL,
+               delete_at                = NULL,
+               file_names               = NULL,
+               trash_at                 = NULL,
+               is_trashed               = NULL,
+
+               initialize = function(uuid = NULL, etag = NULL, owner_uuid = NULL,
+                              created_at = NULL, modified_by_client_uuid = NULL,
+                              modified_by_user_uuid = NULL, modified_at = NULL,
+                              portable_data_hash = NULL, replication_desired = NULL,
+                              replication_confirmed_at = NULL,
+                              replication_confirmed = NULL, updated_at = NULL,
+                              manifest_text = NULL, name = NULL, description = NULL,
+                              properties = NULL, delete_at = NULL, file_names = NULL,
+                              trash_at = NULL, is_trashed = NULL) 
         {
-            self$api <- api
-            private$REST <- api$getRESTService()
-
-            self$uuid <- uuid
-
-            private$fileContent <- private$REST$getCollectionContent(uuid)
-            private$tree <- CollectionTree$new(private$fileContent, self)
+                       self$uuid                     <- uuid
+                       self$etag                     <- etag
+                       self$owner_uuid               <- owner_uuid
+                       self$created_at               <- created_at
+                       self$modified_by_client_uuid  <- modified_by_client_uuid
+                       self$modified_by_user_uuid    <- modified_by_user_uuid
+                       self$modified_at              <- modified_at
+                       self$portable_data_hash       <- portable_data_hash
+                       self$replication_desired      <- replication_desired
+                       self$replication_confirmed_at <- replication_confirmed_at
+                       self$replication_confirmed    <- replication_confirmed
+                       self$updated_at               <- updated_at
+                       self$manifest_text            <- manifest_text
+                       self$name                     <- name
+                       self$description              <- description
+                       self$properties               <- properties
+                       self$delete_at                <- delete_at
+                       self$file_names               <- file_names
+                       self$trash_at                 <- trash_at
+                       self$is_trashed               <- is_trashed
+                       
+                       private$classFields <- c("uuid", "etag", "owner_uuid", 
+                                     "created_at", "modified_by_client_uuid",
+                                     "modified_by_user_uuid", "modified_at",
+                                     "portable_data_hash", "replication_desired",
+                                     "replication_confirmed_at",
+                                     "replication_confirmed", "updated_at",
+                                     "manifest_text", "name", "description", 
+                                     "properties", "delete_at", "file_names",
+                                     "trash_at", "is_trashed")
         },
 
         add = function(content, relativePath = "")
         {
+            if(is.null(private$tree))
+                private$genereateCollectionTreeStructure()
+
             if(relativePath == ""  ||
                relativePath == "." ||
                relativePath == "./")
@@ -87,7 +139,6 @@ Collection <- R6::R6Class(
             if("ArvadosFile"   %in% class(content) ||
                "Subcollection" %in% class(content))
             {
-
                 if(content$getName() == "")
                     stop("Content has invalid name.")
 
@@ -104,6 +155,9 @@ Collection <- R6::R6Class(
 
         create = function(fileNames, relativePath = "")
         {
+            if(is.null(private$tree))
+                private$genereateCollectionTreeStructure()
+
             if(relativePath == ""  ||
                relativePath == "." ||
                relativePath == "./")
@@ -149,6 +203,9 @@ Collection <- R6::R6Class(
 
         remove = function(paths)
         {
+            if(is.null(private$tree))
+                private$genereateCollectionTreeStructure()
+
             if(is.character(paths))
             {
                 sapply(paths, function(filePath)
@@ -179,6 +236,9 @@ Collection <- R6::R6Class(
 
         move = function(content, newLocation)
         {
+            if(is.null(private$tree))
+                private$genereateCollectionTreeStructure()
+
             content <- trimFromEnd(content, "/")
 
             elementToMove <- self$get(content)
@@ -191,12 +251,18 @@ Collection <- R6::R6Class(
 
         getFileListing = function()
         {
+            if(is.null(private$tree))
+                private$genereateCollectionTreeStructure()
+
             content <- private$REST$getCollectionContent(self$uuid)
             content[order(tolower(content))]
         },
 
         get = function(relativePath)
         {
+            if(is.null(private$tree))
+                private$genereateCollectionTreeStructure()
+
             private$tree$getElement(relativePath)
         },
 
@@ -208,7 +274,20 @@ Collection <- R6::R6Class(
 
         REST        = NULL,
         tree        = NULL,
-        fileContent = NULL
+        fileContent = NULL,
+        classFields = NULL,
+
+        genereateCollectionTreeStructure = function()
+        {
+            if(is.null(self$uuid))
+                stop("Collection uuid is not defined.")
+
+            if(is.null(private$REST))
+                stop("REST service is not defined.")
+
+            private$fileContent <- private$REST$getCollectionContent(self$uuid)
+            private$tree <- CollectionTree$new(private$fileContent, self)
+        }
     ),
 
     cloneable = FALSE
index 12e6591ee8f4b3e3cafa6f187bf85886eb6e4914..b87310e9166ed461b13f4a2b467d0526ad0a166f 100644 (file)
@@ -4,27 +4,22 @@ RESTService <- R6::R6Class(
 
     public = list(
 
-        hostName   = NULL,
         token      = NULL,
         http       = NULL,
         httpParser = NULL,
         numRetries = NULL,
 
-        initialize = function(token, hostName,
+        initialize = function(token, rawHost,
                               http, httpParser,
                               numRetries     = 0,
                               webDavHostName = NULL)
         {
-            version <- "v1"
+            self$token      <- token
+            self$http       <- http
+            self$httpParser <- httpParser
+            self$numRetries <- numRetries
 
-            self$token       <- token
-            self$hostName    <- paste0("https://", hostName,
-                                       "/arvados/", version, "/")
-            self$http        <- http
-            self$httpParser  <- httpParser
-            self$numRetries  <- numRetries
-
-            private$rawHostName    <- hostName
+            private$rawHostName    <- rawHost
             private$webDavHostName <- webDavHostName
         },
 
@@ -55,40 +50,7 @@ RESTService <- R6::R6Class(
             private$webDavHostName
         },
 
-        getResource = function(resource, uuid)
-        {
-            resourceURL <- paste0(self$hostName, resource, "/", uuid)
-            headers <- list(Authorization = paste("OAuth2", self$token))
-
-            serverResponse <- self$http$execute("GET", resourceURL, headers,
-                                                retryTimes = self$numRetries)
-
-            resource <- self$httpParser$parseJSONResponse(serverResponse)
-
-            if(!is.null(resource$errors))
-                stop(resource$errors)
-
-            resource
-        },
-
-        listResources = function(resource, filters = NULL, limit = 100, offset = 0)
-        {
-            resourceURL <- paste0(self$hostName, resource)
-            headers <- list(Authorization = paste("OAuth2", self$token))
-            body <- NULL
-
-            serverResponse <- self$http$execute("GET", resourceURL, headers, body,
-                                                filters, limit, offset,
-                                                self$numRetries)
-
-            resources <- self$httpParser$parseJSONResponse(serverResponse)
-
-            if(!is.null(resources$errors))
-                stop(resources$errors)
-
-            resources
-        },
-
+        #Move this to utility 
         fetchAllItems = function(resourceURL, filters)
         {
             headers <- list(Authorization = paste("OAuth2", self$token))
@@ -120,61 +82,6 @@ RESTService <- R6::R6Class(
             items
         },
 
-        deleteResource = function(resource, uuid)
-        {
-            collectionURL <- paste0(self$hostName, resource, "/", uuid)
-            headers <- list("Authorization" = paste("OAuth2", self$token),
-                            "Content-Type"  = "application/json")
-
-            serverResponse <- self$http$execute("DELETE", collectionURL, headers,
-                                                retryTimes = self$numRetries)
-
-            removedResource <- self$httpParser$parseJSONResponse(serverResponse)
-
-            if(!is.null(removedResource$errors))
-                stop(removedResource$errors)
-
-            removedResource
-        },
-
-        updateResource = function(resource, uuid, newContent)
-        {
-            resourceURL <- paste0(self$hostName, resource, "/", uuid)
-            headers <- list("Authorization" = paste("OAuth2", self$token),
-                            "Content-Type"  = "application/json")
-
-            newContent <- jsonlite::toJSON(newContent, auto_unbox = T)
-
-            serverResponse <- self$http$execute("PUT", resourceURL, headers, newContent,
-                                                retryTimes = self$numRetries)
-
-            updatedResource <- self$httpParser$parseJSONResponse(serverResponse)
-
-            if(!is.null(updatedResource$errors))
-                stop(updatedResource$errors)
-
-            updatedResource
-        },
-
-        createResource = function(resource, content)
-        {
-            resourceURL <- paste0(self$hostName, resource)
-            headers <- list("Authorization" = paste("OAuth2", self$token),
-                            "Content-Type"  = "application/json")
-
-            content <- jsonlite::toJSON(content, auto_unbox = T)
-
-            serverResponse <- self$http$execute("POST", resourceURL, headers, content,
-                                                retryTimes = self$numRetries)
-
-            newResource <- self$httpParser$parseJSONResponse(serverResponse)
-
-            if(!is.null(newResource$errors))
-                stop(newResource$errors)
-
-            newResource
-        },
-
         create = function(files, uuid)
         {
             sapply(files, function(filePath)
index c7bf4b3dd3b3f2cc4e3bc28eed2109a36cdffaee..95206a4a0a096010f2d023d565fcd46a93cf5546 100644 (file)
@@ -44,7 +44,7 @@ generateArvadosAPIClass <- function(discoveryDocument)
     arvadosClass <- c(arvadosAPIHeader, arvadosMethods, arvadosAPIFooter)
 
     #TODO: Save to a file or load in memory?
-    fileConn <- file("ArvadosAPI.R", "w")
+    fileConn <- file("./R/Arvados.R", "w")
     writeLines(unlist(arvadosClass), fileConn)
     close(fileConn)
     NULL
@@ -93,7 +93,6 @@ getFunctionBody <- function(functionMetaData, classMetaData)
     url  <- getRequestURL(functionMetaData)
     headers <- getRequestHeaders()
     requestQueryList <- getRequestQueryList(functionMetaData)
-    requestQueryList <- getRequestQueryList(functionMetaData)
     requestBody <- getRequestBody(functionMetaData)
     request <- getRequest(functionMetaData)
     response <- getResponse(functionMetaData)
@@ -116,7 +115,7 @@ getRequestBody <- function(functionMetaData)
 
 getRequestHeaders <- function()
 {
-    paste0("headers <- list(Authorization = paste(\"OAuth2\", private$token),",
+    paste0("headers <- list(Authorization = paste(\"OAuth2\", private$token), ",
                             "\"Content-Type\" = \"application/json\")")
 }
 
@@ -125,6 +124,11 @@ getReturnObject <- function(functionMetaData, classMetaData)
     returnClass <- functionMetaData$response[["$ref"]]
     classArguments <- getReturnClassArguments(returnClass, classMetaData)
 
+    if(returnClass == "Collection")
+        return(c(paste0("collection <- ", returnClass, "$new(", classArguments, ")"),
+                 "collection$setRESTService(private$REST)",
+                 "collection"))
+
     c(paste0(returnClass, "$new(", classArguments, ")"))
 }
 
@@ -143,12 +147,12 @@ getReturnClassArguments <- function(className, classMetaData)
 getRequest <- function(functionMetaData)
 {
     method <- functionMetaData$httpMethod
-    paste0("response <- private$http$exec(\"", method, "\", url, headers, body, queryArgs)")
+    paste0("response <- private$REST$http$exec(\"", method, "\", url, headers, body, queryArgs)")
 }
 
 getResponse <- function(functionMetaData)
 {
-    "resource <- private$httpParser$parseJSONResponse(response)"
+    "resource <- private$REST$httpParser$parseJSONResponse(response)"
 }
 
 getRequestURL <- function(functionMetaData)
@@ -189,9 +193,9 @@ createFunction <- function(functionName, functionMetaData, classMetaData)
 generateAPIClassHeader <- function()
 {
     c("#' @export",
-      "ArvadosAPI <- R6::R6Class(",
+      "Arvados <- R6::R6Class(",
       "",
-      "\t\"ArvadosAPI\",",
+      "\t\"Arvados\",",
       "",
       "\tpublic = list(",
       "",
@@ -203,33 +207,36 @@ generateAPIClassHeader <- function()
       "\t\t\tif(!is.null(authToken))",
       "\t\t\t\tSys.setenv(ARVADOS_API_TOKEN = authToken)",
       "",
-      "\t\t\tprivate$rawHost <- Sys.getenv(\"ARVADOS_API_HOST\")",
-      "\t\t\tprivate$host <- paste0(\"https://\", private$rawHost, \"/arvados/v1/\")",
-      "\t\t\tprivate$token <- Sys.getenv(\"ARVADOS_API_TOKEN\")",
-      "\t\t\tprivate$numRetries  <- numRetries",
-      "\t\t\tprivate$http  <- ArvadosR:::HttpRequest$new()",
-      "\t\t\tprivate$httpParser  <- ArvadosR:::HttpParser$new()",
+      "\t\t\thostName <- Sys.getenv(\"ARVADOS_API_HOST\")",
+      "\t\t\ttoken    <- Sys.getenv(\"ARVADOS_API_TOKEN\")",
       "",
-      "\t\t\tif(private$rawHost == \"\" | private$token == \"\")",
+      "\t\t\tif(hostName == \"\" | token == \"\")",
       "\t\t\t\tstop(paste(\"Please provide host name and authentification token\",",
       "\t\t\t\t\t\t   \"or set ARVADOS_API_HOST and ARVADOS_API_TOKEN\",",
       "\t\t\t\t\t\t   \"environment variables.\"))",
+      "",
+      "\t\t\tprivate$token <- token",
+      "\t\t\tprivate$host  <- paste0(\"https://\", hostName, \"/arvados/v1/\")",
+      "\t\t\tprivate$numRetries <- numRetries",
+      "\t\t\tprivate$REST <- RESTService$new(token, hostName,",
+      "\t\t\t                                HttpRequest$new(), HttpParser$new(),",
+      "\t\t\t                                numRetries)",
+      "",
       "\t\t},\n")
 }
 
 generateAPIClassFooter <- function()
 {
     c("\t\tgetHostName = function() private$host,",
-      "\t\tgetToken = function() private$token",
+      "\t\tgetToken = function() private$token,",
+      "\t\tsetRESTService = function(newREST) private$REST <- newREST",
       "\t),",
       "",
       "\tprivate = list(",
       "",
       "\t\ttoken = NULL,",
-      "\t\trawHost = NULL,",
       "\t\thost = NULL,",
-      "\t\thttp = NULL,",
-      "\t\thttpParser = NULL,",
+      "\t\tREST = NULL,",
       "\t\tnumRetries = NULL",
       "\t),",
       "",
@@ -241,13 +248,15 @@ generateArvadosClasses <- function(resources)
 {
     classes <- sapply(resources$schemas, function(classSchema)
     {
-        getArvadosClass(classSchema)
+        #NOTE: Collection is implemented manually.
+        if(classSchema$id != "Collection")
+            getArvadosClass(classSchema)
 
     }, USE.NAMES = TRUE)
 
     unlist(unname(classes))
 
-    fileConn <- file("ArvadosClasses.R", "w")
+    fileConn <- file("./R/ArvadosClasses.R", "w")
     writeLines(unlist(classes), fileConn)
     close(fileConn)
     NULL
@@ -260,7 +269,8 @@ getArvadosClass <- function(classSchema)
     fieldsList <- paste0("c(", paste0("\"", fields, "\"", collapse = ", "), ")")
     constructorArgs <- paste0(fields, " = NULL", collapse = ", ")
 
-    classString <- c(paste0(name, " <- R6::R6Class("),
+    classString <- c("#' @export",
+              paste0(name, " <- R6::R6Class("),
                      "",
               paste0("\t\"", name, "\","),
                      "",
diff --git a/sdk/R/man/Arvados.Rd b/sdk/R/man/Arvados.Rd
deleted file mode 100644 (file)
index 3c66437..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/Arvados.R
-\name{Arvados}
-\alias{Arvados}
-\title{Arvados}
-\description{
-Arvados class gives users ability to manipulate collections and projects.
-}
-\section{Usage}{
-
-\preformatted{arv = Arvados$new(authToken = NULL, hostName = NULL, numRetries = 0)}
-}
-
-\section{Arguments}{
-
-\describe{
-  \item{authToken}{Authentification token. If not specified ARVADOS_API_TOKEN environment variable will be used.}
-  \item{hostName}{Host name. If not specified ARVADOS_API_HOST environment variable will be used.}
-  \item{numRetries}{Number which specifies how many times to retry failed service requests.}
-}
-}
-
-\section{Methods}{
-
-\describe{
-  \item{getToken()}{Returns authentification token currently in use.}
-  \item{getHostName()}{Returns host name currently in use.}
-  \item{getNumRetries()}{Returns number which specifies how many times to retry failed service requests.}
-  \item{setNumRetries(newNumOfRetries)}{Sets number which specifies how many times to retry failed service requests.}
-  \item{getCollection(uuid)}{Get collection with specified UUID.}
-  \item{listCollections(filters = NULL, limit = 100, offset = 0)}{Returns list of collections based on filters parameter.}
-  \item{listAllCollections(filters = NULL)}{Lists all collections, based on filters parameter, even if the number of items is greater than maximum API limit.}
-  \item{deleteCollection(uuid)}{Deletes collection with specified UUID.}
-  \item{updateCollection(uuid, newContent)}{Updates collection with specified UUID.}
-  \item{createCollection(content)}{Creates new collection.}
-  \item{getProject(uuid)}{Get project with specified UUID.}
-  \item{listProjects(filters = NULL, limit = 100, offset = 0)}{Returns list of projects based on filters parameter.}
-  \item{listAllProjects(filters = NULL)}{Lists all projects, based on filters parameter, even if the number of items is greater than maximum API limit.}
-  \item{deleteProject(uuid)}{Deletes project with specified UUID.}
-  \item{updateProject(uuid, newContent)}{Updates project with specified UUID.}
-  \item{createProject(content)}{Creates new project.}
-}
-}
-
-\examples{
-\dontrun{
-arv <- Arvados$new("your Arvados token", "example.arvadosapi.com")
-
-collection <- arv$getCollection("uuid")
-
-collectionList <- arv$listCollections(list(list("name", "like", "Test\%")))
-collectionList <- arv$listAllCollections(list(list("name", "like", "Test\%")))
-
-deletedCollection <- arv$deleteCollection("uuid")
-
-updatedCollection <- arv$updateCollection("uuid", list(name = "New name",
-                                                       description = "New description"))
-
-createdCollection <- arv$createCollection(list(name = "Example",
-                                               description = "This is a test collection"))
-}
-}
diff --git a/sdk/R/man/print.Arvados.Rd b/sdk/R/man/print.Arvados.Rd
deleted file mode 100644 (file)
index 0833d15..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/Arvados.R
-\name{print.Arvados}
-\alias{print.Arvados}
-\title{print.Arvados}
-\usage{
-\method{print}{Arvados}(x, ...)
-}
-\arguments{
-\item{x}{Instance of Arvados class}
-
-\item{...}{Optional arguments.}
-}
-\description{
-Custom print function for Arvados class
-}
diff --git a/sdk/R/tests/testthat/test-Arvados.R b/sdk/R/tests/testthat/test-Arvados.R
deleted file mode 100644 (file)
index 25cf88f..0000000
+++ /dev/null
@@ -1,306 +0,0 @@
-context("Arvados API")
-
-source("fakes/FakeRESTService.R")
-
-test_that("Constructor will use environment variables if no parameters are passed to it", {
-
-    Sys.setenv(ARVADOS_API_HOST  = "environment_api_host")
-    Sys.setenv(ARVADOS_API_TOKEN = "environment_api_token")
-
-    arv <- Arvados$new()
-
-    Sys.unsetenv("ARVADOS_API_HOST")
-    Sys.unsetenv("ARVADOS_API_TOKEN")
-
-    expect_that("https://environment_api_host/arvados/v1/",
-                equals(arv$getHostName())) 
-
-    expect_that("environment_api_token",
-                equals(arv$getToken())) 
-}) 
-
-test_that("Constructor preferes constructor fields over environment variables", {
-
-    Sys.setenv(ARVADOS_API_HOST  = "environment_api_host")
-    Sys.setenv(ARVADOS_API_TOKEN = "environment_api_token")
-
-    arv <- Arvados$new("constructor_api_token", "constructor_api_host")
-
-    Sys.unsetenv("ARVADOS_API_HOST")
-    Sys.unsetenv("ARVADOS_API_TOKEN")
-
-    expect_that("https://constructor_api_host/arvados/v1/",
-                equals(arv$getHostName())) 
-
-    expect_that("constructor_api_token",
-                equals(arv$getToken())) 
-}) 
-
-test_that("Constructor raises exception if fields and environment variables are not provided", {
-
-    expect_that(Arvados$new(),
-                throws_error(paste0("Please provide host name and authentification token",
-                                    " or set ARVADOS_API_HOST and ARVADOS_API_TOKEN",
-                                    " environment variables.")))
-}) 
-
-test_that("getCollection delegates operation to RESTService class", {
-
-    arv <- Arvados$new("token", "hostName")
-    fakeREST <- FakeRESTService$new()
-    arv$setRESTService(fakeREST)
-    collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
-    arv$getCollection(collectionUUID)
-
-    expect_that(fakeREST$getResourceCallCount, equals(1))
-}) 
-
-test_that("listCollections delegates operation to RESTService class", {
-
-    arv <- Arvados$new("token", "hostName")
-    fakeREST <- FakeRESTService$new()
-    arv$setRESTService(fakeREST)
-
-    arv$listCollections()
-
-    expect_that(fakeREST$listResourcesCallCount, equals(1))
-}) 
-
-test_that("listCollections filter paramerter must be named 'collection'", {
-
-    filters <- list(list("name", "like", "MyCollection"))
-    names(filters) <- c("collection")
-    fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
-    arv <- Arvados$new("token", "hostName")
-    arv$setRESTService(fakeREST)
-
-    arv$listCollections(list(list("name", "like", "MyCollection")))
-
-    expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
-}) 
-
-test_that("listAllCollections delegates operation to RESTService class", {
-
-    arv <- Arvados$new("token", "hostName")
-    fakeREST <- FakeRESTService$new()
-    arv$setRESTService(fakeREST)
-
-    arv$listAllCollections()
-
-    expect_that(fakeREST$fetchAllItemsCallCount, equals(1))
-}) 
-
-test_that("listAllCollections filter paramerter must be named 'collection'", {
-
-    filters <- list(list("name", "like", "MyCollection"))
-    names(filters) <- c("collection")
-    fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
-    arv <- Arvados$new("token", "hostName")
-    arv$setRESTService(fakeREST)
-
-    arv$listAllCollections(list(list("name", "like", "MyCollection")))
-
-    expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
-}) 
-
-test_that("deleteCollection delegates operation to RESTService class", {
-
-    arv <- Arvados$new("token", "hostName")
-    fakeREST <- FakeRESTService$new()
-    arv$setRESTService(fakeREST)
-    collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
-    arv$deleteCollection(collectionUUID)
-
-    expect_that(fakeREST$deleteResourceCallCount, equals(1))
-}) 
-
-test_that("updateCollection delegates operation to RESTService class", {
-
-    arv <- Arvados$new("token", "hostName")
-    fakeREST <- FakeRESTService$new()
-    arv$setRESTService(fakeREST)
-    newCollectionContent <- list(newName = "Brand new shiny name")
-    collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
-    arv$updateCollection(collectionUUID, newCollectionContent)
-
-    expect_that(fakeREST$updateResourceCallCount, equals(1))
-}) 
-
-test_that("updateCollection adds content to request parameter named 'collection'", {
-
-    collectionUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    body <- list(list())
-    names(body) <- c("collection")
-    body$collection <- list(name = "MyCollection", desc = "No description")
-    fakeREST <- FakeRESTService$new(returnContent = body)
-    arv <- Arvados$new("token", "hostName")
-    arv$setRESTService(fakeREST)
-
-    arv$updateCollection(collectionUUID, 
-                         list(name = "MyCollection", desc = "No description"))
-
-    expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
-}) 
-
-test_that("createCollection delegates operation to RESTService class", {
-
-    arv <- Arvados$new("token", "hostName")
-    fakeREST <- FakeRESTService$new()
-    arv$setRESTService(fakeREST)
-    collectionContent <- list(newName = "Brand new shiny name")
-
-    arv$createCollection(collectionContent)
-
-    expect_that(fakeREST$createResourceCallCount, equals(1))
-}) 
-
-test_that("createCollection adds content to request parameter named 'collection'", {
-
-    body <- list(list())
-    names(body) <- c("collection")
-    body$collection <- list(name = "MyCollection", desc = "No description")
-    fakeREST <- FakeRESTService$new(returnContent = body)
-    arv <- Arvados$new("token", "hostName")
-    arv$setRESTService(fakeREST)
-
-    arv$createCollection(list(name = "MyCollection", desc = "No description"))
-
-    expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
-}) 
-
-test_that("getProject delegates operation to RESTService class", {
-
-    arv <- Arvados$new("token", "hostName")
-    fakeREST <- FakeRESTService$new()
-    arv$setRESTService(fakeREST)
-    projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
-    arv$getCollection(projectUUID)
-
-    expect_that(fakeREST$getResourceCallCount, equals(1))
-}) 
-
-test_that("listProjects delegates operation to RESTService class", {
-
-    arv <- Arvados$new("token", "hostName")
-    fakeREST <- FakeRESTService$new()
-    arv$setRESTService(fakeREST)
-
-    arv$listCollections()
-
-    expect_that(fakeREST$listResourcesCallCount, equals(1))
-}) 
-
-test_that("listProjects filter contains additional 'group_class' field by default", {
-
-    filters <- list(list("name", "like", "MyProject"))
-    names(filters) <- c("groups")
-    filters[[length(filters) + 1]] <- list("group_class", "=", "project")
-
-    fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
-    arv <- Arvados$new("token", "hostName")
-    arv$setRESTService(fakeREST)
-
-    arv$listProjects(list(list("name", "like", "MyProject")))
-
-    expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
-}) 
-
-test_that("listAllProjects delegates operation to RESTService class", {
-
-    arv <- Arvados$new("token", "hostName")
-    fakeREST <- FakeRESTService$new()
-    arv$setRESTService(fakeREST)
-
-    arv$listAllProjects()
-
-    expect_that(fakeREST$fetchAllItemsCallCount, equals(1))
-}) 
-
-test_that("listAllProjects filter contains additional 'group_class' field by default", {
-
-    filters <- list(list("name", "like", "MyProject"))
-    names(filters) <- c("groups")
-    filters[[length(filters) + 1]] <- list("group_class", "=", "project")
-
-    fakeREST <- FakeRESTService$new(expectedFilterContent = filters)
-    arv <- Arvados$new("token", "hostName")
-    arv$setRESTService(fakeREST)
-
-    arv$listAllProjects(list(list("name", "like", "MyProject")))
-
-    expect_that(fakeREST$filtersAreConfiguredCorrectly, is_true())
-}) 
-
-test_that("deleteProject delegates operation to RESTService class", {
-
-    arv <- Arvados$new("token", "hostName")
-    fakeREST <- FakeRESTService$new()
-    arv$setRESTService(fakeREST)
-    projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
-    arv$deleteCollection(projectUUID)
-
-    expect_that(fakeREST$deleteResourceCallCount, equals(1))
-}) 
-
-test_that("updateProject delegates operation to RESTService class", {
-
-    arv <- Arvados$new("token", "hostName")
-    fakeREST <- FakeRESTService$new()
-    arv$setRESTService(fakeREST)
-    newProjectContent <- list(newName = "Brand new shiny name")
-    projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-
-    arv$updateCollection(projectUUID, newProjectContent)
-
-    expect_that(fakeREST$updateResourceCallCount, equals(1))
-}) 
-
-test_that("updateProject adds content to request parameter named 'group'", {
-
-    projectUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    body <- list(list())
-    names(body) <- c("group")
-    body$group <- list(name = "MyProject", desc = "No description")
-
-    fakeREST <- FakeRESTService$new(returnContent = body)
-    arv <- Arvados$new("token", "hostName")
-    arv$setRESTService(fakeREST)
-
-    arv$updateProject(projectUUID,
-                      list(name = "MyProject", desc = "No description"))
-
-    expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
-}) 
-
-test_that("createProject delegates operation to RESTService class", {
-
-    arv <- Arvados$new("token", "hostName")
-    fakeREST <- FakeRESTService$new()
-    arv$setRESTService(fakeREST)
-    projectContent <- list(newName = "Brand new shiny name")
-
-    arv$createCollection(projectContent)
-
-    expect_that(fakeREST$createResourceCallCount, equals(1))
-}) 
-
-test_that("createProject request body contains 'goup_class' filed", {
-
-    body <- list(list())
-    names(body) <- c("group")
-    body$group <- c("group_class" = "project",
-                    list(name = "MyProject", desc = "No description"))
-
-    fakeREST <- FakeRESTService$new(returnContent = body)
-    arv <- Arvados$new("token", "hostName")
-    arv$setRESTService(fakeREST)
-
-    arv$createProject(list(name = "MyProject", desc = "No description"))
-
-    expect_that(fakeREST$bodyIsConfiguredCorrectly, is_true())
-}) 
index 90cc1499d674df18f075876c4e2ba0bf028f06e7..67ed0f6240938562ff5cb7894201205926c3c494 100644 (file)
@@ -45,9 +45,8 @@ test_that(paste("getSizeInBytes delegates size calculation",
     returnSize <- 100
     fakeREST <- FakeRESTService$new(collectionContent, returnSize)
 
-    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")
 
     resourceSize <- fish$getSizeInBytes()
@@ -81,9 +80,8 @@ test_that("read raises exception offset or length is negative number", {
     collectionContent <- c("animal", "animal/fish")
     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")
 
     expect_that(fish$read(contentType = "text", offset = -1),
@@ -100,9 +98,8 @@ test_that("read delegates reading operation to REST service class", {
     readContent <- "my file"
     fakeREST <- FakeRESTService$new(collectionContent, readContent)
 
-    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")
     
     fileContent <- fish$read("text")
@@ -118,9 +115,8 @@ test_that(paste("connection delegates connection creation ro RESTService class",
     collectionContent <- c("animal", "animal/fish")
     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")
 
     connection <- fish$connection("r")
@@ -134,9 +130,8 @@ test_that(paste("connection returns textConnection opened",
     collectionContent <- c("animal", "animal/fish")
     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")
 
     connection <- fish$connection("w")
@@ -156,9 +151,8 @@ test_that("flush sends data stored in a connection to a REST server", {
     collectionContent <- c("animal", "animal/fish")
     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")
 
     connection <- fish$connection("w")
@@ -184,9 +178,8 @@ test_that("write delegates writing operation to REST service class", {
     collectionContent <- c("animal", "animal/fish")
     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")
     
     fileContent <- fish$write("new file content")
@@ -215,10 +208,8 @@ test_that(paste("move raises exception if newLocationInCollection",
 
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     dog <- collection$get("animal/dog")
 
     expect_that(dog$move("objects/dog"),
@@ -236,9 +227,8 @@ test_that("move raises exception if new location contains content with the same
 
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     dog <- collection$get("animal/dog")
 
     expect_that(dog$move("dog"),
@@ -257,9 +247,8 @@ test_that("move moves arvados file inside collection tree", {
 
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     dog <- collection$get("animal/dog")
 
     dog$move("dog")
index ec00ca3c66dbcc66d875abee3d810a9ba06b9cd9..56e09f85ce80a095088cb0a7dcf05a1f01761881 100644 (file)
@@ -8,9 +8,8 @@ test_that(paste("constructor creates file tree from text content",
     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,9 +23,8 @@ test_that(paste("add raises exception if passed argumet is not",
     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
 
@@ -40,9 +38,8 @@ test_that("add 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")
 
@@ -56,9 +53,8 @@ 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")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     rootFolder <- Subcollection$new("")
 
@@ -72,9 +68,8 @@ test_that(paste("add adds ArvadosFile or Subcollection",
     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")
@@ -91,9 +86,8 @@ test_that("create raises exception if passed argumet is not character vector", {
     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).", 
@@ -108,9 +102,8 @@ test_that("create raises exception if relative path is not valid", {
 
     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")
 
@@ -125,9 +118,8 @@ test_that(paste("create adds files specified by fileNames",
     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")
@@ -147,9 +139,8 @@ test_that("remove raises exception if passed argumet is not character vector", {
     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).", 
@@ -161,9 +152,8 @@ 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")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
 
     expect_that(collection$remove(""),
                 throws_error("You can't delete root folder.", fixed = TRUE))
@@ -175,9 +165,8 @@ test_that(paste("remove removes files specified by paths",
     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"))
 
@@ -197,9 +186,8 @@ test_that(paste("move moves content to a new location inside file tree",
     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")
 
@@ -216,9 +204,8 @@ test_that("move raises exception if new location 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)
 
     expect_that(collection$move("fish", "object"),
                 throws_error("Content you want to move doesn't exist in the collection.",
@@ -230,9 +217,8 @@ test_that("getFileListing returns sorted collection content received from REST s
     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"))
@@ -248,9 +234,8 @@ test_that("get returns arvados file or subcollection from internal tree structur
     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)
index d4f3c2c1c0b809f48fa983cf55d504e6da42eadf..ef4a114cd15d0d6d8dabf3f5be60c68d21341699 100644 (file)
@@ -31,92 +31,6 @@ test_that("getWebDavHostName returns webDAV host name properly", {
     expect_that("https://myWebDavServer.com", equals(REST$getWebDavHostName())) 
 }) 
 
-test_that("getResource calls REST service properly", {
-
-    serverResponse <- NULL
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    expectedURL    <- paste0("https://host/arvados/v1/collections/", resourceUUID)
-
-    httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
-    REST <- RESTService$new("token", "host", 
-                            httpRequest, FakeHttpParser$new(),
-                            0, "webDavHost")
-
-    REST$getResource("collections", resourceUUID)
-
-    expect_that(httpRequest$URLIsProperlyConfigured, is_true())
-    expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
-    expect_that(httpRequest$numberOfGETRequests, equals(1))
-}) 
-
-test_that("getResource parses server response", {
-
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    httpParser <- FakeHttpParser$new()
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(), httpParser,
-                            0, "webDavHost")
-
-    REST$getResource("collections", resourceUUID)
-
-    expect_that(httpParser$parserCallCount, equals(1))
-}) 
-
-test_that("getResource raises exception if response contains errors field", {
-
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    serverResponse <- list(errors = 404)
-
-    REST <- RESTService$new("token", "host",
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new(),
-                            0, "webDavHost")
-    
-    expect_that(REST$getResource("collections", resourceUUID), throws_error("404", fixed = TRUE))
-}) 
-
-test_that("listResources calls REST service properly", {
-
-    serverResponse <- NULL
-    expectedURL    <- paste0("https://host/arvados/v1/collections")
-    httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
-    REST <- RESTService$new("token", "host", 
-                            httpRequest, FakeHttpParser$new(),
-                            0, "webDavHost")
-
-    REST$listResources("collections")
-
-    expect_that(httpRequest$URLIsProperlyConfigured, is_true())
-    expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
-    expect_that(httpRequest$numberOfGETRequests, equals(1))
-}) 
-
-test_that("listResources parses server response", {
-
-    httpParser <- FakeHttpParser$new()
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(), httpParser,
-                            0, "webDavHost")
-
-    REST$listResources("collections")
-
-    expect_that(httpParser$parserCallCount, equals(1))
-}) 
-
-test_that("listResources raises exception if response contains errors field", {
-
-    serverResponse <- list(errors = 404)
-
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new(),
-                            0, "webDavHost")
-    
-    expect_that(REST$listResources("collections"), throws_error("404", fixed = TRUE))
-}) 
-
 test_that("fetchAllItems always returns all resource items from server", {
 
     expectedURL <- NULL
@@ -145,150 +59,6 @@ test_that("fetchAllItems always returns all resource items from server", {
     expect_that(httpParser$parserCallCount, equals(3))
 }) 
 
-test_that("deleteResource calls REST service properly", {
-
-    serverResponse <- NULL
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    expectedURL    <- paste0("https://host/arvados/v1/collections/", resourceUUID)
-
-    httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
-    REST <- RESTService$new("token", "host", 
-                            httpRequest, FakeHttpParser$new(),
-                            0, "webDavHost")
-
-    REST$deleteResource("collections", resourceUUID)
-
-    expect_that(httpRequest$URLIsProperlyConfigured, is_true())
-    expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
-    expect_that(httpRequest$numberOfDELETERequests, equals(1))
-}) 
-
-test_that("deleteCollection parses server response", {
-
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    httpParser <- FakeHttpParser$new()
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(), httpParser,
-                            0, "webDavHost")
-
-    REST$deleteResource("collections", resourceUUID)
-
-    expect_that(httpParser$parserCallCount, equals(1))
-}) 
-
-test_that("deleteCollection raises exception if response contains errors field", {
-
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    serverResponse <- list(errors = 404)
-
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new(),
-                            0, "webDavHost")
-    
-    expect_that(REST$deleteResource("collections", resourceUUID), throws_error("404", fixed = TRUE))
-}) 
-
-test_that("updateResource calls REST service properly", {
-
-    serverResponse <- NULL
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    expectedURL    <- paste0("https://host/arvados/v1/collections/", resourceUUID)
-    newResourceContent <- list(newName = "Brand new shiny name")
-
-    httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
-    REST <- RESTService$new("token", "host", 
-                            httpRequest, FakeHttpParser$new(),
-                            0, "webDavHost")
-
-    REST$updateResource("collections", resourceUUID, newResourceContent)
-
-    expect_that(httpRequest$URLIsProperlyConfigured, is_true())
-    expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
-    expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
-    expect_that(httpRequest$numberOfPUTRequests, equals(1))
-}) 
-
-test_that("updateResource parses server response", {
-
-    newResourceContent <- list(newName = "Brand new shiny name")
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    httpParser <- FakeHttpParser$new()
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(), httpParser,
-                            0, "webDavHost")
-
-    REST$updateResource("collections", resourceUUID, newResourceContent)
-
-    expect_that(httpParser$parserCallCount, equals(1))
-}) 
-
-test_that("updateResource raises exception if response contains errors field", {
-
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    serverResponse <- list(errors = 404)
-    newResourceContent <- list(newName = "Brand new shiny name")
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new(),
-                            0, "webDavHost")
-    
-    expect_that(REST$updateResource("collections", resourceUUID, newResourceContent),
-                throws_error("404", fixed = TRUE))
-}) 
-
-test_that("createResource calls REST service properly", {
-
-    resourceContent <- list(name = "My favorite collection")
-    serverResponse <- NULL
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    expectedURL <- "https://host/arvados/v1/collections"
-    newResourceContent <- list(newName = "Brand new shiny name")
-
-    httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
-
-    REST <- RESTService$new("token", "host", 
-                            httpRequest, FakeHttpParser$new(),
-                            0, "webDavHost")
-
-    REST$createResource("collections", resourceContent)
-
-    expect_that(httpRequest$URLIsProperlyConfigured, is_true())
-    expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
-    expect_that(httpRequest$JSONEncodedBodyIsProvided, is_true())
-    expect_that(httpRequest$numberOfPOSTRequests, equals(1))
-}) 
-
-test_that("createResource parses server response", {
-
-    resourceContent <- list(newName = "Brand new shiny name")
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    httpParser <- FakeHttpParser$new()
-    REST <- RESTService$new("token", "host",
-                            FakeHttpRequest$new(), httpParser,
-                            0, "webDavHost")
-
-    REST$createResource("collections", resourceContent)
-
-    expect_that(httpParser$parserCallCount, equals(1))
-}) 
-
-test_that("createResource raises exception if response contains errors field", {
-
-    resourceUUID <- "aaaaa-j7d0g-ccccccccccccccc"
-    serverResponse <- list(errors = 404)
-    resourceContent <- list(newName = "Brand new shiny name")
-    REST <- RESTService$new("token", "host", 
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new(),
-                            0, "webDavHost")
-    
-    expect_that(REST$createResource("collections", resourceContent),
-                throws_error("404", fixed = TRUE))
-}) 
-
 test_that("create calls REST service properly", {
 
     uuid <- "aaaaa-j7d0g-ccccccccccccccc"
index 1b141e10514c91e3db63ad0368989141137726ff..eafc74734b76b384b5ff8658223433f1ee664b86 100644 (file)
@@ -117,10 +117,9 @@ test_that(paste("add post content to a REST service",
     collectionContent <- c("animal", "animal/fish")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
 
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     animal <- collection$get("animal")
     dog <- ArvadosFile$new("dog")
 
@@ -168,9 +167,8 @@ test_that(paste("remove removes content from REST service",
     collectionContent <- c("animal", "animal/fish", "animal/dog")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     animal <- collection$get("animal")
 
     animal$remove("fish")
@@ -278,9 +276,8 @@ test_that("move raises exception if new location contains content with the same
                            "fish")
     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")
 
     expect_that(fish$move("fish"),
@@ -298,10 +295,8 @@ test_that(paste("move raises exception if newLocationInCollection",
                            "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")
 
     expect_that(fish$move("objects/dog"),
@@ -317,9 +312,8 @@ test_that("move moves subcollection inside collection tree", {
                            "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")
 
     fish$move("fish")
@@ -345,9 +339,8 @@ test_that(paste("getSizeInBytes delegates size calculation",
     returnSize <- 100
     fakeREST <- FakeRESTService$new(collectionContent, returnSize)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     animal <- collection$get("animal")
 
     resourceSize <- animal$getSizeInBytes()