Search in sources :

Example 1 with InteractionListenerResolving

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"));
}
Also used : ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) TreeMap(java.util.TreeMap) URI(java.net.URI) InteractionListener(org.eol.globi.process.InteractionListener) InteractionListenerResolving(org.eol.globi.util.InteractionListenerResolving) Map(java.util.Map) TreeMap(java.util.TreeMap) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Example 2 with InteractionListenerResolving

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"));
}
Also used : ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) TreeMap(java.util.TreeMap) URI(java.net.URI) InteractionListener(org.eol.globi.process.InteractionListener) InteractionListenerResolving(org.eol.globi.util.InteractionListenerResolving) Map(java.util.Map) TreeMap(java.util.TreeMap) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Aggregations

LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)2 IOException (java.io.IOException)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Pair (org.apache.commons.lang3.tuple.Pair)2 InteractionListener (org.eol.globi.process.InteractionListener)2 InteractionListenerResolving (org.eol.globi.util.InteractionListenerResolving)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2