From ec5eb1f80add9c8f9f43744728b731db53fc84d2 Mon Sep 17 00:00:00 2001 From: eblondel Date: Thu, 12 Oct 2023 00:00:54 +0200 Subject: [PATCH] fix #370 + integration test --- .../workflows/config_metadata_ncml.json | 23 +++++++++++ inst/extdata/workflows/workflows.csv | 3 +- inst/metadata/entity/entity_handler_ncml.R | 4 +- tests/testthat/test_config_metadata_ncml.R | 41 +++++++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 inst/extdata/workflows/config_metadata_ncml.json create mode 100644 tests/testthat/test_config_metadata_ncml.R diff --git a/inst/extdata/workflows/config_metadata_ncml.json b/inst/extdata/workflows/config_metadata_ncml.json new file mode 100644 index 00000000..0da4eddc --- /dev/null +++ b/inst/extdata/workflows/config_metadata_ncml.json @@ -0,0 +1,23 @@ +{ + "profile": { + "id": "my-workflow", + "name": "My workflow", + "project": "Test geoflow project", + "organization": "My organization", + "logos": [ + "https://via.placeholder.com/300x150.png/09f/fff?text=geoflow" + ], + "mode": "entity" + }, + "metadata": { + "entities": [ + { + "handler": "ncml", + "source": "https://galilee.univ-reunion.fr/thredds/ncml/dataStations/La_Reunion/saintjosephmairie/saintjosephmairie_aggregated.ncml?catalog=https%3A%2F%2Fgalilee.univ-reunion.fr%2Fthredds%2Fcatalog%2FdataStations%2FLa_Reunion%2Fsaintjosephmairie%2Fcatalog.html&dataset=station%2FLa_Reunion%2Fsaintjosephmairie%2Fsaintjosephmairie_aggregated.ncml" + } + ], + "contacts" : [] + }, + "software": [], + "actions": [] +} diff --git a/inst/extdata/workflows/workflows.csv b/inst/extdata/workflows/workflows.csv index 976ba133..634f0518 100644 --- a/inst/extdata/workflows/workflows.csv +++ b/inst/extdata/workflows/workflows.csv @@ -16,4 +16,5 @@ config_metadata_gsheets_sdi_geoserver_geotiff_directory.json,Load metadata entit config_metadata_ocs.json,Load metadata entities/contacts/dictionary from CSV files hosted on a cloud supporting OCS API (eg. nextcloud/owncloud) config_metadata_dataverse.json,Load metadata entities/contacts from Dataverse records config_metadata_zenodo.json,Load metadata entities/contacts from Zenodo deposits/records -config_metadata_zenodo_with_options.json,Load metadata entities/contacts from Zenodo deposits/records (with options declared to fetch from public records and by DOI) \ No newline at end of file +config_metadata_zenodo_with_options.json,Load metadata entities/contacts from Zenodo deposits/records (with options declared to fetch from public records and by DOI) +config_metadata_ncml.json,Load a metadata entity/contacts from a NCML source \ No newline at end of file diff --git a/inst/metadata/entity/entity_handler_ncml.R b/inst/metadata/entity/entity_handler_ncml.R index 6f225cde..56de1e9d 100644 --- a/inst/metadata/entity/entity_handler_ncml.R +++ b/inst/metadata/entity/entity_handler_ncml.R @@ -86,7 +86,7 @@ handle_entities_ncml <- function(handler, source, config, handle = TRUE){ #identifiers - entity$setIdentifier("id", basename(source_name)) + entity$setIdentifier("id", basename(attr$full_name$value)) doi <- attr$identifier_product_doi$value if(!is.null(doi)){ @@ -98,7 +98,7 @@ handle_entities_ncml <- function(handler, source, config, handle = TRUE){ if(!is.null(title)){ entity$setTitle("title", title) }else{ - entity$setTitle("title",basename(source_name)) + entity$setTitle("title",basename(attr$full_name$value)) } #description diff --git a/tests/testthat/test_config_metadata_ncml.R b/tests/testthat/test_config_metadata_ncml.R new file mode 100644 index 00000000..21d548a8 --- /dev/null +++ b/tests/testthat/test_config_metadata_ncml.R @@ -0,0 +1,41 @@ +# test_config_metadata_ncml.R +# Author: Emmanuel Blondel +# +# Description: Integration tests for config_metadata_ncml.json workflow +#======================= +require(geoflow, quietly = TRUE) +require(testthat) + +#init +test_that("init",{ + testthat::skip_on_cran() + cfg_file = system.file("extdata/workflows/config_metadata_ncml.json", package = "geoflow") + CFG <- geoflow::initWorkflow(cfg_file) + expect_is(CFG$metadata$content, "list") + expect_equal(length(CFG$metadata$content), 1L) + expect_equal(names(CFG$metadata$content), "entities") + expect_equal(length(CFG$metadata$content$entities), 1L) + expect_equal(length(CFG$getEntities()), 1L) + expect_equal(length(CFG$actions), 0L) +}) + +#debug +test_that("debug",{ + testthat::skip_on_cran() + cfg_file = system.file("extdata/workflows/config_metadata_ncml.json", package = "geoflow") + DEBUG <- geoflow::debugWorkflow(cfg_file, entityIndex = 1, dir = ".") + expect_equal(names(DEBUG), c("config", "entity")) + expect_is(DEBUG$config, "list") + expect_is(DEBUG$entity, "geoflow_entity") +}) + +#execute +test_that("execute",{ + #testthat::skip_on_cran() + #cfg_file = system.file("extdata/workflows/config_metadata_ncml.json", package = "geoflow") + #execution + #EXEC <- geoflow::executeWorkflow(cfg_file, dir = ".") + #expect_true(dir.exists(EXEC)) + #expect_true(file.exists(file.path(EXEC, "job.json"))) + #expect_true(file.exists(file.path(EXEC, "job-logs.txt"))) +})