Integrated autogenerated classes with existing content
[arvados.git] / sdk / R / tests / testthat / test-RESTService.R
index abc34d95659ba7db707a7df17f0265d3093e64c7..ef4a114cd15d0d6d8dabf3f5be60c68d21341699 100644 (file)
@@ -10,7 +10,7 @@ test_that("getWebDavHostName calls REST service properly", {
     serverResponse <- list(keepWebServiceUrl = "https://myWebDavServer.com")
     httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
 
-    REST <- RESTService$new("token", "host", NULL,
+    REST <- RESTService$new("token", "host",
                             httpRequest, FakeHttpParser$new())
 
     REST$getWebDavHostName()
@@ -25,92 +25,12 @@ test_that("getWebDavHostName returns webDAV host name properly", {
     serverResponse <- list(keepWebServiceUrl = "https://myWebDavServer.com")
     httpRequest <- FakeHttpRequest$new(expectedURL = NULL, serverResponse)
 
-    REST <- RESTService$new("token", "host", NULL,
+    REST <- RESTService$new("token", "host",
                             httpRequest, FakeHttpParser$new())
 
     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", "webDavHost",
-                            httpRequest, FakeHttpParser$new())
-
-    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", "webDavHost",
-                            FakeHttpRequest$new(), httpParser)
-
-    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", "webDavHost",
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new())
-    
-    expect_that(REST$getResource("collections", resourceUUID), throws_error(404))
-}) 
-
-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", "webDavHost",
-                            httpRequest, FakeHttpParser$new())
-
-    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", "webDavHost",
-                            FakeHttpRequest$new(), httpParser)
-
-    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", "webDavHost",
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new())
-    
-    expect_that(REST$listResources("collections"), throws_error(404))
-}) 
-
 test_that("fetchAllItems always returns all resource items from server", {
 
     expectedURL <- NULL
@@ -128,8 +48,9 @@ test_that("fetchAllItems always returns all resource items from server", {
     httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
     httpRequest$serverMaxElementsPerRequest <- 3
 
-    REST <- RESTService$new("token", "host", "webDavHost",
-                            httpRequest, httpParser)
+    REST <- RESTService$new("token", "host", 
+                            httpRequest, httpParser,
+                            0, "webDavHost")
 
     result <- REST$fetchAllItems(NULL, NULL)
 
@@ -138,141 +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", "webDavHost",
-                            httpRequest, FakeHttpParser$new())
-
-    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", "webDavHost",
-                            FakeHttpRequest$new(), httpParser)
-
-    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", "webDavHost",
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new())
-    
-    expect_that(REST$deleteResource("collections", resourceUUID), throws_error(404))
-}) 
-
-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", "webDavHost",
-                            httpRequest, FakeHttpParser$new())
-
-    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", "webDavHost",
-                            FakeHttpRequest$new(), httpParser)
-
-    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", "webDavHost",
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new())
-    
-    expect_that(REST$updateResource("collections", resourceUUID, newResourceContent),
-                throws_error(404))
-}) 
-
-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", "webDavHost",
-                            httpRequest, FakeHttpParser$new())
-
-    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", "webDavHost",
-                            FakeHttpRequest$new(), httpParser)
-
-    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", "webDavHost",
-                            FakeHttpRequest$new(NULL, serverResponse),
-                            FakeHttpParser$new())
-    
-    expect_that(REST$createResource("collections", resourceContent),
-                throws_error(404))
-}) 
-
 test_that("create calls REST service properly", {
 
     uuid <- "aaaaa-j7d0g-ccccccccccccccc"
@@ -280,8 +66,9 @@ test_that("create calls REST service properly", {
     fakeHttp <- FakeHttpRequest$new(expectedURL)
     fakeHttpParser <- FakeHttpParser$new()
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, fakeHttpParser)
+    REST <- RESTService$new("token", "https://host/",
+                            fakeHttp, fakeHttpParser,
+                            0, "https://webDavHost/")
 
     REST$create("file", uuid)
 
@@ -297,8 +84,9 @@ test_that("create raises exception if server response code is not between 200 an
     response$status_code <- 404
     fakeHttp <- FakeHttpRequest$new(serverResponse = response)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, HttpParser$new())
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, HttpParser$new(),
+                            0, "https://webDavHost/")
 
     expect_that(REST$create("file", uuid),
                 throws_error("Server code: 404"))
@@ -311,8 +99,9 @@ test_that("delete calls REST service properly", {
     fakeHttp <- FakeHttpRequest$new(expectedURL)
     fakeHttpParser <- FakeHttpParser$new()
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, fakeHttpParser)
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, fakeHttpParser,
+                            0, "https://webDavHost/")
 
     REST$delete("file", uuid)
 
@@ -328,8 +117,9 @@ test_that("delete raises exception if server response code is not between 200 an
     response$status_code <- 404
     fakeHttp <- FakeHttpRequest$new(serverResponse = response)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, HttpParser$new())
+    REST <- RESTService$new("token", "https://host/",
+                            fakeHttp, HttpParser$new(),
+                            0, "https://webDavHost/")
 
     expect_that(REST$delete("file", uuid),
                 throws_error("Server code: 404"))
@@ -342,8 +132,9 @@ test_that("move calls REST service properly", {
     fakeHttp <- FakeHttpRequest$new(expectedURL)
     fakeHttpParser <- FakeHttpParser$new()
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, fakeHttpParser)
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, fakeHttpParser,
+                            0, "https://webDavHost/")
 
     REST$move("file", "newDestination/file", uuid)
 
@@ -360,8 +151,9 @@ test_that("move raises exception if server response code is not between 200 and
     response$status_code <- 404
     fakeHttp <- FakeHttpRequest$new(serverResponse = response)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, HttpParser$new())
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, HttpParser$new(),
+                            0, "https://webDavHost/")
 
     expect_that(REST$move("file", "newDestination/file", uuid),
                 throws_error("Server code: 404"))
@@ -377,8 +169,9 @@ test_that("getCollectionContent retreives correct content from WebDAV server", {
 
     fakeHttp <- FakeHttpRequest$new(expectedURL, returnContent)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, FakeHttpParser$new())
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, FakeHttpParser$new(),
+                            0, "https://webDavHost/")
 
     returnResult <- REST$getCollectionContent(uuid)
     returnedContentMatchExpected <- all.equal(returnResult,
@@ -394,8 +187,9 @@ test_that("getCollectionContent raises exception if server returns empty respons
     response <- ""
     fakeHttp <- FakeHttpRequest$new(serverResponse = response)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, FakeHttpParser$new())
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, FakeHttpParser$new(),
+                            0, "https://webDavHost/")
 
     expect_that(REST$getCollectionContent(uuid),
                 throws_error("Response is empty, request may be misconfigured"))
@@ -405,8 +199,9 @@ test_that("getCollectionContent parses server response", {
 
     uuid <- "aaaaa-j7d0g-ccccccccccccccc"
     fakeHttpParser <- FakeHttpParser$new()
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            FakeHttpRequest$new(), fakeHttpParser)
+    REST <- RESTService$new("token", "https://host/", 
+                            FakeHttpRequest$new(), fakeHttpParser,
+                            0, "https://webDavHost/")
 
     REST$getCollectionContent(uuid)
 
@@ -419,8 +214,9 @@ test_that("getCollectionContent raises exception if server returns empty respons
     response <- ""
     fakeHttp <- FakeHttpRequest$new(serverResponse = response)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, FakeHttpParser$new())
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, FakeHttpParser$new(),
+                            0, "https://webDavHost/")
 
     expect_that(REST$getCollectionContent(uuid),
                 throws_error("Response is empty, request may be misconfigured"))
@@ -434,8 +230,9 @@ test_that(paste("getCollectionContent raises exception if server",
     response$status_code <- 404
     fakeHttp <- FakeHttpRequest$new(serverResponse = response)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, HttpParser$new())
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, HttpParser$new(),
+                            0, "https://webDavHost/")
 
     expect_that(REST$getCollectionContent(uuid),
                 throws_error("Server code: 404"))
@@ -451,8 +248,9 @@ test_that("getResourceSize calls REST service properly", {
     response$content <- c(6, 2, 931, 12003)
     fakeHttp <- FakeHttpRequest$new(expectedURL, response)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, FakeHttpParser$new())
+    REST <- RESTService$new("token", "https://host/",
+                            fakeHttp, FakeHttpParser$new(),
+                            0, "https://webDavHost/")
 
     returnResult <- REST$getResourceSize("file", uuid)
     returnedContentMatchExpected <- all.equal(returnResult,
@@ -469,8 +267,9 @@ test_that("getResourceSize raises exception if server returns empty response", {
     response <- ""
     fakeHttp <- FakeHttpRequest$new(serverResponse = response)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, FakeHttpParser$new())
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, FakeHttpParser$new(),
+                            0, "https://webDavHost/")
 
     expect_that(REST$getResourceSize("file", uuid),
                 throws_error("Response is empty, request may be misconfigured"))
@@ -484,8 +283,9 @@ test_that(paste("getResourceSize raises exception if server",
     response$status_code <- 404
     fakeHttp <- FakeHttpRequest$new(serverResponse = response)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, HttpParser$new())
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, HttpParser$new(),
+                            0, "https://webDavHost/")
 
     expect_that(REST$getResourceSize("file", uuid),
                 throws_error("Server code: 404"))
@@ -495,8 +295,9 @@ test_that("getResourceSize parses server response", {
 
     uuid <- "aaaaa-j7d0g-ccccccccccccccc"
     fakeHttpParser <- FakeHttpParser$new()
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            FakeHttpRequest$new(), fakeHttpParser)
+    REST <- RESTService$new("token", "https://host/", 
+                            FakeHttpRequest$new(), fakeHttpParser,
+                            0, "https://webDavHost/")
 
     REST$getResourceSize("file", uuid)
 
@@ -513,8 +314,9 @@ test_that("read calls REST service properly", {
 
     fakeHttp <- FakeHttpRequest$new(expectedURL, serverResponse)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, FakeHttpParser$new())
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, FakeHttpParser$new(),
+                            0, "https://webDavHost/")
 
     returnResult <- REST$read("file", uuid, "text", 1024, 512)
 
@@ -531,8 +333,9 @@ test_that("read raises exception if server response code is not between 200 and
     response$status_code <- 404
     fakeHttp <- FakeHttpRequest$new(serverResponse = response)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, HttpParser$new())
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, HttpParser$new(),
+                            0, "https://webDavHost/")
 
     expect_that(REST$read("file", uuid),
                 throws_error("Server code: 404"))
@@ -543,8 +346,9 @@ test_that("read raises exception if contentType is not valid", {
     uuid <- "aaaaa-j7d0g-ccccccccccccccc"
     fakeHttp <- FakeHttpRequest$new()
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, HttpParser$new())
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, HttpParser$new(),
+                            0, "https://webDavHost/")
 
     expect_that(REST$read("file", uuid, "some invalid content type"),
                 throws_error("Invalid contentType. Please use text or raw."))
@@ -554,8 +358,9 @@ test_that("read parses server response", {
 
     uuid <- "aaaaa-j7d0g-ccccccccccccccc"
     fakeHttpParser <- FakeHttpParser$new()
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            FakeHttpRequest$new(), fakeHttpParser)
+    REST <- RESTService$new("token", "https://host/", 
+                            FakeHttpRequest$new(), fakeHttpParser,
+                            0, "https://webDavHost/")
 
     REST$read("file", uuid, "text", 1024, 512)
 
@@ -569,8 +374,9 @@ test_that("write calls REST service properly", {
     expectedURL <- "https://webDavHost/c=aaaaa-j7d0g-ccccccccccccccc/file"
     fakeHttp <- FakeHttpRequest$new(expectedURL)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, FakeHttpParser$new())
+    REST <- RESTService$new("token", "https://host/", 
+                            fakeHttp, FakeHttpParser$new(),
+                            0, "https://webDavHost/")
 
     REST$write("file", uuid, fileContent, "text/html")
 
@@ -588,8 +394,9 @@ test_that("write raises exception if server response code is not between 200 and
     response$status_code <- 404
     fakeHttp <- FakeHttpRequest$new(serverResponse = response)
 
-    REST <- RESTService$new("token", "https://host/", "https://webDavHost/",
-                            fakeHttp, HttpParser$new())
+    REST <- RESTService$new("token", "https://host/",
+                            fakeHttp, HttpParser$new(),
+                            0, "https://webDavHost/")
 
     expect_that(REST$write("file", uuid, fileContent, "text/html"),
                 throws_error("Server code: 404"))