Added test for json deserialization
This commit is contained in:
parent
490619efe7
commit
3f29a00f05
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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"
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE xml>
|
||||||
|
<configuration>
|
||||||
|
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
|
||||||
|
<logger name="org.gcube" level="INFO" />
|
||||||
|
<logger name="org.gcube.data_catalogue.grsf_publish_ws" level="TRACE" />
|
||||||
|
|
||||||
|
<root level="WARN">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
Loading…
Reference in New Issue