Search in sources :

Example 11 with ResourceService

use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.

the class SparqlClientOpenBiodivFactoryTest method expectNonCaching.

@Test(expected = IOException.class)
public void expectNonCaching() throws IOException {
    final ResourceService resourceService = SparqlClientCachingFactoryTest.singleRequestResourceService();
    final SparqlClient openBiodivClient = new OpenBiodivClientImpl(resourceService);
    DatasetImporterForPensoft.findCitationByDoi("10.3897/zookeys.306.5455", openBiodivClient);
    try {
        DatasetImporterForPensoft.findCitationByDoi("10.3897/zookeys.306.5455", openBiodivClient);
    } catch (IOException ex) {
        assertThat(ex.getCause().getMessage(), is("should not ask twice"));
        throw ex;
    }
}
Also used : SparqlClient(org.globalbioticinteractions.util.SparqlClient) ResourceService(org.eol.globi.service.ResourceService) OpenBiodivClientImpl(org.globalbioticinteractions.util.OpenBiodivClientImpl) IOException(java.io.IOException) Test(org.junit.Test)

Example 12 with ResourceService

use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.

the class InteractTypeMapperFactoryImplTest method createOverrideMappingEmptyMapping.

@Test
public void createOverrideMappingEmptyMapping() throws TermLookupServiceException, IOException {
    ResourceService resourceService = Mockito.mock(ResourceService.class);
    when(resourceService.retrieve(URI.create("interaction_types_ignored.csv"))).thenReturn(IOUtils.toInputStream("interaction_type_ignored\nshouldBeIgnored", StandardCharsets.UTF_8));
    String mapping = "provided_interaction_type_label,provided_interaction_type_id,mapped_to_interaction_type_label,mapped_to_interaction_type_id";
    when(resourceService.retrieve(URI.create("interaction_types_mapping.csv"))).thenReturn(IOUtils.toInputStream(mapping, StandardCharsets.UTF_8));
    InteractTypeMapperFactory interactTypeMapperFactory = new InteractTypeMapperFactoryImpl(resourceService);
    InteractTypeMapper interactTypeMapper = interactTypeMapperFactory.create();
    final InteractType interactType = interactTypeMapper.getInteractType("associated with");
    assertThat(interactType, is(InteractType.INTERACTS_WITH));
}
Also used : InteractType(org.eol.globi.domain.InteractType) ResourceService(org.eol.globi.service.ResourceService) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 13 with ResourceService

use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.

the class InteractTypeMapperFactoryImplTest method createAndIgnoreTermNoMap.

@Test
public void createAndIgnoreTermNoMap() throws TermLookupServiceException, IOException {
    ResourceService resourceService = Mockito.mock(ResourceService.class);
    when(resourceService.retrieve(URI.create("interaction_types_ignored.csv"))).thenReturn(IOUtils.toInputStream("interaction_type_ignored\neats", StandardCharsets.UTF_8)).thenReturn(IOUtils.toInputStream("interaction_type_ignored\neats", StandardCharsets.UTF_8));
    when(resourceService.retrieve(URI.create("interaction_types_mappings.csv"))).thenReturn(null);
    InteractTypeMapperFactoryImpl interactTypeMapperFactory = new InteractTypeMapperFactoryImpl(resourceService);
    InteractTypeMapper interactTypeMapper = interactTypeMapperFactory.create();
    assertThat(interactTypeMapper.getInteractType("eats"), is(nullValue()));
}
Also used : ResourceService(org.eol.globi.service.ResourceService) Test(org.junit.Test)

Example 14 with ResourceService

use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.

the class InteractTypeMapperFactoryImplTest method createMappingWithQuotes2.

@Test
public void createMappingWithQuotes2() throws TermLookupServiceException, IOException {
    ResourceService resourceService = Mockito.mock(ResourceService.class);
    when(resourceService.retrieve(URI.create("interaction_types_ignored.csv"))).thenReturn(IOUtils.toInputStream("interaction_type_ignored\nshouldBeIgnored", StandardCharsets.UTF_8));
    String mapping = "provided_interaction_type_label,provided_interaction_type_id,mapped_to_interaction_type_label,mapped_to_interaction_type_id" + "\nassociates\"\" with\"\",,testing123,http://purl.obolibrary.org/obo/RO_0002437";
    when(resourceService.retrieve(URI.create("interaction_types_mapping.csv"))).thenReturn(IOUtils.toInputStream(mapping, StandardCharsets.UTF_8));
    InteractTypeMapperFactory interactTypeMapperFactory = new InteractTypeMapperFactoryImpl(resourceService);
    InteractTypeMapper interactTypeMapper = interactTypeMapperFactory.create();
    final InteractType interactType = interactTypeMapper.getInteractType("\\\"associates with\\\"");
    assertThat(interactType, is(InteractType.INTERACTS_WITH));
}
Also used : InteractType(org.eol.globi.domain.InteractType) ResourceService(org.eol.globi.service.ResourceService) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 15 with ResourceService

use of org.eol.globi.service.ResourceService in project eol-globi-data by jhpoelen.

the class InteractTypeMapperFactoryImplTest method createOverrideNonBlankMapping.

@Test
public void createOverrideNonBlankMapping() throws TermLookupServiceException, IOException {
    ResourceService resourceService = Mockito.mock(ResourceService.class);
    when(resourceService.retrieve(URI.create("interaction_types_ignored.csv"))).thenReturn(IOUtils.toInputStream("interaction_type_ignored\nshouldBeIgnored", StandardCharsets.UTF_8));
    String mapping = "provided_interaction_type_label,provided_interaction_type_id,mapped_to_interaction_type_label,mapped_to_interaction_type_id\n" + "associated with,,pollinates,http://purl.obolibrary.org/obo/RO_0002455";
    when(resourceService.retrieve(URI.create("interaction_types_mapping.csv"))).thenReturn(IOUtils.toInputStream(mapping, StandardCharsets.UTF_8));
    InteractTypeMapperFactory interactTypeMapperFactory = new InteractTypeMapperFactoryImpl(resourceService);
    InteractTypeMapper mapper = interactTypeMapperFactory.create();
    assertThat(mapper.getInteractType("associated with"), is(InteractType.POLLINATES));
    assertThat(mapper.getInteractType("pollinates"), is(InteractType.POLLINATES));
}
Also used : ResourceService(org.eol.globi.service.ResourceService) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

ResourceService (org.eol.globi.service.ResourceService)34 Test (org.junit.Test)31 IOException (java.io.IOException)9 Matchers.anyString (org.mockito.Matchers.anyString)9 URI (java.net.URI)7 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 InteractType (org.eol.globi.domain.InteractType)3 InteractionListener (org.eol.globi.process.InteractionListener)3 TermLookupService (org.eol.globi.service.TermLookupService)3 DatasetImpl (org.globalbioticinteractions.dataset.DatasetImpl)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 HashMap (java.util.HashMap)2 Term (org.eol.globi.domain.Term)2 TermLookupServiceConfigurationException (org.eol.globi.service.TermLookupServiceConfigurationException)2 TermLookupServiceException (org.eol.globi.service.TermLookupServiceException)2 Dataset (org.globalbioticinteractions.dataset.Dataset)2 OpenBiodivClientImpl (org.globalbioticinteractions.util.OpenBiodivClientImpl)2 SparqlClient (org.globalbioticinteractions.util.SparqlClient)2