Search in sources :

Example 16 with ResourceService

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

the class InteractTypeMapperFactoryImplTest method createDrinkingMapping.

@Test
public void createDrinkingMapping() throws TermLookupServiceException, IOException {
    ResourceService resourceService = Mockito.mock(ResourceService.class);
    when(resourceService.retrieve(URI.create("interaction_types_ignored.csv"))).thenReturn(null);
    String mapping = "provided_interaction_type_label,provided_interaction_type_id,mapped_to_interaction_type_label,mapped_to_interaction_type_id\n" + "drinking,http://purl.obolibrary.org/obo/OMIT_0005582,eats,http://purl.obolibrary.org/obo/RO_0002470\n";
    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();
    assertThat(interactTypeMapper.getInteractType("http://purl.obolibrary.org/obo/OMIT_0005582"), is(InteractType.ATE));
    assertThat(interactTypeMapper.getInteractType("drinking"), is(InteractType.ATE));
}
Also used : ResourceService(org.eol.globi.service.ResourceService) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 17 with ResourceService

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

the class InteractTypeMapperFactoryImplTest method createInvalidTypeMape.

@Test()
public void createInvalidTypeMape() throws TermLookupServiceException, IOException {
    // reproduce https://github.com/qgroom/Vespa-velutina/issues/3
    ResourceService resourceService = Mockito.mock(ResourceService.class);
    when(resourceService.retrieve(URI.create("interaction_types_mapping.csv"))).thenReturn(IOUtils.toInputStream("provided_interaction_type_label,provided_interaction_type_id,mapped_to_interaction_type_label,mapped_to_interaction_type_id\n" + "stings,,participates in a biotic-biotic interaction with,http://purl.obolibrary.org/obo/RO_0002574\n" + "reproductively interferes with,,participates in a biotic-biotic interaction with,http://purl.obolibrary.org/obo/RO_0002574\n", StandardCharsets.UTF_8));
    InteractTypeMapperFactoryImpl interactTypeMapperFactory = new InteractTypeMapperFactoryImpl(resourceService);
    InteractTypeMapper interactTypeMapper = interactTypeMapperFactory.create();
    assertThat(interactTypeMapper.getInteractType("stings"), is(InteractType.INTERACTS_WITH));
}
Also used : ResourceService(org.eol.globi.service.ResourceService) Test(org.junit.Test)

Example 18 with ResourceService

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

the class InteractTypeMapperFactoryImpl method getResourceServiceForDefaultInteractionTypeMapping.

public static ResourceService getResourceServiceForDefaultInteractionTypeMapping(ResourceService service) {
    return new ResourceService() {

        @Override
        public InputStream retrieve(URI resourceName) throws IOException {
            URI supportedURI = getSupportedURI(resourceName);
            return supportedURI == null || service == null ? null : service.retrieve(supportedURI);
        }

        URI getSupportedURI(URI resourceName) {
            List<URI> supportedResources = Arrays.asList(TYPE_IGNORED_URI_DEFAULT, TYPE_MAP_URI_DEFAULT);
            URI resource = URI.create("classpath:/org/globalbioticinteractions/" + resourceName);
            return supportedResources.contains(resourceName) ? resource : null;
        }
    };
}
Also used : ResourceService(org.eol.globi.service.ResourceService) URI(java.net.URI)

Example 19 with ResourceService

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

the class InteractionListenerImplTest method processMessageWithTranslatedInteractionType.

@Test
public void processMessageWithTranslatedInteractionType() throws StudyImporterException, IOException {
    ResourceService resourceService = Mockito.mock(ResourceService.class);
    when(resourceService.retrieve(URI.create("interaction_types_ignored.csv"))).thenReturn(IOUtils.toInputStream("provided_interaction_type_id\nshouldBeIgnored", StandardCharsets.UTF_8)).thenReturn(IOUtils.toInputStream("provided_interaction_type_id\nshouldBeIgnored", StandardCharsets.UTF_8));
    when(resourceService.retrieve(URI.create("interaction_types_mapping.csv"))).thenReturn(IOUtils.toInputStream(getTestMap(), StandardCharsets.UTF_8));
    Dataset dataset = new DatasetImpl("bla", resourceService, URI.create("foo:bar"));
    InteractionListenerImpl interactionListener = new InteractionListenerImpl(nodeFactory, null, null, dataset);
    HashMap<String, String> interaction = new HashMap<>();
    interaction.put(SOURCE_TAXON_NAME, "sourceName");
    interaction.put(DatasetImporterForTSV.INTERACTION_TYPE_NAME, "shouldBeMapped");
    interaction.put(TARGET_TAXON_NAME, "targetName");
    interaction.put(REFERENCE_ID, "citation");
    assertStudyCount(0L);
    interactionListener.on(interaction);
    assertStudyCount(1L);
}
Also used : HashMap(java.util.HashMap) Dataset(org.globalbioticinteractions.dataset.Dataset) ResourceService(org.eol.globi.service.ResourceService) DatasetImpl(org.globalbioticinteractions.dataset.DatasetImpl) Test(org.junit.Test)

Example 20 with ResourceService

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

the class SparqlClientCachingFactoryTest method expectCaching.

@Test
public void expectCaching() throws IOException {
    final ResourceService resourceService = singleRequestResourceService();
    final SparqlClient openBiodivClient = new SparqlClientCachingFactory().create(resourceService);
    assertCitation(openBiodivClient);
    assertCitation(openBiodivClient);
}
Also used : SparqlClient(org.globalbioticinteractions.util.SparqlClient) ResourceService(org.eol.globi.service.ResourceService) 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