Search in sources :

Example 1 with BioSamplesClient

use of uk.ac.ebi.biosamples.client.BioSamplesClient in project biosamples-v4 by EBIBioSamples.

the class NcbiElementCallableTest method should_extract_double_organism_if_organism_is_in_description_with_null_amr_map.

@Test
public void should_extract_double_organism_if_organism_is_in_description_with_null_amr_map() throws Exception {
    ArgumentCaptor<Sample> generatedSample = ArgumentCaptor.forClass(Sample.class);
    when(bioSamplesClient.persistSampleResource(generatedSample.capture())).thenReturn(null);
    NcbiSampleConversionService ncbiSampleConversionService = new NcbiSampleConversionService(taxonService);
    NcbiElementCallable callable = new NcbiElementCallable(ncbiSampleConversionService, bioSamplesClient, sample, "test", null);
    callable.call();
    Sample sample = generatedSample.getValue();
    List<Attribute> organisms = sample.getAttributes().stream().filter(attr -> attr.getType().equalsIgnoreCase("organism")).collect(Collectors.toList());
    assertThat(organisms).hasSize(2);
    assertThat(organisms.stream().anyMatch(organism -> organism.getValue().equals("Oryza sativa Japonica Group")));
    assertThat(organisms.stream().anyMatch(organism -> organism.getValue().equals("Oryza sativa")));
}
Also used : Sample(uk.ac.ebi.biosamples.model.Sample) Java6Assertions.assertThat(org.assertj.core.api.Java6Assertions.assertThat) BioSamplesClient(uk.ac.ebi.biosamples.client.BioSamplesClient) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Test(org.junit.Test) ActiveProfiles(org.springframework.test.context.ActiveProfiles) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) List(java.util.List) ArgumentCaptor(org.mockito.ArgumentCaptor) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) TaxonomyService(uk.ac.ebi.biosamples.utils.TaxonomyService) XmlPathBuilder(uk.ac.ebi.biosamples.utils.XmlPathBuilder) Attribute(uk.ac.ebi.biosamples.model.Attribute) Element(org.dom4j.Element) SpringRunner(org.springframework.test.context.junit4.SpringRunner) NcbiSampleConversionService(uk.ac.ebi.biosamples.ncbi.service.NcbiSampleConversionService) Before(org.junit.Before) MockBean(org.springframework.boot.test.mock.mockito.MockBean) Attribute(uk.ac.ebi.biosamples.model.Attribute) Sample(uk.ac.ebi.biosamples.model.Sample) NcbiSampleConversionService(uk.ac.ebi.biosamples.ncbi.service.NcbiSampleConversionService) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with BioSamplesClient

use of uk.ac.ebi.biosamples.client.BioSamplesClient in project biosamples-v4 by EBIBioSamples.

the class NcbiElementCallableTest method should_extract_double_organism_if_organism_is_in_description.

@Test
public void should_extract_double_organism_if_organism_is_in_description() throws Exception {
    ArgumentCaptor<Sample> generatedSample = ArgumentCaptor.forClass(Sample.class);
    when(bioSamplesClient.persistSampleResource(generatedSample.capture())).thenReturn(null);
    NcbiSampleConversionService ncbiSampleConversionService = new NcbiSampleConversionService(taxonService);
    NcbiElementCallable callable = new NcbiElementCallable(ncbiSampleConversionService, bioSamplesClient, sample, "test", new HashMap<>());
    callable.call();
    Sample sample = generatedSample.getValue();
    List<Attribute> organisms = sample.getAttributes().stream().filter(attr -> attr.getType().equalsIgnoreCase("organism")).collect(Collectors.toList());
    assertThat(organisms).hasSize(2);
    assertThat(organisms.stream().anyMatch(organism -> organism.getValue().equals("Oryza sativa Japonica Group")));
    assertThat(organisms.stream().anyMatch(organism -> organism.getValue().equals("Oryza sativa")));
}
Also used : Sample(uk.ac.ebi.biosamples.model.Sample) Java6Assertions.assertThat(org.assertj.core.api.Java6Assertions.assertThat) BioSamplesClient(uk.ac.ebi.biosamples.client.BioSamplesClient) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Test(org.junit.Test) ActiveProfiles(org.springframework.test.context.ActiveProfiles) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) List(java.util.List) ArgumentCaptor(org.mockito.ArgumentCaptor) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) TaxonomyService(uk.ac.ebi.biosamples.utils.TaxonomyService) XmlPathBuilder(uk.ac.ebi.biosamples.utils.XmlPathBuilder) Attribute(uk.ac.ebi.biosamples.model.Attribute) Element(org.dom4j.Element) SpringRunner(org.springframework.test.context.junit4.SpringRunner) NcbiSampleConversionService(uk.ac.ebi.biosamples.ncbi.service.NcbiSampleConversionService) Before(org.junit.Before) MockBean(org.springframework.boot.test.mock.mockito.MockBean) Attribute(uk.ac.ebi.biosamples.model.Attribute) Sample(uk.ac.ebi.biosamples.model.Sample) NcbiSampleConversionService(uk.ac.ebi.biosamples.ncbi.service.NcbiSampleConversionService) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Java6Assertions.assertThat (org.assertj.core.api.Java6Assertions.assertThat)2 Element (org.dom4j.Element)2 Before (org.junit.Before)2 Test (org.junit.Test)2 RunWith (org.junit.runner.RunWith)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 Mockito.when (org.mockito.Mockito.when)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MockBean (org.springframework.boot.test.mock.mockito.MockBean)2 ActiveProfiles (org.springframework.test.context.ActiveProfiles)2 SpringRunner (org.springframework.test.context.junit4.SpringRunner)2 BioSamplesClient (uk.ac.ebi.biosamples.client.BioSamplesClient)2 Attribute (uk.ac.ebi.biosamples.model.Attribute)2 Sample (uk.ac.ebi.biosamples.model.Sample)2 NcbiSampleConversionService (uk.ac.ebi.biosamples.ncbi.service.NcbiSampleConversionService)2 TaxonomyService (uk.ac.ebi.biosamples.utils.TaxonomyService)2 XmlPathBuilder (uk.ac.ebi.biosamples.utils.XmlPathBuilder)2