/** Fields that are non-string data types, must be mapped to value of correct type. */ @Test public void testCorrectDataType() { // Core Occurrence extension doesn't need id column mapped ExtensionMappingValidator.ValidationStatus status = validator.validate(extensionMapping, resource, peek, columns); assertTrue(status.isValid()); assertNull(status.getIdProblem()); // add eventDate term to Occurrence extension, and add mapping to it with wrong data type List<ExtensionProperty> extensionProperties = extensionMapping.getExtension().getProperties(); ExtensionProperty extensionProperty = new ExtensionProperty(); extensionProperty.setQualname(DwcTerm.eventDate.qualifiedName()); extensionProperty.setRequired(false); extensionProperty.setType(ArchiveField.DataType.date); extensionProperties.add(extensionProperty); Set<PropertyMapping> fields = extensionMapping.getFields(); PropertyMapping eventDate = new PropertyMapping(); eventDate.setTerm(DwcTerm.eventDate); eventDate.setIndex(1); fields.add(eventDate); peek.add(new String[] {"id1", "August 18, 1983"}); status = validator.validate(extensionMapping, resource, peek, columns); assertFalse(status.isValid()); assertEquals(1, status.getWrongDataTypeFields().size()); }
/** A non-core extension must have an ID column mapping. */ @Test public void testMissingIDColumMappingForNonCoreExtension() { // Core Occurrence extension doesn't need id column mapped ExtensionMappingValidator.ValidationStatus status = validator.validate(extensionMapping, resource, peek, columns); assertTrue(status.isValid()); assertNull(status.getIdProblem()); // Distribution extension does need id column mapped Extension extension = extensionMapping.getExtension(); extension.setRowType("http://rs.gbif.org/terms/1.0/Distribution"); status = validator.validate(extensionMapping, resource, peek, columns); assertFalse(status.isValid()); assertNotNull(status.getIdProblem()); }
/** Required fields must be mapped. */ @Test public void testRequiredFieldMapped() { // Core Occurrence extension doesn't need id column mapped ExtensionMappingValidator.ValidationStatus status = validator.validate(extensionMapping, resource, peek, columns); assertTrue(status.isValid()); assertNull(status.getIdProblem()); // add BasisOfRecord to Occurrence extension, and make it a required field List<ExtensionProperty> extensionProperties = extensionMapping.getExtension().getProperties(); ExtensionProperty extensionProperty = new ExtensionProperty(); extensionProperty.setQualname(DwcTerm.basisOfRecord.qualifiedName()); extensionProperty.setRequired(true); extensionProperties.add(extensionProperty); status = validator.validate(extensionMapping, resource, peek, columns); assertFalse(status.isValid()); assertEquals(1, status.getMissingRequiredFields().size()); }