Search in sources :

Example 81 with DatasetImpl

use of org.globalbioticinteractions.dataset.DatasetImpl in project eol-globi-data by jhpoelen.

the class TableInteractionListenerProxyTest method interactionListenerTest.

@Test
public void interactionListenerTest() throws IOException, StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<Map<String, String>>();
    JsonNode config = new ObjectMapper().readTree("{ \"dcterms:bibliographicCitation\":\"some citation\", \"url\":\"https://example.org/someResource\" }");
    DatasetImpl dataset = new DatasetImpl(null, URI.create("http://someurl"), inStream -> inStream);
    dataset.setConfig(config);
    final TableInteractionListenerProxy listener = new TableInteractionListenerProxy(dataset, new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            links.add(interaction);
        }
    });
    listener.on(new HashMap<>());
    assertThat(links.size(), is(1));
    assertThat(links.get(0).get(DatasetImporterForTSV.DATASET_CITATION), startsWith("some citation. Accessed at <https://example.org/someResource> on "));
    assertThat(links.get(0).get(DatasetImporterForTSV.REFERENCE_CITATION), startsWith("some citation. Accessed at <https://example.org/someResource> on "));
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) InteractionListener(org.eol.globi.process.InteractionListener) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 82 with DatasetImpl

use of org.globalbioticinteractions.dataset.DatasetImpl in project eol-globi-data by jhpoelen.

the class TableInteractionListenerProxyTest method interactionListener2Test.

@Test
public void interactionListener2Test() throws IOException, StudyImporterException {
    final List<Map<String, String>> links = new ArrayList<Map<String, String>>();
    JsonNode config = new ObjectMapper().readTree("{ \"dcterms:bibliographicCitation\":\"some citation\", \"url\":\"https://example.org/someResource\" }");
    DatasetImpl dataset = new DatasetImpl(null, URI.create("http://someurl"), inStream -> inStream);
    dataset.setConfig(config);
    final TableInteractionListenerProxy listener = new TableInteractionListenerProxy(dataset, new InteractionListener() {

        @Override
        public void on(Map<String, String> interaction) throws StudyImporterException {
            links.add(interaction);
        }
    });
    listener.on(new HashMap<String, String>() {

        {
            put(DatasetImporterForTSV.REFERENCE_CITATION, "some ref");
        }
    });
    assertThat(links.size(), is(1));
    assertThat(links.get(0).get(DatasetImporterForTSV.DATASET_CITATION), startsWith("some citation. Accessed at <https://example.org/someResource> on "));
    assertThat(links.get(0).get(DatasetImporterForTSV.REFERENCE_CITATION), startsWith("some ref"));
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) InteractionListener(org.eol.globi.process.InteractionListener) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 83 with DatasetImpl

use of org.globalbioticinteractions.dataset.DatasetImpl in project eol-globi-data by jhpoelen.

the class DatasetTest method unknownResourceURL.

@Test(expected = IOException.class)
public void unknownResourceURL() throws IOException, URISyntaxException {
    URL resource = getClass().getResource("archive.zip");
    File archive = new File(resource.toURI());
    assertThat(archive.exists(), is(true));
    URI parentDir = archive.getParentFile().toURI();
    Dataset dataset = new DatasetImpl("some/namespace", parentDir, inStream -> inStream);
    assertThat(dataset.retrieve(URI.create("archivezz.zip")), is(notNullValue()));
}
Also used : Dataset(org.globalbioticinteractions.dataset.Dataset) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) File(java.io.File) URI(java.net.URI) URL(java.net.URL) Test(org.junit.Test)

Aggregations

DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)83 Test (org.junit.Test)73 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)50 URI (java.net.URI)32 JsonNode (com.fasterxml.jackson.databind.JsonNode)31 Dataset (org.globalbioticinteractions.dataset.Dataset)25 ArrayList (java.util.ArrayList)22 IOException (java.io.IOException)21 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)21 InteractionListener (org.eol.globi.process.InteractionListener)19 URL (java.net.URL)18 Map (java.util.Map)17 StudyNode (org.eol.globi.domain.StudyNode)17 HashMap (java.util.HashMap)16 Is.is (org.hamcrest.core.Is.is)16 List (java.util.List)15 StudyImpl (org.eol.globi.domain.StudyImpl)15 StringUtils (org.apache.commons.lang3.StringUtils)14 CoreMatchers.nullValue (org.hamcrest.CoreMatchers.nullValue)14 Is (org.hamcrest.core.Is)14