use of org.eol.globi.tool.NullImportLogger in project eol-globi-data by jhpoelen.
the class DatasetImporterForDwCATest method nonInteractionRecordMessage.
@Test
public void nonInteractionRecordMessage() throws StudyImporterException, URISyntaxException {
List<String> msgs = new ArrayList<>();
URL resource = getClass().getResource("/org/globalbioticinteractions/dataset/mcz-adjusted/meta.xml");
URI archiveRoot = new File(resource.toURI()).getParentFile().toURI();
AtomicInteger recordCounter = new AtomicInteger(0);
DatasetImporterForDwCA studyImporterForDwCA = new DatasetImporterForDwCA(null, null);
studyImporterForDwCA.setLogger(new NullImportLogger() {
@Override
public void info(LogContext ctx, String message) {
msgs.add(message);
}
});
studyImporterForDwCA.setDataset(new DatasetImpl("some/namespace", archiveRoot, inStream -> inStream));
studyImporterForDwCA.setInteractionListener(new InteractionListener() {
@Override
public void on(Map<String, String> interaction) throws StudyImporterException {
assertThat(interaction.get(DatasetImporterForTSV.RESOURCE_TYPES), is("http://rs.tdwg.org/dwc/terms/ResourceRelationship | http://rs.tdwg.org/dwc/terms/Occurrence"));
recordCounter.incrementAndGet();
}
});
studyImporterForDwCA.importStudy();
assertThat(recordCounter.get(), is(0));
String joinedMsgs = StringUtils.join(msgs, "\n");
assertThat(joinedMsgs, containsString("]: indexing interaction records"));
assertThat(joinedMsgs, containsString("]: scanned [1] record(s)"));
}
use of org.eol.globi.tool.NullImportLogger in project eol-globi-data by jhpoelen.
the class InteractionListenerWithInteractionTypeMappingTest method withVerbatimInteractionType.
@Test
public void withVerbatimInteractionType() throws StudyImporterException {
final List<Map<String, String>> links = new ArrayList<>();
InteractionListener listener = new InteractionListenerWithInteractionTypeMapping(links::add, new InteractTypeMapper() {
@Override
public boolean shouldIgnoreInteractionType(String nameOrId) {
return false;
}
@Override
public InteractType getInteractType(String nameOrId) {
return InteractType.ATE;
}
}, new NullImportLogger());
listener.on(new HashMap<String, String>() {
{
put(INTERACTION_TYPE_NAME, "Donald");
put(INTERACTION_TYPE_ID, "duck");
}
});
assertThat(links.size(), is(1));
assertThat(links.get(0).get(INTERACTION_TYPE_ID_VERBATIM), is("duck"));
assertThat(links.get(0).get(INTERACTION_TYPE_NAME_VERBATIM), is("Donald"));
assertThat(links.get(0).get(INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002470"));
assertThat(links.get(0).get(INTERACTION_TYPE_NAME), is("eats"));
}
use of org.eol.globi.tool.NullImportLogger in project eol-globi-data by jhpoelen.
the class InteractionListenerWithInteractionTypeMappingTest method withBlankInteractionType.
@Test
public void withBlankInteractionType() throws StudyImporterException {
final List<Map<String, String>> links = new ArrayList<>();
InteractionListener listener = new InteractionListenerWithInteractionTypeMapping(links::add, new InteractTypeMapper() {
@Override
public boolean shouldIgnoreInteractionType(String nameOrId) {
return false;
}
@Override
public InteractType getInteractType(String nameOrId) {
return InteractType.ATE;
}
}, new NullImportLogger());
listener.on(new HashMap<String, String>() {
{
put(INTERACTION_TYPE_NAME, "");
put(INTERACTION_TYPE_ID, "");
}
});
assertThat(links.size(), is(1));
assertThat(links.get(0).get(INTERACTION_TYPE_ID), is("http://purl.obolibrary.org/obo/RO_0002470"));
assertThat(links.get(0).get(INTERACTION_TYPE_NAME), is("eats"));
assertThat(links.get(0).get(INTERACTION_TYPE_ID_VERBATIM), is(""));
assertThat(links.get(0).get(INTERACTION_TYPE_NAME_VERBATIM), is(""));
}
use of org.eol.globi.tool.NullImportLogger in project eol-globi-data by jhpoelen.
the class InteractionListenerWithInteractionTypeMappingTest method withNullInteractionType.
@Test
public void withNullInteractionType() throws StudyImporterException {
final List<Map<String, String>> links = new ArrayList<>();
InteractionListener listener = new InteractionListenerWithInteractionTypeMapping(links::add, new InteractTypeMapper() {
@Override
public boolean shouldIgnoreInteractionType(String nameOrId) {
return false;
}
@Override
public InteractType getInteractType(String nameOrId) {
return InteractType.ATE;
}
}, new NullImportLogger());
listener.on(new HashMap<String, String>() {
{
put(INTERACTION_TYPE_NAME, null);
put(INTERACTION_TYPE_ID, null);
}
});
assertThat(links.size(), is(1));
assertThat(links.get(0).get(INTERACTION_TYPE_ID), is(nullValue()));
assertThat(links.get(0).get(INTERACTION_TYPE_NAME), is(nullValue()));
assertThat(links.get(0).get(INTERACTION_TYPE_ID_VERBATIM), is(nullValue()));
assertThat(links.get(0).get(INTERACTION_TYPE_NAME_VERBATIM), is(nullValue()));
}
use of org.eol.globi.tool.NullImportLogger in project eol-globi-data by jhpoelen.
the class TaxonNameEnricherTest method importWithMissingTargetTaxonButAvailableInstitutionCollectionCatalogTriple.
@Test
public void importWithMissingTargetTaxonButAvailableInstitutionCollectionCatalogTriple() throws StudyImporterException {
List<String> msgs = new ArrayList<>();
List<Map<String, String>> received = new ArrayList<>();
final InteractionListener listener = new TaxonNameEnricher(interaction -> received.add(interaction), new NullImportLogger() {
@Override
public void info(LogContext ctx, String message) {
msgs.add(message);
}
@Override
public void warn(LogContext ctx, String message) {
msgs.add(message);
}
@Override
public void severe(LogContext ctx, String message) {
msgs.add(message);
}
});
final TreeMap<String, String> link = new TreeMap<>();
link.put(SOURCE_TAXON_NAME, "Donald duck");
link.put(SOURCE_TAXON_PATH, "Aves | Donald | Donald duck");
link.put(SOURCE_TAXON_PATH_NAMES, "class | genus | species");
link.put(SOURCE_TAXON_SPECIFIC_EPITHET, "duck");
link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, InteractType.ATE.getIRI());
link.put(TARGET_OCCURRENCE_ID, "occurrenceId123");
link.put(TARGET_INSTITUTION_CODE, "institutionCode123");
link.put(TARGET_COLLECTION_CODE, "collectionCode123");
link.put(TARGET_COLLECTION_ID, "collectionId123");
link.put(TARGET_CATALOG_NUMBER, "catalogNumber123");
link.put(DATASET_CITATION, "some source ref");
link.put(REFERENCE_ID, "123");
link.put(REFERENCE_CITATION, "");
listener.on(link);
assertThat(msgs, hasItem("target taxon name missing: using institutionCode/collectionCode/collectionId/catalogNumber/occurrenceId as placeholder"));
assertThat(received.size(), is(1));
Map<String, String> receivedInteraction = received.get(0);
assertThat(receivedInteraction.get(TARGET_TAXON_NAME), is("institutionCode123 | collectionCode123 | collectionId123 | catalogNumber123 | occurrenceId123"));
}
Aggregations