/** A column cannot be translated multiple times. */ @Test public void testValidateMultipleTranslationsForColumn() { // before updating fields to simulate multiple translations for same column, mapping validates ExtensionMappingValidator.ValidationStatus status = validator.validate(extensionMapping, resource, peek, columns); assertTrue(status.isValid()); assertEquals(0, status.getMultipleTranslationsForSameColumn().size()); // field translation Map<String, String> translation = Maps.newHashMap(); translation.put("id1", "translated-id1"); Set<PropertyMapping> fields = extensionMapping.getFields(); PropertyMapping identificationId = new PropertyMapping(); identificationId.setTerm(DwcTerm.identificationID); identificationId.setIndex(0); identificationId.setTranslation(translation); fields.add(identificationId); PropertyMapping identificationQualifier = new PropertyMapping(); identificationQualifier.setTerm(DwcTerm.identificationQualifier); identificationQualifier.setIndex(0); identificationQualifier.setTranslation(translation); fields.add(identificationQualifier); status = validator.validate(extensionMapping, resource, peek, columns); assertFalse(status.isValid()); assertEquals(1, status.getMultipleTranslationsForSameColumn().size()); }
/** 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()); }