From 3f29a00f05a53d40a5ec84e7560461aab087d624 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 2 Sep 2022 12:42:03 +0200 Subject: [PATCH] Added test for json deserialization --- .../grsf_publish_ws/TestJson.java | 39 +++++++++++++++++++ .../70ae6895-7d3d-4f4a-86f9-bcb17d41bff6.json | 34 ++++++++++++++++ src/test/resources/logback-test.xml | 19 +++++++++ 3 files changed, 92 insertions(+) create mode 100644 src/test/java/org/gcube/data_catalogue/grsf_publish_ws/TestJson.java create mode 100644 src/test/resources/70ae6895-7d3d-4f4a-86f9-bcb17d41bff6.json create mode 100644 src/test/resources/logback-test.xml diff --git a/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/TestJson.java b/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/TestJson.java new file mode 100644 index 0000000..e9c9409 --- /dev/null +++ b/src/test/java/org/gcube/data_catalogue/grsf_publish_ws/TestJson.java @@ -0,0 +1,39 @@ +package org.gcube.data_catalogue.grsf_publish_ws; + +import java.io.File; +import java.io.IOException; +import java.net.URL; + +import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.StockRecord; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +public class TestJson { + + private static final Logger logger = LoggerFactory.getLogger(Test.class); + + public File getResourcesDirectory() throws Exception { + URL logbackFileURL = TestJson.class.getClassLoader().getResource("logback-test.xml"); + File logbackFile = new File(logbackFileURL.toURI()); + File resourcesDirectory = logbackFile.getParentFile(); + return resourcesDirectory; + } + + @Test + public void testJsonDeserialization() throws Exception { + File jsonQueryFile = new File(getResourcesDirectory(), "70ae6895-7d3d-4f4a-86f9-bcb17d41bff6.json"); + ObjectMapper objectMapper = new ObjectMapper(); + // JsonNode jsonNode = objectMapper.readTree(jsonQueryFile); + StockRecord sr = objectMapper.readValue(jsonQueryFile, StockRecord.class); + logger.debug("{}", sr); + } + +} diff --git a/src/test/resources/70ae6895-7d3d-4f4a-86f9-bcb17d41bff6.json b/src/test/resources/70ae6895-7d3d-4f4a-86f9-bcb17d41bff6.json new file mode 100644 index 0000000..15d420c --- /dev/null +++ b/src/test/resources/70ae6895-7d3d-4f4a-86f9-bcb17d41bff6.json @@ -0,0 +1,34 @@ +{ + "stock_name" : "European hake - Southern Adriatic", + "license_id" : "CC-BY-SA-4.0", + "version" : 1.0, + "database_sources" : [ { + "name" : "FAO SDG 14.4.1 questionnaire", + "description" : "FAO SDG 14.4.1 questionnaire", + "url" : "https://www.fao.org/sustainable-development-goals/indicators/14.4.1/en/" + } ], + "stock_uri" : "https://github.com/grsf/resource/sdg_14_4_1/stock/70ae6895-7d3d-4f4a-86f9-bcb17d41bff6", + "grsf_uuid" : "70ae6895-7d3d-4f4a-86f9-bcb17d41bff6", + "short_name" : "European hake - Southern Adriatic", + "description" : "European hake - Southern Adriatic", + "grsf_type" : "assessment unit", + "species" : [ "Code: HKE, Classification System: ASFIS, Scientific Name: Merluccius merluccius" ], + "assessment_area" : [ "Code: 18, System: gfcm, Name: Southern Adriatic " ], + "source_of_information" : [ { + "name" : "https://www.fao.org/sustainable-development-goals/indicators/14.4.1/en/sdg-alb-1", + "description" : "", + "url" : "https://www.fao.org/sustainable-development-goals/indicators/14.4.1/en/sdg-alb-1" + } ], + "data_owner" : [ "Albania" ], + "assessment_methods" : [ "The official stock assessment concludes 'Overfished' with respect to abundance reference points. [Rep. Year or Assessment ID: 2019, Ref. Year: 2018]" ], + "connections_indicator" : "not connected", + "similarities_indicator" : "without similar records", + "landings" : [ { + "value" : "872", + "unit" : "Tonnes", + "reference_year" : 2018, + "reporting_year_or_assessment_id" : "2020", + "data_owner" : "Albania" + } ], + "citation" : "citation TBD" +} \ No newline at end of file diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml new file mode 100644 index 0000000..10cbe5a --- /dev/null +++ b/src/test/resources/logback-test.xml @@ -0,0 +1,19 @@ + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n + + + + + + + + + + + + \ No newline at end of file