library(testthat) library(MGPSDK) # source("/Users/ncarr/Documents/GitHub/marianas-team/SDKs/R/MGP_SDK/interface.R") # setwd(tempdir()) bbox4326 = "39.547255,-106.138978,39.648179,-105.931954" bbox3857 = "4800367.1232,-11815336.9516,4814947.4863,-11792291.1876" bboxDiscover = '-105,40,-104,41' download_loc <- "/Users/ncarr/Downloads" audit_date = '2023-03-12T00:00:00Z/2023-03-15T12:31:12Z' datetime = '2015-01-01T00:00:00Z/2016-01-01T00:00:00Z' stac_id = '1020010079424900' id_list = '0d1e2b78-aeb0-493e-b046-561265c6735b-inv, 385c2a01-d880-4662-9bef-adde996cf810-inv' intersects_r <- list(type = "Polygon",coordinates = list(list(c(-105, 39),c(-103, 39),c(-103, 41),c(-104, 41),c(-104, 40),c(-105, 40),c(-105, 39)))) orderby = 'id' where = 'eo:cloud_cover < 20' collections = 'wv01' sub_catalog_id = 'dg-archive' filter="productName='VIVID_STANDARD_30'" test_that("Interface class initializes correctly", { interface <- MGPSDK::Interface$new() expect_is(interface, "Interface") }) #Streaming API test_that("Interface class can search for features in 4326", { interface <- MGPSDK::Interface$new() result <- interface$streaming_search(bbox = bbox4326) expect_is(result, "list") }) test_that("Interface class can search for features in 3857", { interface <- MGPSDK::Interface$new() result <- interface$streaming_search(bbox = bbox3857, srsname = "EPSG:3857") expect_is(result, "list") }) test_that("Interface class can download a shapefile of search results", { interface <- MGPSDK::Interface$new() result <- interface$streaming_search(bbox = bbox4326, shapefile = TRUE, download_path = file.path(download_loc, "shapeDownload.zip")) expect_true(file.exists(file.path(download_loc, "shapeDownload.zip"))) file.remove(file.path(download_loc, "shapeDownload.zip")) }) test_that("Interface class can download a CSV of search results", { interface <- MGPSDK::Interface$new() result <- interface$streaming_search(bbox = bbox4326, csv = TRUE, download_path = file.path(download_loc,"Download.csv")) expect_true(file.exists(file.path(download_loc,"Download.csv"))) file.remove(file.path(download_loc,"Download.csv")) }) test_that("Interface class can perform a wms request and download a file in EPSG:4326", { interface <- MGPSDK::Interface$new() result <- interface$streaming_download_image(bbox = bbox4326, height = 512, width = 512, outputpath =file.path(download_loc,"download.jpeg"), display = FALSE) expect_true(file.exists(file.path(download_loc,"download.jpeg"))) # Teardown file.remove(file.path(download_loc,"download.jpeg")) }) test_that("Interface class can perform a wms request and download a file in EPSG:3857", { interface <- MGPSDK::Interface$new() result <- interface$streaming_download_image(bbox = bbox3857, srsname="EPSG:3857",height = 512, width = 512, outputpath =file.path(download_loc,"download3857.jpeg"), display=FALSE) expect_true(file.exists(file.path(download_loc,"download3857.jpeg"))) # Teardown file.remove(file.path(download_loc,"download3857.jpeg")) }) #Basemaps API test_that("Interface class can perform a wfs search for basemaps features",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_search(bbox = bbox4326, srsname = "EPSG:4326",filter="productName='VIVID_STANDARD_30'") expect_is(result, "list") }) test_that("Interface class can perform a wfs search for basemaps seamlines features",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_search(bbox = bbox4326, srsname = "EPSG:4326",filter="product_name='VIVID_STANDARD_30'", seamlines=TRUE) expect_is(result, "list") }) test_that("Interface class can perform a 3857 wfs search for basemaps features",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_search(bbox = bbox3857, srsname = "EPSG:3857",filter="productName='VIVID_STANDARD_30'") expect_is(result, "list") }) test_that("Interface class can perform a 3857 wfs search for basemaps features seamlines",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_search(bbox = bbox3857, srsname = "EPSG:3857",filter="product_name='VIVID_STANDARD_30'",seamlines = TRUE) expect_is(result, "list") }) test_that("Interface class can perform a wfs search for basemaps features and download SHP",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_search(bbox = bbox4326, srsname = "EPSG:4326",filter="productName='VIVID_STANDARD_30'", shapefile = TRUE,download_path = file.path(download_loc, "shapeDownload.zip")) expect_true(file.exists(file.path(download_loc, "shapeDownload.zip"))) file.remove(file.path(download_loc, "shapeDownload.zip")) }) test_that("Interface class can perform a wfs search for basemaps features and download SHP seamlines",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_search(bbox = bbox4326, srsname = "EPSG:4326",filter="product_name='VIVID_STANDARD_30'", shapefile = TRUE,seamlines=TRUE,download_path = file.path(download_loc, "shapeDownload.zip")) expect_true(file.exists(file.path(download_loc, "shapeDownload.zip"))) file.remove(file.path(download_loc, "shapeDownload.zip")) }) test_that("Interface class can perform a wfs search for basemaps features and download CSV",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_search(bbox = bbox4326, srsname = "EPSG:4326",filter="productName='VIVID_STANDARD_30'", csv = TRUE,download_path = file.path(download_loc, "Download.csv")) expect_true(file.exists(file.path(download_loc,"Download.csv"))) file.remove(file.path(download_loc,"Download.csv")) }) test_that("Interface class can perform a wfs search for basemaps features and download CSV seamlines",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_search(bbox = bbox4326, srsname = "EPSG:4326",filter="product_name='VIVID_STANDARD_30'", csv = TRUE,seamlines = TRUE,download_path = file.path(download_loc, "Download.csv")) expect_true(file.exists(file.path(download_loc,"Download.csv"))) file.remove(file.path(download_loc,"Download.csv")) }) test_that("Interface class can perform a wfs search for basemaps features and download SHP in 3857",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_search(bbox = bbox3857, srsname = "EPSG:3857",filter="productName='VIVID_STANDARD_30'", shapefile = TRUE,download_path = file.path(download_loc, "shapeDownload.zip")) expect_true(file.exists(file.path(download_loc, "shapeDownload.zip"))) file.remove(file.path(download_loc, "shapeDownload.zip")) }) test_that("Interface class can perform a wfs search for basemaps features and download SHP in 3857 seamlines",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_search(bbox = bbox3857, srsname = "EPSG:3857",filter="product_name='VIVID_STANDARD_30'", shapefile = TRUE,seamlines=TRUE,download_path = file.path(download_loc, "shapeDownloadSeamlines.zip")) expect_true(file.exists(file.path(download_loc, "shapeDownloadSeamlines.zip"))) file.remove(file.path(download_loc, "shapeDownloadSeamlines.zip")) }) test_that("Interface class can perform a wfs search for basemaps features and download SHP in 3857",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_search(bbox = bbox3857, srsname = "EPSG:3857",filter="productName='VIVID_STANDARD_30'", shapefile = TRUE,download_path = file.path(download_loc, "shapeDownload.zip")) expect_true(file.exists(file.path(download_loc, "shapeDownload.zip"))) file.remove(file.path(download_loc, "shapeDownload.zip")) }) test_that("Interface class can perform a wfs search for basemaps features and download CSV in 3857",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_search(bbox = bbox3857, srsname = "EPSG:3857",filter="productName='VIVID_STANDARD_30'", csv = TRUE,download_path = file.path(download_loc, "Download.csv")) expect_true(file.exists(file.path(download_loc,"Download.csv"))) file.remove(file.path(download_loc,"Download.csv")) }) test_that("Interface class can perform a wfs search for basemaps features and download CSV in 3857 seamlines",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_search(bbox = bbox3857, srsname = "EPSG:3857",filter="product_name='VIVID_STANDARD_30'", csv = TRUE,seamlines = TRUE,download_path = file.path(download_loc, "Download.csv")) expect_true(file.exists(file.path(download_loc,"Download.csv"))) file.remove(file.path(download_loc,"Download.csv")) }) test_that("Interface class can perform a WMS request for basemaps and download the image",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_download_image(bbox = bbox4326, srsname = "EPSG:4326",height = 512,width = 512,img_format = "jpeg", outputpath =file.path(download_loc,"download4326basemaps.jpeg")) expect_true(file.exists(file.path(download_loc,"download4326basemaps.jpeg"))) file.remove(file.path(download_loc,"download4326basemaps.jpeg")) }) test_that("Interface class can perform a WMS request for basemaps and download the image seamlines",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_download_image(bbox = bbox4326, srsname = "EPSG:4326",height = 512,width = 512,img_format = "jpeg", seamlines = TRUE,outputpath =file.path(download_loc,"download4326basemaps.jpeg")) expect_true(file.exists(file.path(download_loc,"download4326basemaps.jpeg"))) file.remove(file.path(download_loc,"download4326basemaps.jpeg")) }) test_that("Interface class can perform a WMS request for basemaps and download the image 3857",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_download_image(bbox = bbox3857, srsname = "EPSG:3857",height = 512,width = 512,img_format = "jpeg", outputpath =file.path(download_loc,"download3857basemaps.jpeg")) expect_true(file.exists(file.path(download_loc,"download3857basemaps.jpeg"))) file.remove(file.path(download_loc,"download3857basemaps.jpeg")) }) test_that("Interface class can perform a WMS request for basemaps and download the image 3857 seamlines",{ interface <- MGPSDK::Interface$new() result <- interface$basemaps_download_image(bbox = bbox3857, srsname = "EPSG:3857",height = 512,width = 512,img_format = "jpeg", seamlines = TRUE,outputpath =file.path(download_loc,"download3857basemaps.jpeg")) expect_true(file.exists(file.path(download_loc,"download3857basemaps.jpeg"))) file.remove(file.path(download_loc,"download3857basemaps.jpeg")) }) test_that("Interface class can perform WMTS request for basemaps and download tiles",{ interface <- MGPSDK::Interface$new() dir.create(file.path(download_loc,"Basmaps_tiles")) result <- interface$basemaps_download_tiles(bbox = bbox4326, zoom_level = 13, outputpath = file.path(download_loc,"Basmaps_tiles")) expect_true(any(grepl("MaxarTile", list.files(path = file.path(download_loc,"Basmaps_tiles"))))) #checks the whole directory for files that are MaxarTile unlink(file.path(download_loc,"Basmaps_tiles"), recursive = TRUE) }) test_that("Interface class can perform WMTS request for basemaps and download tiles seamlines",{ interface <- MGPSDK::Interface$new() dir.create(file.path(download_loc,"Basmaps_seamlines_tiles")) result <- interface$basemaps_download_tiles(bbox = bbox4326, zoom_level = 13, seamlines = TRUE,outputpath = file.path(download_loc,"Basmaps_seamlines_tiles")) expect_true(any(grepl("MaxarTile", list.files(path = file.path(download_loc,"Basmaps_seamlines_tiles"))))) #checks the whole directory for files that are MaxarTile unlink(file.path(download_loc,"Basmaps_seamlines_tiles"), recursive = TRUE) }) #Discovery Service test_that("Interface class can perform stac search",{ interface <- MGPSDK::Interface$new() result <- interface$discovery_stac_search(bbox=bboxDiscover, datetime=datetime, collections=collections, where=where, orderby=orderby) expect_is(result, "list") }) test_that("Interface class can perform search with audit fields",{ interface <- MGPSDK::Interface$new() result <- interface$discovery_search_by_audit_fields(collection_id = collections, audit_update_date = audit_date, limit = as.integer(1)) expect_is(result, "character") expect_true(grepl("102", result), info = "Expected '102' to be present in the result") }) test_that("Interface can get root catalog", { interface <- MGPSDK::Interface$new() result <- interface$discovery_get_root_catalog() expect_is(result,"list") }) test_that("Interface can get collection definitions", { interface <- MGPSDK::Interface$new() result <- interface$discovery_get_collection_definition(collection_id = collections) expect_is(result,"list") }) test_that("Interface can get all collections", { interface <- MGPSDK::Interface$new() result <- interface$discovery_get_all_collections() expect_is(result,"list") }) test_that("Interface can View details about a specific STAC item", { interface <- MGPSDK::Interface$new() result <- interface$discovery_get_stac_item(collection_id = collections, item_id = stac_id) expect_is(result,"list") }) test_that("Interface can get top level sub catalog", { interface <- MGPSDK::Interface$new() result <- interface$discovery_get_top_level_sub_catalog(limit = as.integer(2)) expect_is(result,"list") }) test_that("Interface can get sub catalog ", { interface <- MGPSDK::Interface$new() result <- interface$discovery_get_sub_catalog(sub_catalog_id = sub_catalog_id) expect_is(result,"list") })