X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/3d6d097f42128bde90b7bc184057a84e99ea3e0a..1a7c5c627ca9cbbbc13e1c9710bbd6268c59b22a:/sdk/R/tests/testthat/test-RESTService.R diff --git a/sdk/R/tests/testthat/test-RESTService.R b/sdk/R/tests/testthat/test-RESTService.R index d4f3c2c1c0..8885ed3de2 100644 --- a/sdk/R/tests/testthat/test-RESTService.R +++ b/sdk/R/tests/testthat/test-RESTService.R @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 + source("fakes/FakeArvados.R") source("fakes/FakeHttpRequest.R") source("fakes/FakeHttpParser.R") @@ -6,8 +10,8 @@ context("REST service") test_that("getWebDavHostName calls REST service properly", { - expectedURL <- "https://host/discovery/v1/apis/arvados/v1/rest" - serverResponse <- list(keepWebServiceUrl = "https://myWebDavServer.com") + expectedURL <- "https://host/arvados/v1/config" + serverResponse <- list(Services = list(WebDAVDownload = list(ExternalURL = "https://myWebDavServer.com"))) httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse) REST <- RESTService$new("token", "host", @@ -15,279 +19,21 @@ test_that("getWebDavHostName calls REST service properly", { REST$getWebDavHostName() - expect_that(httpRequest$URLIsProperlyConfigured, is_true()) - expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true()) + expect_true(httpRequest$URLIsProperlyConfigured) + expect_false(httpRequest$requestHeaderContainsAuthorizationField) expect_that(httpRequest$numberOfGETRequests, equals(1)) -}) +}) test_that("getWebDavHostName returns webDAV host name properly", { - serverResponse <- list(keepWebServiceUrl = "https://myWebDavServer.com") + serverResponse <- list(Services = list(WebDAVDownload = list(ExternalURL = "https://myWebDavServer.com"))) httpRequest <- FakeHttpRequest$new(expectedURL = NULL, serverResponse) 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", - 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 - serverResponse <- list(items_available = 8, - items = list("collection1", - "collection2", - "collection3", - "collection4", - "collection5", - "collection6", - "collection7", - "collection8")) - - httpParser <- FakeHttpParser$new() - httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse) - httpRequest$serverMaxElementsPerRequest <- 3 - - REST <- RESTService$new("token", "host", - httpRequest, httpParser, - 0, "webDavHost") - - result <- REST$fetchAllItems(NULL, NULL) - - expect_that(length(result), equals(8)) - expect_that(httpRequest$numberOfGETRequests, equals(3)) - 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)) -}) + expect_that("https://myWebDavServer.com", equals(REST$getWebDavHostName())) +}) test_that("create calls REST service properly", { @@ -302,10 +48,10 @@ test_that("create calls REST service properly", { REST$create("file", uuid) - expect_that(fakeHttp$URLIsProperlyConfigured, is_true()) - expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true()) + expect_true(fakeHttp$URLIsProperlyConfigured) + expect_true(fakeHttp$requestHeaderContainsAuthorizationField) expect_that(fakeHttp$numberOfPUTRequests, equals(1)) -}) +}) test_that("create raises exception if server response code is not between 200 and 300", { @@ -314,13 +60,13 @@ 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/", + REST <- RESTService$new("token", "https://host/", fakeHttp, HttpParser$new(), 0, "https://webDavHost/") expect_that(REST$create("file", uuid), throws_error("Server code: 404")) -}) +}) test_that("delete calls REST service properly", { @@ -329,16 +75,16 @@ test_that("delete calls REST service properly", { fakeHttp <- FakeHttpRequest$new(expectedURL) fakeHttpParser <- FakeHttpParser$new() - REST <- RESTService$new("token", "https://host/", + REST <- RESTService$new("token", "https://host/", fakeHttp, fakeHttpParser, 0, "https://webDavHost/") REST$delete("file", uuid) - expect_that(fakeHttp$URLIsProperlyConfigured, is_true()) - expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true()) + expect_true(fakeHttp$URLIsProperlyConfigured) + expect_true(fakeHttp$requestHeaderContainsAuthorizationField) expect_that(fakeHttp$numberOfDELETERequests, equals(1)) -}) +}) test_that("delete raises exception if server response code is not between 200 and 300", { @@ -353,7 +99,7 @@ test_that("delete raises exception if server response code is not between 200 an expect_that(REST$delete("file", uuid), throws_error("Server code: 404")) -}) +}) test_that("move calls REST service properly", { @@ -362,17 +108,17 @@ test_that("move calls REST service properly", { fakeHttp <- FakeHttpRequest$new(expectedURL) fakeHttpParser <- FakeHttpParser$new() - REST <- RESTService$new("token", "https://host/", + REST <- RESTService$new("token", "https://host/", fakeHttp, fakeHttpParser, 0, "https://webDavHost/") REST$move("file", "newDestination/file", uuid) - expect_that(fakeHttp$URLIsProperlyConfigured, is_true()) - expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true()) - expect_that(fakeHttp$requestHeaderContainsDestinationField, is_true()) + expect_true(fakeHttp$URLIsProperlyConfigured) + expect_true(fakeHttp$requestHeaderContainsAuthorizationField) + expect_true(fakeHttp$requestHeaderContainsDestinationField) expect_that(fakeHttp$numberOfMOVERequests, equals(1)) -}) +}) test_that("move raises exception if server response code is not between 200 and 300", { @@ -381,13 +127,47 @@ 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/", + 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")) -}) +}) + +test_that("copy calls REST service properly", { + + uuid <- "aaaaa-j7d0g-ccccccccccccccc" + expectedURL <- "https://webDavHost/c=aaaaa-j7d0g-ccccccccccccccc/file" + fakeHttp <- FakeHttpRequest$new(expectedURL) + fakeHttpParser <- FakeHttpParser$new() + + REST <- RESTService$new("token", "https://host/", + fakeHttp, fakeHttpParser, + 0, "https://webDavHost/") + + REST$copy("file", "newDestination/file", uuid) + + expect_true(fakeHttp$URLIsProperlyConfigured) + expect_true(fakeHttp$requestHeaderContainsAuthorizationField) + expect_true(fakeHttp$requestHeaderContainsDestinationField) + expect_that(fakeHttp$numberOfCOPYRequests, equals(1)) +}) + +test_that("copy raises exception if server response code is not between 200 and 300", { + + uuid <- "aaaaa-j7d0g-ccccccccccccccc" + response <- list() + response$status_code <- 404 + fakeHttp <- FakeHttpRequest$new(serverResponse = response) + + REST <- RESTService$new("token", "https://host/", + fakeHttp, HttpParser$new(), + 0, "https://webDavHost/") + + expect_that(REST$copy("file", "newDestination/file", uuid), + throws_error("Server code: 404")) +}) test_that("getCollectionContent retreives correct content from WebDAV server", { @@ -399,7 +179,7 @@ test_that("getCollectionContent retreives correct content from WebDAV server", { fakeHttp <- FakeHttpRequest$new(expectedURL, returnContent) - REST <- RESTService$new("token", "https://host/", + REST <- RESTService$new("token", "https://host/", fakeHttp, FakeHttpParser$new(), 0, "https://webDavHost/") @@ -407,9 +187,9 @@ test_that("getCollectionContent retreives correct content from WebDAV server", { returnedContentMatchExpected <- all.equal(returnResult, c("animal", "animal/dog", "ball")) - expect_that(returnedContentMatchExpected, is_true()) - expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true()) -}) + expect_true(returnedContentMatchExpected) + expect_true(fakeHttp$requestHeaderContainsAuthorizationField) +}) test_that("getCollectionContent raises exception if server returns empty response", { @@ -417,26 +197,26 @@ test_that("getCollectionContent raises exception if server returns empty respons response <- "" fakeHttp <- FakeHttpRequest$new(serverResponse = response) - REST <- RESTService$new("token", "https://host/", + 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")) -}) +}) test_that("getCollectionContent parses server response", { uuid <- "aaaaa-j7d0g-ccccccccccccccc" fakeHttpParser <- FakeHttpParser$new() - REST <- RESTService$new("token", "https://host/", + REST <- RESTService$new("token", "https://host/", FakeHttpRequest$new(), fakeHttpParser, 0, "https://webDavHost/") REST$getCollectionContent(uuid) expect_that(fakeHttpParser$parserCallCount, equals(1)) -}) +}) test_that("getCollectionContent raises exception if server returns empty response", { @@ -444,13 +224,13 @@ test_that("getCollectionContent raises exception if server returns empty respons response <- "" fakeHttp <- FakeHttpRequest$new(serverResponse = response) - REST <- RESTService$new("token", "https://host/", + 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")) -}) +}) test_that(paste("getCollectionContent raises exception if server", "response code is not between 200 and 300"), { @@ -460,13 +240,13 @@ test_that(paste("getCollectionContent raises exception if server", response$status_code <- 404 fakeHttp <- FakeHttpRequest$new(serverResponse = response) - REST <- RESTService$new("token", "https://host/", + REST <- RESTService$new("token", "https://host/", fakeHttp, HttpParser$new(), 0, "https://webDavHost/") expect_that(REST$getCollectionContent(uuid), throws_error("Server code: 404")) -}) +}) test_that("getResourceSize calls REST service properly", { @@ -486,10 +266,10 @@ test_that("getResourceSize calls REST service properly", { returnedContentMatchExpected <- all.equal(returnResult, c(6, 2, 931, 12003)) - expect_that(fakeHttp$URLIsProperlyConfigured, is_true()) - expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true()) - expect_that(returnedContentMatchExpected, is_true()) -}) + expect_true(fakeHttp$URLIsProperlyConfigured) + expect_true(fakeHttp$requestHeaderContainsAuthorizationField) + expect_true(returnedContentMatchExpected) +}) test_that("getResourceSize raises exception if server returns empty response", { @@ -497,13 +277,13 @@ test_that("getResourceSize raises exception if server returns empty response", { response <- "" fakeHttp <- FakeHttpRequest$new(serverResponse = response) - REST <- RESTService$new("token", "https://host/", + 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")) -}) +}) test_that(paste("getResourceSize raises exception if server", "response code is not between 200 and 300"), { @@ -513,26 +293,26 @@ test_that(paste("getResourceSize raises exception if server", response$status_code <- 404 fakeHttp <- FakeHttpRequest$new(serverResponse = response) - REST <- RESTService$new("token", "https://host/", + REST <- RESTService$new("token", "https://host/", fakeHttp, HttpParser$new(), 0, "https://webDavHost/") expect_that(REST$getResourceSize("file", uuid), throws_error("Server code: 404")) -}) +}) test_that("getResourceSize parses server response", { uuid <- "aaaaa-j7d0g-ccccccccccccccc" fakeHttpParser <- FakeHttpParser$new() - REST <- RESTService$new("token", "https://host/", + REST <- RESTService$new("token", "https://host/", FakeHttpRequest$new(), fakeHttpParser, 0, "https://webDavHost/") REST$getResourceSize("file", uuid) expect_that(fakeHttpParser$parserCallCount, equals(1)) -}) +}) test_that("read calls REST service properly", { @@ -544,17 +324,17 @@ test_that("read calls REST service properly", { fakeHttp <- FakeHttpRequest$new(expectedURL, serverResponse) - REST <- RESTService$new("token", "https://host/", + REST <- RESTService$new("token", "https://host/", fakeHttp, FakeHttpParser$new(), 0, "https://webDavHost/") returnResult <- REST$read("file", uuid, "text", 1024, 512) - expect_that(fakeHttp$URLIsProperlyConfigured, is_true()) - expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true()) - expect_that(fakeHttp$requestHeaderContainsRangeField, is_true()) + expect_true(fakeHttp$URLIsProperlyConfigured) + expect_true(fakeHttp$requestHeaderContainsAuthorizationField) + expect_true(fakeHttp$requestHeaderContainsRangeField) expect_that(returnResult, equals("file content")) -}) +}) test_that("read raises exception if server response code is not between 200 and 300", { @@ -563,63 +343,63 @@ 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/", + REST <- RESTService$new("token", "https://host/", fakeHttp, HttpParser$new(), 0, "https://webDavHost/") expect_that(REST$read("file", uuid), throws_error("Server code: 404")) -}) +}) test_that("read raises exception if contentType is not valid", { uuid <- "aaaaa-j7d0g-ccccccccccccccc" fakeHttp <- FakeHttpRequest$new() - REST <- RESTService$new("token", "https://host/", + 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.")) -}) +}) test_that("read parses server response", { uuid <- "aaaaa-j7d0g-ccccccccccccccc" fakeHttpParser <- FakeHttpParser$new() - REST <- RESTService$new("token", "https://host/", + REST <- RESTService$new("token", "https://host/", FakeHttpRequest$new(), fakeHttpParser, 0, "https://webDavHost/") REST$read("file", uuid, "text", 1024, 512) expect_that(fakeHttpParser$parserCallCount, equals(1)) -}) +}) test_that("write calls REST service properly", { - fileContent <- "new file content" + fileContent <- "new file content" uuid <- "aaaaa-j7d0g-ccccccccccccccc" expectedURL <- "https://webDavHost/c=aaaaa-j7d0g-ccccccccccccccc/file" fakeHttp <- FakeHttpRequest$new(expectedURL) - REST <- RESTService$new("token", "https://host/", + REST <- RESTService$new("token", "https://host/", fakeHttp, FakeHttpParser$new(), 0, "https://webDavHost/") REST$write("file", uuid, fileContent, "text/html") - expect_that(fakeHttp$URLIsProperlyConfigured, is_true()) - expect_that(fakeHttp$requestBodyIsProvided, is_true()) - expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true()) - expect_that(fakeHttp$requestHeaderContainsContentTypeField, is_true()) -}) + expect_true(fakeHttp$URLIsProperlyConfigured) + expect_true(fakeHttp$requestBodyIsProvided) + expect_true(fakeHttp$requestHeaderContainsAuthorizationField) + expect_true(fakeHttp$requestHeaderContainsContentTypeField) +}) test_that("write raises exception if server response code is not between 200 and 300", { uuid <- "aaaaa-j7d0g-ccccccccccccccc" - fileContent <- "new file content" + fileContent <- "new file content" response <- list() response$status_code <- 404 fakeHttp <- FakeHttpRequest$new(serverResponse = response) @@ -630,4 +410,17 @@ test_that("write raises exception if server response code is not between 200 and expect_that(REST$write("file", uuid, fileContent, "text/html"), throws_error("Server code: 404")) -}) +}) + +test_that("getConnection calls REST service properly", { + uuid <- "aaaaa-j7d0g-ccccccccccccccc" + fakeHttp <- FakeHttpRequest$new() + + REST <- RESTService$new("token", "https://host/", + fakeHttp, FakeHttpParser$new(), + 0, "https://webDavHost/") + + REST$getConnection("file", uuid, "r") + + expect_that(fakeHttp$numberOfgetConnectionCalls, equals(1)) +})