- REST <- RESTService$new("token", "host", NULL,
- 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
- 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", "webDavHost",
- httpRequest, httpParser)
-
- 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", "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",