From 3ed36487390df860bd5d6d0b0df9cebe53ce6024 Mon Sep 17 00:00:00 2001 From: Fabio Sinibaldi Date: Thu, 8 Apr 2021 16:15:25 +0200 Subject: [PATCH] Metadata testing --- .../toPublishMeta/blue-cloud-demonstrator.xml | 220 ++++++++++++++++++ .../resources/toPublishMeta/copernicus.xml | 188 +++++++++++++++ .../spatial/data/sdi/test/MetadataTests.java | 103 ++++++++ .../resources/xml/blue-cloud-demonstrator.xml | 220 ++++++++++++++++++ .../src/test/resources/xml/copernicus.xml | 188 +++++++++++++++ 5 files changed, 919 insertions(+) create mode 100644 sdi-library/src/test/resources/toPublishMeta/blue-cloud-demonstrator.xml create mode 100644 sdi-library/src/test/resources/toPublishMeta/copernicus.xml create mode 100644 sdi-service/src/test/java/org/gcube/spatial/data/sdi/test/MetadataTests.java create mode 100644 sdi-service/src/test/resources/xml/blue-cloud-demonstrator.xml create mode 100644 sdi-service/src/test/resources/xml/copernicus.xml diff --git a/sdi-library/src/test/resources/toPublishMeta/blue-cloud-demonstrator.xml b/sdi-library/src/test/resources/toPublishMeta/blue-cloud-demonstrator.xml new file mode 100644 index 0000000..0b9fb4b --- /dev/null +++ b/sdi-library/src/test/resources/toPublishMeta/blue-cloud-demonstrator.xml @@ -0,0 +1,220 @@ + + + + Dataset + + + Geographic Information — Metadata Part 1: + Fundamentals + + + ISO 19115-1:2014 + + + + + 4 + + + + + Vertical + + + 63 + + + + + + + Column + + + 97 + + + + + + + Row + + + 129 + + + + + + + Time + + + 1 + + + + + Area + + + false + + + + + + + + + time depth lat lon + + + + + + + + + + + Kinetic Energy annual climatology map + + + + + + out_data_(SEASTATV1_ID_62daba28-d3b9-4833-a507-b2dac9838e5c) + + + + + + + + Centro Euro-Mediterraneo sui Cambiamenti + Climatici - CMCC, Italy + + + Originator + + + + + Please check - + https://www.blue-cloud.org/demonstrators/marine-environmental-indicators + + + + + + + + Centro Euro-Mediterraneo sui Cambiamenti + Climatici - CMCC, Italy + + + Point of contact + + + + + Grid + + + + + NetCDF-4 + + + Hierarchical Data Format, version 5 + + + + + + Please check - + https://www.blue-cloud.org/demonstrators/marine-environmental-indicators + + + + + + + + + + + + depth_bnds + + + + + double[2][63] + + + + + + + + + + + + + + + + + ke + + + + + float[97][129][63][1] + + + + + + + + Annual Climatology Map of Kinetic Energy + + + m²∕s² + + + + + \ No newline at end of file diff --git a/sdi-library/src/test/resources/toPublishMeta/copernicus.xml b/sdi-library/src/test/resources/toPublishMeta/copernicus.xml new file mode 100644 index 0000000..222bab6 --- /dev/null +++ b/sdi-library/src/test/resources/toPublishMeta/copernicus.xml @@ -0,0 +1,188 @@ + + + + Dataset + + + Geographic Information — Metadata Part 1: + Fundamentals + + + ISO 19115-1:2014 + + + + + 2 + + + + + Column + + + 120960 + + + + + + + Row + + + 47040 + + + + + Area + + + false + + + + + + + + + WGS 84 + + + + + + + + + + + 10-daily Leaf Area Index 333M: GLOBE + 2014-01-10T00:00:00Z + + + V1.0.1 + + + + + c_gls_LAI300_201401100000_GLOBE_PROBAV_V1.0.1 + + + + + + + + VITO NV + + + Originator + + + + + http://land.copernicus.eu/global/products/lai + + + + + + + + VITO NV + + + Point of contact + + + + + Grid + + + + + NetCDF-4 + + + Hierarchical Data Format, version 5 + + + + + + + + + + + + + + LAI + + + + + ubyte[120960][47040] + + + + + + + + Leaf Area Index 333m + + + 0.033333 + + + 0.0 + + + + + + + + + + + + + Proba-V + + + + + + + + \ No newline at end of file diff --git a/sdi-service/src/test/java/org/gcube/spatial/data/sdi/test/MetadataTests.java b/sdi-service/src/test/java/org/gcube/spatial/data/sdi/test/MetadataTests.java new file mode 100644 index 0000000..fe0f682 --- /dev/null +++ b/sdi-service/src/test/java/org/gcube/spatial/data/sdi/test/MetadataTests.java @@ -0,0 +1,103 @@ +package org.gcube.spatial.data.sdi.test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + +import java.io.File; +import java.io.FilenameFilter; +import java.nio.file.Paths; +import java.util.Set; + +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.gcube.spatial.data.sdi.model.ServiceConstants; +import org.gcube.spatial.data.sdi.model.metadata.MetadataReport; +import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocation; +import org.gcube.spatial.data.sdi.model.metadata.TemplateInvocationBuilder; +import org.glassfish.jersey.media.multipart.FormDataMultiPart; +import org.glassfish.jersey.media.multipart.file.FileDataBodyPart; +import org.junit.Test; + +public class MetadataTests extends ServiceTest { + + + + @Test + public void testUpload() { + assumeTrue(isTestInfrastructureEnabled()); + } + + @Test + public void testMetadataTemplates() throws Exception { + assumeTrue(isTestInfrastructureEnabled()); + + File metadata=Paths.get("src/test/resources/xml").toFile(); + + + for(File f:metadata.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.endsWith(".xml"); + } + })) { + + publishMetadataFile(f, + new TemplateInvocationBuilder(). + threddsOnlineResources("my_hostname", "some_dataset.nc", "myPersonalCatalog").get()); + } + } + + private void publishMetadataFile(File toPublish, Set templates) throws Exception { + try { + String id= pushMetadata(toPublish, target(ServiceConstants.Metadata.INTERFACE)); + + MetadataReport applicationReport= applytemplate(id, target(ServiceConstants.Metadata.INTERFACE), templates); + System.out.println(applicationReport); + assertTrue(applicationReport.getAppliedTemplates().size()==templates.size()); + + MetadataReport publishReport= publish(id, target(ServiceConstants.Metadata.INTERFACE), + true, true, ServiceConstants.Metadata.DEFAULT_CATEGORY, ServiceConstants.Metadata.DEFAULT_STYLESHEET); + System.out.println(publishReport); + assertTrue(publishReport.getPublishedUUID()!=null); + }catch(Exception e) { + throw new Exception("Failed test on xml file "+toPublish.getName()); + } + } + + + + private static String pushMetadata(File toPublish,WebTarget endpoint) throws Exception { + FormDataMultiPart multi=new FormDataMultiPart(); +// multi.field("file",toPublish,MediaType.APPLICATION_OCTET_STREAM_TYPE); + FileDataBodyPart fileDataBodyPart = new FileDataBodyPart(ServiceConstants.Metadata.UPLOADED_FILE_PARAMETER, + toPublish,MediaType.APPLICATION_OCTET_STREAM_TYPE); + multi.bodyPart(fileDataBodyPart); + Response resp= endpoint.request().post(Entity.entity(multi, multi.getMediaType())); + checkResponse(resp); + return resp.readEntity(String.class); + } + + + private static MetadataReport applytemplate(String uploadedID, WebTarget endpoint,Set templates) throws Exception { + + + Response resp= endpoint.path(uploadedID). + request(MediaType.APPLICATION_JSON).put(Entity.entity(templates,MediaType.APPLICATION_JSON)); + checkResponse(resp); + return resp.readEntity(MetadataReport.class); + } + + private static MetadataReport publish(String uploadedID,WebTarget endpoint,boolean validate, + boolean setPublic, String category, String stylesheet) throws Exception { + Response resp= endpoint.path(ServiceConstants.Metadata.PUBLISH_METHOD).path(uploadedID).path(category). + queryParam(ServiceConstants.Metadata.VALIDATE_PARAMETER, validate). + queryParam(ServiceConstants.Metadata.PUBLIC_PARAMETER, setPublic). + queryParam(ServiceConstants.Metadata.STYLESHEET_PARAMETER, stylesheet). + request(MediaType.APPLICATION_JSON).get(); + checkResponse(resp); + return resp.readEntity(MetadataReport.class); + } +} diff --git a/sdi-service/src/test/resources/xml/blue-cloud-demonstrator.xml b/sdi-service/src/test/resources/xml/blue-cloud-demonstrator.xml new file mode 100644 index 0000000..0b9fb4b --- /dev/null +++ b/sdi-service/src/test/resources/xml/blue-cloud-demonstrator.xml @@ -0,0 +1,220 @@ + + + + Dataset + + + Geographic Information — Metadata Part 1: + Fundamentals + + + ISO 19115-1:2014 + + + + + 4 + + + + + Vertical + + + 63 + + + + + + + Column + + + 97 + + + + + + + Row + + + 129 + + + + + + + Time + + + 1 + + + + + Area + + + false + + + + + + + + + time depth lat lon + + + + + + + + + + + Kinetic Energy annual climatology map + + + + + + out_data_(SEASTATV1_ID_62daba28-d3b9-4833-a507-b2dac9838e5c) + + + + + + + + Centro Euro-Mediterraneo sui Cambiamenti + Climatici - CMCC, Italy + + + Originator + + + + + Please check - + https://www.blue-cloud.org/demonstrators/marine-environmental-indicators + + + + + + + + Centro Euro-Mediterraneo sui Cambiamenti + Climatici - CMCC, Italy + + + Point of contact + + + + + Grid + + + + + NetCDF-4 + + + Hierarchical Data Format, version 5 + + + + + + Please check - + https://www.blue-cloud.org/demonstrators/marine-environmental-indicators + + + + + + + + + + + + depth_bnds + + + + + double[2][63] + + + + + + + + + + + + + + + + + ke + + + + + float[97][129][63][1] + + + + + + + + Annual Climatology Map of Kinetic Energy + + + m²∕s² + + + + + \ No newline at end of file diff --git a/sdi-service/src/test/resources/xml/copernicus.xml b/sdi-service/src/test/resources/xml/copernicus.xml new file mode 100644 index 0000000..222bab6 --- /dev/null +++ b/sdi-service/src/test/resources/xml/copernicus.xml @@ -0,0 +1,188 @@ + + + + Dataset + + + Geographic Information — Metadata Part 1: + Fundamentals + + + ISO 19115-1:2014 + + + + + 2 + + + + + Column + + + 120960 + + + + + + + Row + + + 47040 + + + + + Area + + + false + + + + + + + + + WGS 84 + + + + + + + + + + + 10-daily Leaf Area Index 333M: GLOBE + 2014-01-10T00:00:00Z + + + V1.0.1 + + + + + c_gls_LAI300_201401100000_GLOBE_PROBAV_V1.0.1 + + + + + + + + VITO NV + + + Originator + + + + + http://land.copernicus.eu/global/products/lai + + + + + + + + VITO NV + + + Point of contact + + + + + Grid + + + + + NetCDF-4 + + + Hierarchical Data Format, version 5 + + + + + + + + + + + + + + LAI + + + + + ubyte[120960][47040] + + + + + + + + Leaf Area Index 333m + + + 0.033333 + + + 0.0 + + + + + + + + + + + + + Proba-V + + + + + + + + \ No newline at end of file