use of org.eol.globi.util.InteractionListenerResolving in project eol-globi-data by jhpoelen.
the class DatasetImporterForRSSTest method enrichingInteractionListener.
@Test
public void enrichingInteractionListener() throws StudyImporterException {
DatasetImporterWithListener studyImporter = new DatasetImporterWithListener(new ParserFactory() {
@Override
public LabeledCSVParser createParser(URI studyResource, String characterEncoding) throws IOException {
return null;
}
}, new NodeFactoryNull()) {
@Override
public void importStudy() throws StudyImporterException {
//
}
};
final List<Map<String, String>> receivedLinks = new ArrayList<>();
studyImporter.setInteractionListener(new InteractionListener() {
@Override
public void on(Map<String, String> interaction) throws StudyImporterException {
receivedLinks.add(interaction);
}
});
TreeMap<Pair<String, String>, Map<String, String>> interactionsWithUnresolvedOccurrenceIds = new TreeMap<Pair<String, String>, Map<String, String>>() {
{
put(Pair.of(DatasetImporterForTSV.TARGET_OCCURRENCE_ID, "1234"), new TreeMap<String, String>() {
{
put(DatasetImporterForTSV.TARGET_OCCURRENCE_ID, "1234");
put(DatasetImporterForTSV.TARGET_LIFE_STAGE_NAME, "lifeStageName");
put(DatasetImporterForTSV.TARGET_LIFE_STAGE_ID, "lifeStageId");
put(DatasetImporterForTSV.TARGET_BODY_PART_NAME, "bodyPartName");
put(DatasetImporterForTSV.TARGET_BODY_PART_ID, "bodyPartId");
put(TaxonUtil.TARGET_TAXON_NAME, "taxonName");
put(TaxonUtil.TARGET_TAXON_ID, "taxonId");
}
});
}
};
InteractionListenerResolving listener = new InteractionListenerResolving(interactionsWithUnresolvedOccurrenceIds, studyImporter.getInteractionListener());
listener.on(new TreeMap<String, String>() {
{
put(DatasetImporterForTSV.TARGET_OCCURRENCE_ID, "1234");
}
});
assertThat(receivedLinks.size(), is(1));
Map<String, String> received = receivedLinks.get(0);
assertThat(received.get(TaxonUtil.TARGET_TAXON_NAME), is("taxonName"));
assertThat(received.get(TaxonUtil.TARGET_TAXON_ID), is("taxonId"));
assertThat(received.get(DatasetImporterForTSV.TARGET_BODY_PART_NAME), is("bodyPartName"));
assertThat(received.get(DatasetImporterForTSV.TARGET_BODY_PART_ID), is("bodyPartId"));
assertThat(received.get(DatasetImporterForTSV.TARGET_LIFE_STAGE_NAME), is("lifeStageName"));
assertThat(received.get(DatasetImporterForTSV.TARGET_LIFE_STAGE_ID), is("lifeStageId"));
}
use of org.eol.globi.util.InteractionListenerResolving in project eol-globi-data by jhpoelen.
the class DatasetImporterForRSSTest method enrichingInteractionListenerSourceOccurrence.
@Test()
public void enrichingInteractionListenerSourceOccurrence() throws StudyImporterException {
DatasetImporterWithListener studyImporter = new DatasetImporterWithListener(new ParserFactory() {
@Override
public LabeledCSVParser createParser(URI studyResource, String characterEncoding) throws IOException {
return null;
}
}, new NodeFactoryNull()) {
@Override
public void importStudy() throws StudyImporterException {
//
}
};
final List<Map<String, String>> receivedLinks = new ArrayList<>();
studyImporter.setInteractionListener(new InteractionListener() {
@Override
public void on(Map<String, String> interaction) throws StudyImporterException {
receivedLinks.add(interaction);
}
});
TreeMap<Pair<String, String>, Map<String, String>> interactionsWithUnresolvedOccurrenceIds = new TreeMap<Pair<String, String>, Map<String, String>>() {
{
put(Pair.of(DatasetImporterForTSV.TARGET_OCCURRENCE_ID, "1234"), new TreeMap<String, String>() {
{
put(DatasetImporterForTSV.TARGET_OCCURRENCE_ID, "1234");
put(DatasetImporterForTSV.TARGET_LIFE_STAGE_NAME, "lifeStageName");
put(DatasetImporterForTSV.TARGET_LIFE_STAGE_ID, "lifeStageId");
put(DatasetImporterForTSV.TARGET_BODY_PART_NAME, "bodyPartName");
put(DatasetImporterForTSV.TARGET_BODY_PART_ID, "bodyPartId");
put(TaxonUtil.TARGET_TAXON_NAME, "taxonName");
put(TaxonUtil.TARGET_TAXON_ID, "taxonId");
}
});
}
};
InteractionListenerResolving listener = new InteractionListenerResolving(interactionsWithUnresolvedOccurrenceIds, studyImporter.getInteractionListener());
listener.on(new TreeMap<String, String>() {
{
put(DatasetImporterForTSV.SOURCE_OCCURRENCE_ID, "4567");
put(DatasetImporterForTSV.TARGET_OCCURRENCE_ID, "1234");
}
});
assertThat(receivedLinks.size(), is(1));
Map<String, String> received = receivedLinks.get(0);
assertThat(received.get(DatasetImporterForTSV.SOURCE_OCCURRENCE_ID), is("4567"));
assertThat(received.get(TaxonUtil.TARGET_TAXON_NAME), is("taxonName"));
assertThat(received.get(TaxonUtil.TARGET_TAXON_ID), is("taxonId"));
assertThat(received.get(DatasetImporterForTSV.TARGET_OCCURRENCE_ID), is("1234"));
assertThat(received.get(DatasetImporterForTSV.TARGET_BODY_PART_NAME), is("bodyPartName"));
assertThat(received.get(DatasetImporterForTSV.TARGET_BODY_PART_ID), is("bodyPartId"));
assertThat(received.get(DatasetImporterForTSV.TARGET_LIFE_STAGE_NAME), is("lifeStageName"));
assertThat(received.get(DatasetImporterForTSV.TARGET_LIFE_STAGE_ID), is("lifeStageId"));
}
Aggregations