diff --git a/src/main/java/eu/dissco/core/translator/terms/BaseDigitalObjectDirector.java b/src/main/java/eu/dissco/core/translator/terms/BaseDigitalObjectDirector.java index 117cf8b..5d00258 100644 --- a/src/main/java/eu/dissco/core/translator/terms/BaseDigitalObjectDirector.java +++ b/src/main/java/eu/dissco/core/translator/terms/BaseDigitalObjectDirector.java @@ -174,6 +174,7 @@ import eu.dissco.core.translator.terms.specimen.identification.taxonomy.Tribe; import eu.dissco.core.translator.terms.specimen.identification.taxonomy.VerbatimTaxonRank; import eu.dissco.core.translator.terms.specimen.identification.taxonomy.VernacularName; +import eu.dissco.core.translator.terms.specimen.location.AbstractMeterTerm; import eu.dissco.core.translator.terms.specimen.location.Continent; import eu.dissco.core.translator.terms.specimen.location.Country; import eu.dissco.core.translator.terms.specimen.location.CountryCode; @@ -252,6 +253,17 @@ public abstract class BaseDigitalObjectDirector { private final FdoProperties fdoProperties; private final List identifierTerms; + private static Double stringToDouble(Term term, String value) { + try { + if (value != null) { + return Double.valueOf(value); + } + } catch (NumberFormatException ex) { + log.warn("Unable to parse value: {} to a double for term: {}", value, term.getTerm()); + } + return null; + } + public DigitalSpecimen assembleDigitalSpecimenTerm(JsonNode data, boolean dwc) throws OrganisationException, UnknownPhysicalSpecimenIdType { var ds = assembleDigitalSpecimenTerms(data, dwc); @@ -455,7 +467,6 @@ protected Identification createIdentification(JsonNode data, boolean dwc) { return identification; } - private List assembleEventTerms(JsonNode data, boolean dwc) { var geoReference = new Georeference() .withType("ods:Georeference") @@ -531,14 +542,10 @@ private List assembleEventTerms(JsonNode data, boolean dwc) { .withDwcStateProvince(termMapper.retrieveTerm(new StateProvince(), data, dwc)) .withDwcWaterBody(termMapper.retrieveTerm(new WaterBody(), data, dwc)) .withDwcHigherGeography(termMapper.retrieveTerm(new HigherGeography(), data, dwc)) - .withDwcMaximumDepthInMeters(parseToDouble(new MaximumDepthInMeters(), data, dwc)) .withDwcMaximumDistanceAboveSurfaceInMeters( parseToDouble(new MaximumDistanceAboveSurfaceInMeters(), data, dwc)) - .withDwcMaximumElevationInMeters(parseToDouble(new MaximumElevationInMeters(), data, dwc)) - .withDwcMinimumDepthInMeters(parseToDouble(new MinimumDepthInMeters(), data, dwc)) .withDwcMinimumDistanceAboveSurfaceInMeters( parseToDouble(new MinimumDistanceAboveSurfaceInMeters(), data, dwc)) - .withDwcMinimumElevationInMeters(parseToDouble(new MinimumElevationInMeters(), data, dwc)) .withDwcVerbatimDepth(termMapper.retrieveTerm(new VerbatimDepth(), data, dwc)) .withDwcVerbatimElevation(termMapper.retrieveTerm(new VerbatimElevation(), data, dwc)) .withDwcVerticalDatum(termMapper.retrieveTerm(new VerticalDatum(), data, dwc)) @@ -546,6 +553,10 @@ private List assembleEventTerms(JsonNode data, boolean dwc) { .withDwcLocationRemarks(termMapper.retrieveTerm(new LocationRemarks(), data, dwc)) .withOdsHasGeoreference(geoReference) .withOdsHasGeologicalContext(geologicalContext); + setMinMaxMeterField(new MinimumElevationInMeters(), location, data, dwc); + setMinMaxMeterField(new MaximumElevationInMeters(), location, data, dwc); + setMinMaxMeterField(new MinimumDepthInMeters(), location, data, dwc); + setMinMaxMeterField(new MaximumDepthInMeters(), location, data, dwc); var assertions = new EventAssertions().gatherEventAssertions(mapper, data, dwc); var event = new Event() .withType("ods:Event") @@ -585,6 +596,31 @@ private List assembleEventTerms(JsonNode data, boolean dwc) { return List.of(event); } + private void setMinMaxMeterField(AbstractMeterTerm term, Location location, JsonNode data, + boolean dwc) { + var sanitizedValue = termMapper.retrieveTerm(term, data, dwc); + var doubleElevation = stringToDouble(term, sanitizedValue); + if (doubleElevation == null && sanitizedValue != null) { + if (term instanceof MaximumElevationInMeters) { + location.setDwcVerbatimElevation( + location.getDwcVerbatimElevation() + "| unparseable value maximumElevationInMeters: " + + sanitizedValue); + } else if (term instanceof MinimumElevationInMeters) { + location.setDwcVerbatimElevation( + location.getDwcVerbatimElevation() + "| unparseable value minimumElevationInMeters: " + + sanitizedValue); + } else if (term instanceof MaximumDepthInMeters) { + location.setDwcVerbatimDepth( + location.getDwcVerbatimDepth() + "| unparseable value maximumDepthInMeters: " + + sanitizedValue); + } else if (term instanceof MinimumDepthInMeters) { + location.setDwcVerbatimDepth( + location.getDwcVerbatimDepth() + "| unparseable value minimumDepthInMeters: " + + sanitizedValue); + } + } + } + private > T retrieveEnum(Term term, JsonNode data, boolean dwc, java.lang.Class enumClass) { var value = termMapper.retrieveTerm(term, data, dwc); @@ -612,14 +648,7 @@ private Integer parseToInteger(Term term, JsonNode data, boolean dwc) { private Double parseToDouble(Term term, JsonNode data, boolean dwc) { var value = termMapper.retrieveTerm(term, data, dwc); - try { - if (value != null) { - return Double.valueOf(value); - } - } catch (NumberFormatException ex) { - log.warn("Unable to parse value: {} to a double for term: {}", value, term.getTerm()); - } - return null; + return stringToDouble(term, value); } private Boolean parseToBoolean(Term term, JsonNode data, boolean dwc) { diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/location/AbstractMeterTerm.java b/src/main/java/eu/dissco/core/translator/terms/specimen/location/AbstractMeterTerm.java new file mode 100644 index 0000000..8c60b18 --- /dev/null +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/location/AbstractMeterTerm.java @@ -0,0 +1,28 @@ +package eu.dissco.core.translator.terms.specimen.location; + +import eu.dissco.core.translator.terms.Term; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public abstract class AbstractMeterTerm extends Term { + + private static final Pattern M_PATTERN = Pattern.compile("((-\\s?)?\\d+([.,]\\d+)?)\\s*m\\.?(eter)?(tr?.?)?(\\sm.?)?"); + + protected String sanitizeInput(String input) { + if (input == null) { + return null; + } + input = input.trim().toLowerCase(); + Matcher matcher = M_PATTERN.matcher(input); + if (matcher.matches()) { + log.debug("Parsed Number: {}", matcher.group(1)); + return matcher.group(1); + } else { + log.debug("Input string does not match the expected format: {}", input); + return input; + } + } + +} diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/location/MaximumDepthInMeters.java b/src/main/java/eu/dissco/core/translator/terms/specimen/location/MaximumDepthInMeters.java index 87cd617..c937460 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/location/MaximumDepthInMeters.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/location/MaximumDepthInMeters.java @@ -1,10 +1,9 @@ package eu.dissco.core.translator.terms.specimen.location; import com.fasterxml.jackson.databind.JsonNode; -import eu.dissco.core.translator.terms.Term; import java.util.List; -public class MaximumDepthInMeters extends Term { +public class MaximumDepthInMeters extends AbstractMeterTerm { public static final String TERM = DWC_PREFIX + "maximumDepthInMeters"; @@ -15,12 +14,14 @@ public class MaximumDepthInMeters extends Term { @Override public String retrieveFromDWCA(JsonNode unit) { - return super.searchJsonForTerm(unit, dwcaTerms); + var rawResult = super.searchJsonForTerm(unit, dwcaTerms); + return sanitizeInput(rawResult); } @Override public String retrieveFromABCD(JsonNode unit) { - return super.searchJsonForTerm(unit, abcdTerms); + var rawResult = super.searchJsonForTerm(unit, abcdTerms); + return sanitizeInput(rawResult); } @Override diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/location/MaximumDistanceAboveSurfaceInMeters.java b/src/main/java/eu/dissco/core/translator/terms/specimen/location/MaximumDistanceAboveSurfaceInMeters.java index 9bc29d6..b9f2275 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/location/MaximumDistanceAboveSurfaceInMeters.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/location/MaximumDistanceAboveSurfaceInMeters.java @@ -1,10 +1,9 @@ package eu.dissco.core.translator.terms.specimen.location; import com.fasterxml.jackson.databind.JsonNode; -import eu.dissco.core.translator.terms.Term; import java.util.List; -public class MaximumDistanceAboveSurfaceInMeters extends Term { +public class MaximumDistanceAboveSurfaceInMeters extends AbstractMeterTerm { public static final String TERM = DWC_PREFIX + "maximumDistanceAboveSurfaceInMeters"; @@ -14,12 +13,14 @@ public class MaximumDistanceAboveSurfaceInMeters extends Term { @Override public String retrieveFromDWCA(JsonNode unit) { - return super.searchJsonForTerm(unit, dwcaTerms); + var rawResult = super.searchJsonForTerm(unit, dwcaTerms); + return sanitizeInput(rawResult); } @Override public String retrieveFromABCD(JsonNode unit) { - return super.searchJsonForTerm(unit, abcdTerms); + var rawResult = super.searchJsonForTerm(unit, abcdTerms); + return sanitizeInput(rawResult); } @Override diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/location/MaximumElevationInMeters.java b/src/main/java/eu/dissco/core/translator/terms/specimen/location/MaximumElevationInMeters.java index a5e4b6c..1999609 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/location/MaximumElevationInMeters.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/location/MaximumElevationInMeters.java @@ -1,10 +1,9 @@ package eu.dissco.core.translator.terms.specimen.location; import com.fasterxml.jackson.databind.JsonNode; -import eu.dissco.core.translator.terms.Term; import java.util.List; -public class MaximumElevationInMeters extends Term { +public class MaximumElevationInMeters extends AbstractMeterTerm { public static final String TERM = DWC_PREFIX + "maximumElevationInMeters"; @@ -15,12 +14,14 @@ public class MaximumElevationInMeters extends Term { @Override public String retrieveFromDWCA(JsonNode unit) { - return super.searchJsonForTerm(unit, dwcaTerms); + var rawResult = super.searchJsonForTerm(unit, dwcaTerms); + return sanitizeInput(rawResult); } @Override public String retrieveFromABCD(JsonNode unit) { - return super.searchJsonForTerm(unit, abcdTerms); + var rawResult = super.searchJsonForTerm(unit, abcdTerms); + return sanitizeInput(rawResult); } @Override diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/location/MinimumDepthInMeters.java b/src/main/java/eu/dissco/core/translator/terms/specimen/location/MinimumDepthInMeters.java index 3d865be..b0c220f 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/location/MinimumDepthInMeters.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/location/MinimumDepthInMeters.java @@ -1,10 +1,9 @@ package eu.dissco.core.translator.terms.specimen.location; import com.fasterxml.jackson.databind.JsonNode; -import eu.dissco.core.translator.terms.Term; import java.util.List; -public class MinimumDepthInMeters extends Term { +public class MinimumDepthInMeters extends AbstractMeterTerm { public static final String TERM = DWC_PREFIX + "minimumDepthInMeters"; @@ -15,12 +14,14 @@ public class MinimumDepthInMeters extends Term { @Override public String retrieveFromDWCA(JsonNode unit) { - return super.searchJsonForTerm(unit, dwcaTerms); + var rawResult = super.searchJsonForTerm(unit, dwcaTerms); + return sanitizeInput(rawResult); } @Override public String retrieveFromABCD(JsonNode unit) { - return super.searchJsonForTerm(unit, abcdTerms); + var rawResult = super.searchJsonForTerm(unit, abcdTerms); + return sanitizeInput(rawResult); } @Override diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/location/MinimumDistanceAboveSurfaceInMeters.java b/src/main/java/eu/dissco/core/translator/terms/specimen/location/MinimumDistanceAboveSurfaceInMeters.java index d52b51f..17f4315 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/location/MinimumDistanceAboveSurfaceInMeters.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/location/MinimumDistanceAboveSurfaceInMeters.java @@ -1,10 +1,9 @@ package eu.dissco.core.translator.terms.specimen.location; import com.fasterxml.jackson.databind.JsonNode; -import eu.dissco.core.translator.terms.Term; import java.util.List; -public class MinimumDistanceAboveSurfaceInMeters extends Term { +public class MinimumDistanceAboveSurfaceInMeters extends AbstractMeterTerm { public static final String TERM = DWC_PREFIX + "minimumDistanceAboveSurfaceInMeters"; @@ -14,12 +13,14 @@ public class MinimumDistanceAboveSurfaceInMeters extends Term { @Override public String retrieveFromDWCA(JsonNode unit) { - return super.searchJsonForTerm(unit, dwcaTerms); + var rawResult = super.searchJsonForTerm(unit, dwcaTerms); + return sanitizeInput(rawResult); } @Override public String retrieveFromABCD(JsonNode unit) { - return super.searchJsonForTerm(unit, abcdTerms); + var rawResult = super.searchJsonForTerm(unit, abcdTerms); + return sanitizeInput(rawResult); } @Override diff --git a/src/main/java/eu/dissco/core/translator/terms/specimen/location/MinimumElevationInMeters.java b/src/main/java/eu/dissco/core/translator/terms/specimen/location/MinimumElevationInMeters.java index 03a82f2..15ae95c 100644 --- a/src/main/java/eu/dissco/core/translator/terms/specimen/location/MinimumElevationInMeters.java +++ b/src/main/java/eu/dissco/core/translator/terms/specimen/location/MinimumElevationInMeters.java @@ -1,10 +1,9 @@ package eu.dissco.core.translator.terms.specimen.location; import com.fasterxml.jackson.databind.JsonNode; -import eu.dissco.core.translator.terms.Term; import java.util.List; -public class MinimumElevationInMeters extends Term { +public class MinimumElevationInMeters extends AbstractMeterTerm { public static final String TERM = DWC_PREFIX + "minimumElevationInMeters"; @@ -15,12 +14,14 @@ public class MinimumElevationInMeters extends Term { @Override public String retrieveFromDWCA(JsonNode unit) { - return super.searchJsonForTerm(unit, dwcaTerms); + var rawResult = super.searchJsonForTerm(unit, dwcaTerms); + return sanitizeInput(rawResult); } @Override public String retrieveFromABCD(JsonNode unit) { - return super.searchJsonForTerm(unit, abcdTerms); + var rawResult = super.searchJsonForTerm(unit, abcdTerms); + return sanitizeInput(rawResult); } @Override diff --git a/src/main/java/eu/dissco/core/translator/terms/utils/IdentifierUtils.java b/src/main/java/eu/dissco/core/translator/terms/utils/IdentifierUtils.java index f69489b..db97dcd 100644 --- a/src/main/java/eu/dissco/core/translator/terms/utils/IdentifierUtils.java +++ b/src/main/java/eu/dissco/core/translator/terms/utils/IdentifierUtils.java @@ -1,6 +1,11 @@ package eu.dissco.core.translator.terms.utils; -import static eu.dissco.core.translator.schema.Identifier.DctermsType.*; +import static eu.dissco.core.translator.schema.Identifier.DctermsType.ARK; +import static eu.dissco.core.translator.schema.Identifier.DctermsType.DOI; +import static eu.dissco.core.translator.schema.Identifier.DctermsType.HANDLE; +import static eu.dissco.core.translator.schema.Identifier.DctermsType.PURL; +import static eu.dissco.core.translator.schema.Identifier.DctermsType.URL; +import static eu.dissco.core.translator.schema.Identifier.DctermsType.UUID; import static eu.dissco.core.translator.schema.Identifier.OdsGupriLevel.GLOBALLY_UNIQUE_STABLE; import static eu.dissco.core.translator.schema.Identifier.OdsGupriLevel.GLOBALLY_UNIQUE_STABLE_PERSISTENT_RESOLVABLE; import static eu.dissco.core.translator.schema.Identifier.OdsGupriLevel.GLOBALLY_UNIQUE_STABLE_PERSISTENT_RESOLVABLE_FDO_COMPLIANT; diff --git a/src/test/java/eu/dissco/core/translator/terms/specimen/location/MaximumDepthInMetersTest.java b/src/test/java/eu/dissco/core/translator/terms/specimen/location/MaximumDepthInMetersTest.java index 8e46381..6bbed1d 100644 --- a/src/test/java/eu/dissco/core/translator/terms/specimen/location/MaximumDepthInMetersTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/specimen/location/MaximumDepthInMetersTest.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @@ -13,11 +15,12 @@ class MaximumDepthInMetersTest { private static final String MAXIMUM_DEPTH_IN_METERS_STRING = "-350"; private final MaximumDepthInMeters maximumDepthInMeters = new MaximumDepthInMeters(); - @Test - void testRetrieveFromDWCA() { + @ParameterizedTest + @ValueSource(strings = {"-350m.", "-350meter", "-350 m", "-350 MTR"}) + void testRetrieveFromDWCA(String input) { // Given var unit = MAPPER.createObjectNode(); - unit.put("dwc:maximumDepthInMeters", MAXIMUM_DEPTH_IN_METERS_STRING); + unit.put("dwc:maximumDepthInMeters", input); // When var result = maximumDepthInMeters.retrieveFromDWCA(unit); @@ -27,11 +30,38 @@ void testRetrieveFromDWCA() { } @Test - void testRetrieveFromABCD() { + void testRetrieveFromDWCANull() { + // Given + var unit = MAPPER.createObjectNode(); + unit.putNull("dwc:maximumDepthInMeters"); + + // When + var result = maximumDepthInMeters.retrieveFromDWCA(unit); + + // Then + assertThat(result).isNull(); + } + + @Test + void testRetrieveFromDWCAUnSanitizable() { + // Given + var unit = MAPPER.createObjectNode(); + unit.put("dwc:maximumDepthInMeters", "235 ft"); + + // When + var result = maximumDepthInMeters.retrieveFromDWCA(unit); + + // Then + assertThat(result).isEqualTo("235 ft"); + } + + @ParameterizedTest + @ValueSource(strings = {"-350m.", "-350meter", "-350 m", "-350 MTR"}) + void testRetrieveFromABCD(String input) { // Given var unit = MAPPER.createObjectNode(); unit.put("abcd:gathering/depth/measurementOrFactAtomised/upperValue/value", - MAXIMUM_DEPTH_IN_METERS_STRING); + input); // When var result = maximumDepthInMeters.retrieveFromABCD(unit); @@ -40,6 +70,19 @@ void testRetrieveFromABCD() { assertThat(result).isEqualTo(MAXIMUM_DEPTH_IN_METERS_STRING); } + @Test + void testRetrieveFromABCDNull() { + // Given + var unit = MAPPER.createObjectNode(); + unit.putNull("abcd:gathering/depth/measurementOrFactAtomised/upperValue/value"); + + // When + var result = maximumDepthInMeters.retrieveFromABCD(unit); + + // Then + assertThat(result).isNull(); + } + @Test void testGetTerm() { // When diff --git a/src/test/java/eu/dissco/core/translator/terms/specimen/location/MaximumDistanceAboveSurfaceInMetersTest.java b/src/test/java/eu/dissco/core/translator/terms/specimen/location/MaximumDistanceAboveSurfaceInMetersTest.java index 1ba68df..a656dc6 100644 --- a/src/test/java/eu/dissco/core/translator/terms/specimen/location/MaximumDistanceAboveSurfaceInMetersTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/specimen/location/MaximumDistanceAboveSurfaceInMetersTest.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @@ -13,12 +15,12 @@ class MaximumDistanceAboveSurfaceInMetersTest { private static final String MAXIMUM_DISTANCE_ABOVE_SURFACE_IN_METERS_STRING = "350"; private final MaximumDistanceAboveSurfaceInMeters maximumDistanceAboveSurfaceInMeters = new MaximumDistanceAboveSurfaceInMeters(); - @Test - void testRetrieveFromDWCA() { + @ParameterizedTest + @ValueSource(strings = {"350m.", "350meter", "350 m m", "350 mtr"}) + void testRetrieveFromDWCA(String input) { // Given var unit = MAPPER.createObjectNode(); - unit.put("dwc:maximumDistanceAboveSurfaceInMeters", - MAXIMUM_DISTANCE_ABOVE_SURFACE_IN_METERS_STRING); + unit.put("dwc:maximumDistanceAboveSurfaceInMeters", input); // When var result = maximumDistanceAboveSurfaceInMeters.retrieveFromDWCA(unit); @@ -28,11 +30,24 @@ void testRetrieveFromDWCA() { } @Test - void testRetrieveFromABCD() { + void testRetrieveFromDWCANull() { + // Given + var unit = MAPPER.createObjectNode(); + unit.putNull("dwc:maximumDistanceAboveSurfaceInMeters"); + + // When + var result = maximumDistanceAboveSurfaceInMeters.retrieveFromDWCA(unit); + + // Then + assertThat(result).isNull(); + } + + @ParameterizedTest + @ValueSource(strings = {"350m.", "350meter", "350 m m", "350 mtr"}) + void testRetrieveFromABCD(String input) { // Given var unit = MAPPER.createObjectNode(); - unit.put("abcd:gathering/height/measurementOrFactAtomised/upperValue/value", - MAXIMUM_DISTANCE_ABOVE_SURFACE_IN_METERS_STRING); + unit.put("abcd:gathering/height/measurementOrFactAtomised/upperValue/value", input); // When var result = maximumDistanceAboveSurfaceInMeters.retrieveFromABCD(unit); @@ -41,6 +56,19 @@ void testRetrieveFromABCD() { assertThat(result).isEqualTo(MAXIMUM_DISTANCE_ABOVE_SURFACE_IN_METERS_STRING); } + @Test + void testRetrieveFromABCDNull() { + // Given + var unit = MAPPER.createObjectNode(); + unit.putNull("abcd:gathering/height/measurementOrFactAtomised/upperValue/value"); + + // When + var result = maximumDistanceAboveSurfaceInMeters.retrieveFromABCD(unit); + + // Then + assertThat(result).isNull(); + } + @Test void testGetTerm() { // When diff --git a/src/test/java/eu/dissco/core/translator/terms/specimen/location/MaximumElevationInMetersTest.java b/src/test/java/eu/dissco/core/translator/terms/specimen/location/MaximumElevationInMetersTest.java index 4b0781a..1c29773 100644 --- a/src/test/java/eu/dissco/core/translator/terms/specimen/location/MaximumElevationInMetersTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/specimen/location/MaximumElevationInMetersTest.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @@ -13,11 +15,12 @@ class MaximumElevationInMetersTest { private static final String MAXIMUM_ELEVATION_IN_METERS_STRING = "350"; private final MaximumElevationInMeters maximumElevationInMeters = new MaximumElevationInMeters(); - @Test - void testRetrieveFromDWCA() { + @ParameterizedTest + @ValueSource(strings = {"350m.", "350meter", "350 m", "350 MTR"}) + void testRetrieveFromDWCA(String input) { // Given var unit = MAPPER.createObjectNode(); - unit.put("dwc:maximumElevationInMeters", MAXIMUM_ELEVATION_IN_METERS_STRING); + unit.put("dwc:maximumElevationInMeters", input); // When var result = maximumElevationInMeters.retrieveFromDWCA(unit); @@ -27,11 +30,24 @@ void testRetrieveFromDWCA() { } @Test - void testRetrieveFromABCD() { + void testRetrieveFromDWCANull() { + // Given + var unit = MAPPER.createObjectNode(); + unit.putNull("dwc:maximumElevationInMeters"); + + // When + var result = maximumElevationInMeters.retrieveFromDWCA(unit); + + // Then + assertThat(result).isNull(); + } + + @ParameterizedTest + @ValueSource(strings = {"350m.", "350meter", "350 m", "350 MTR"}) + void testRetrieveFromABCD(String input) { // Given var unit = MAPPER.createObjectNode(); - unit.put("abcd:gathering/altitude/measurementOrFactAtomised/upperValue/value", - MAXIMUM_ELEVATION_IN_METERS_STRING); + unit.put("abcd:gathering/altitude/measurementOrFactAtomised/upperValue/value", input); // When var result = maximumElevationInMeters.retrieveFromABCD(unit); @@ -40,6 +56,19 @@ void testRetrieveFromABCD() { assertThat(result).isEqualTo(MAXIMUM_ELEVATION_IN_METERS_STRING); } + @Test + void testRetrieveFromABCDNull() { + // Given + var unit = MAPPER.createObjectNode(); + unit.putNull("abcd:gathering/altitude/measurementOrFactAtomised/upperValue/value"); + + // When + var result = maximumElevationInMeters.retrieveFromABCD(unit); + + // Then + assertThat(result).isNull(); + } + @Test void testGetTerm() { // When diff --git a/src/test/java/eu/dissco/core/translator/terms/specimen/location/MinimumDepthInMetersTest.java b/src/test/java/eu/dissco/core/translator/terms/specimen/location/MinimumDepthInMetersTest.java index 9e664c0..0041417 100644 --- a/src/test/java/eu/dissco/core/translator/terms/specimen/location/MinimumDepthInMetersTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/specimen/location/MinimumDepthInMetersTest.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @@ -13,11 +15,12 @@ class MinimumDepthInMetersTest { private static final String MINIMUM_DEPTH_IN_METERS_STRING = "-50"; private final MinimumDepthInMeters minimumDepthInMeters = new MinimumDepthInMeters(); - @Test - void testRetrieveFromDWCA() { + @ParameterizedTest + @ValueSource(strings = {"-50m.", "-50meter", "-50 m", "-50 MTR"}) + void testRetrieveFromDWCA(String input) { // Given var unit = MAPPER.createObjectNode(); - unit.put("dwc:minimumDepthInMeters", MINIMUM_DEPTH_IN_METERS_STRING); + unit.put("dwc:minimumDepthInMeters", input); // When var result = minimumDepthInMeters.retrieveFromDWCA(unit); @@ -27,11 +30,24 @@ void testRetrieveFromDWCA() { } @Test - void testRetrieveFromABCD() { + void testRetrieveFromDWCANull() { + // Given + var unit = MAPPER.createObjectNode(); + unit.putNull("dwc:minimumDepthInMeters"); + + // When + var result = minimumDepthInMeters.retrieveFromDWCA(unit); + + // Then + assertThat(result).isNull(); + } + + @ParameterizedTest + @ValueSource(strings = {"-50m.", "-50meter", "-50 m", "-50 MTR"}) + void testRetrieveFromABCD(String input) { // Given var unit = MAPPER.createObjectNode(); - unit.put("abcd:gathering/depth/measurementOrFactAtomised/lowerValue/value", - MINIMUM_DEPTH_IN_METERS_STRING); + unit.put("abcd:gathering/depth/measurementOrFactAtomised/lowerValue/value", input); // When var result = minimumDepthInMeters.retrieveFromABCD(unit); @@ -40,6 +56,19 @@ void testRetrieveFromABCD() { assertThat(result).isEqualTo(MINIMUM_DEPTH_IN_METERS_STRING); } + @Test + void testRetrieveFromNull() { + // Given + var unit = MAPPER.createObjectNode(); + unit.putNull("abcd:gathering/depth/measurementOrFactAtomised/lowerValue/value"); + + // When + var result = minimumDepthInMeters.retrieveFromABCD(unit); + + // Then + assertThat(result).isNull(); + } + @Test void testGetTerm() { // When diff --git a/src/test/java/eu/dissco/core/translator/terms/specimen/location/MinimumDistanceAboveSurfaceInMetersTest.java b/src/test/java/eu/dissco/core/translator/terms/specimen/location/MinimumDistanceAboveSurfaceInMetersTest.java index d4353e9..a50e598 100644 --- a/src/test/java/eu/dissco/core/translator/terms/specimen/location/MinimumDistanceAboveSurfaceInMetersTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/specimen/location/MinimumDistanceAboveSurfaceInMetersTest.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @@ -13,12 +15,12 @@ class MinimumDistanceAboveSurfaceInMetersTest { private static final String MINIMUM_DISTANCE_ABOVE_SURFACE_IN_METERS_STRING = "250"; private final MinimumDistanceAboveSurfaceInMeters minimumDistanceAboveSurfaceInMeters = new MinimumDistanceAboveSurfaceInMeters(); - @Test - void testRetrieveFromDWCA() { + @ParameterizedTest + @ValueSource(strings = {"250m. ", "250 meter", "250 m", "250 MTR"}) + void testRetrieveFromDWCA(String input) { // Given var unit = MAPPER.createObjectNode(); - unit.put("dwc:minimumDistanceAboveSurfaceInMeters", - MINIMUM_DISTANCE_ABOVE_SURFACE_IN_METERS_STRING); + unit.put("dwc:minimumDistanceAboveSurfaceInMeters", input); // When var result = minimumDistanceAboveSurfaceInMeters.retrieveFromDWCA(unit); @@ -28,11 +30,24 @@ void testRetrieveFromDWCA() { } @Test - void testRetrieveFromABCD() { + void testRetrieveFromDWCANull() { + // Given + var unit = MAPPER.createObjectNode(); + unit.putNull("dwc:minimumDistanceAboveSurfaceInMeters"); + + // When + var result = minimumDistanceAboveSurfaceInMeters.retrieveFromDWCA(unit); + + // Then + assertThat(result).isNull(); + } + + @ParameterizedTest + @ValueSource(strings = {"250m. ", "250 meter", "250 m", "250 MTR"}) + void testRetrieveFromABCD(String input) { // Given var unit = MAPPER.createObjectNode(); - unit.put("abcd:gathering/height/measurementOrFactAtomised/lowerValue/value", - MINIMUM_DISTANCE_ABOVE_SURFACE_IN_METERS_STRING); + unit.put("abcd:gathering/height/measurementOrFactAtomised/lowerValue/value", input); // When var result = minimumDistanceAboveSurfaceInMeters.retrieveFromABCD(unit); @@ -41,6 +56,19 @@ void testRetrieveFromABCD() { assertThat(result).isEqualTo(MINIMUM_DISTANCE_ABOVE_SURFACE_IN_METERS_STRING); } + @Test + void testRetrieveFromABCDNull() { + // Given + var unit = MAPPER.createObjectNode(); + unit.putNull("abcd:gathering/height/measurementOrFactAtomised/lowerValue/value"); + + // When + var result = minimumDistanceAboveSurfaceInMeters.retrieveFromABCD(unit); + + // Then + assertThat(result).isNull(); + } + @Test void testGetTerm() { // When diff --git a/src/test/java/eu/dissco/core/translator/terms/specimen/location/MinimumElevationInMetersTest.java b/src/test/java/eu/dissco/core/translator/terms/specimen/location/MinimumElevationInMetersTest.java index e587ff2..ecac64c 100644 --- a/src/test/java/eu/dissco/core/translator/terms/specimen/location/MinimumElevationInMetersTest.java +++ b/src/test/java/eu/dissco/core/translator/terms/specimen/location/MinimumElevationInMetersTest.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @@ -13,11 +15,12 @@ class MinimumElevationInMetersTest { private static final String MINIMUM_ELEVATION_IN_METERS_STRING = "250"; private final MinimumElevationInMeters minimumElevationInMeters = new MinimumElevationInMeters(); - @Test - void testRetrieveFromDWCA() { + @ParameterizedTest + @ValueSource(strings = {"250m. ", "250 meter", "250 m", "250 MTR"}) + void testRetrieveFromDWCA(String input) { // Given var unit = MAPPER.createObjectNode(); - unit.put("dwc:minimumElevationInMeters", MINIMUM_ELEVATION_IN_METERS_STRING); + unit.put("dwc:minimumElevationInMeters", input); // When var result = minimumElevationInMeters.retrieveFromDWCA(unit); @@ -27,11 +30,24 @@ void testRetrieveFromDWCA() { } @Test - void testRetrieveFromABCD() { + void testRetrieveFromDWCANull() { + // Given + var unit = MAPPER.createObjectNode(); + unit.putNull("dwc:minimumElevationInMeters"); + + // When + var result = minimumElevationInMeters.retrieveFromDWCA(unit); + + // Then + assertThat(result).isNull(); + } + + @ParameterizedTest + @ValueSource(strings = {"250m. ", "250 meter", "250 m", "250 MTR"}) + void testRetrieveFromABCD(String input) { // Given var unit = MAPPER.createObjectNode(); - unit.put("abcd:gathering/altitude/measurementOrFactAtomised/lowerValue/value", - MINIMUM_ELEVATION_IN_METERS_STRING); + unit.put("abcd:gathering/altitude/measurementOrFactAtomised/lowerValue/value", input); // When var result = minimumElevationInMeters.retrieveFromABCD(unit); @@ -40,6 +56,19 @@ void testRetrieveFromABCD() { assertThat(result).isEqualTo(MINIMUM_ELEVATION_IN_METERS_STRING); } + @Test + void testRetrieveFromABCDNull() { + // Given + var unit = MAPPER.createObjectNode(); + unit.putNull("abcd:gathering/altitude/measurementOrFactAtomised/lowerValue/value"); + + // When + var result = minimumElevationInMeters.retrieveFromABCD(unit); + + // Then + assertThat(result).isNull(); + } + @Test void testGetTerm() { // When