Search in sources :

Example 1 with TaxonImage

use of org.eol.globi.domain.TaxonImage in project eol-globi-data by jhpoelen.

the class TaxonUtilTest method toTaxonImage.

@Test
public void toTaxonImage() {
    TaxonImage image = new TaxonImage();
    Taxon taxon = new TaxonImpl("Donald duckus", "EOL:123");
    taxon.setCommonNames("bla @en | boo @de");
    taxon.setPath("one | two | three");
    Map<String, String> taxonMap = new TreeMap<String, String>(TaxonUtil.taxonToMap(taxon));
    taxonMap.put(PropertyAndValueDictionary.THUMBNAIL_URL, "http://foo/bar/thumb");
    taxonMap.put(PropertyAndValueDictionary.EXTERNAL_URL, "http://foo/bar");
    TaxonImage enrichedImage = TaxonUtil.enrichTaxonImageWithTaxon(taxonMap, image);
    assertThat(enrichedImage.getCommonName(), is("bla"));
    assertThat(enrichedImage.getTaxonPath(), is("one | two | three"));
    assertThat(enrichedImage.getInfoURL(), is("http://foo/bar"));
    assertThat(enrichedImage.getThumbnailURL(), is("http://foo/bar/thumb"));
    assertThat(enrichedImage.getPageId(), is("123"));
    assertThat(enrichedImage.getImageURL(), is(nullValue()));
}
Also used : TaxonImage(org.eol.globi.domain.TaxonImage) Taxon(org.eol.globi.domain.Taxon) TaxonImpl(org.eol.globi.domain.TaxonImpl) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 2 with TaxonImage

use of org.eol.globi.domain.TaxonImage in project eol-globi-data by jhpoelen.

the class ImageServiceTest method taxonFoundButNoExternalId.

@Test
public void taxonFoundButNoExternalId() throws IOException {
    imageService.setTaxonSearch(new TaxonSearch() {

        @Override
        public Map<String, String> findTaxon(String scientificName, HttpServletRequest request) throws IOException {
            return new HashMap<String, String>() {

                {
                    put(PropertyAndValueDictionary.EXTERNAL_ID, "no:match");
                    put(PropertyAndValueDictionary.NAME, "some latin name");
                }
            };
        }

        @Override
        public Map<String, String> findTaxonWithImage(String scientificName) throws IOException {
            return null;
        }
    });
    imageService.setImageSearch(new ImageSearch() {

        @Override
        public TaxonImage lookupImageForExternalId(String externalId) {
            return null;
        }
    });
    TaxonImage image = imageService.findTaxonImagesForTaxonWithName("some name");
    assertThat(image.getInfoURL(), is(nullValue()));
    assertThat(image.getScientificName(), is("some latin name"));
    assertThat(image.getCommonName(), is(nullValue()));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ImageSearch(org.eol.globi.service.ImageSearch) TaxonImage(org.eol.globi.domain.TaxonImage) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with TaxonImage

use of org.eol.globi.domain.TaxonImage in project eol-globi-data by jhpoelen.

the class ImageServiceTest method init.

@Before
public void init() {
    imageService = new ImageService();
    imageService.setTaxonSearch(new TaxonSearch() {

        @Override
        public Map<String, String> findTaxon(String scientificName, HttpServletRequest request) throws IOException {
            return new HashMap<String, String>() {

                {
                    put(PropertyAndValueDictionary.EXTERNAL_ID, "EOL:123456");
                }
            };
        }

        @Override
        public Map<String, String> findTaxonWithImage(String scientificName) throws IOException {
            return null;
        }
    });
    imageService.setImageSearch(new ImageSearch() {

        @Override
        public TaxonImage lookupImageForExternalId(String externalId) {
            TaxonImage taxonImage = new TaxonImage();
            taxonImage.setCommonName("some common name for " + externalId);
            return taxonImage;
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ImageSearch(org.eol.globi.service.ImageSearch) TaxonImage(org.eol.globi.domain.TaxonImage) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Example 4 with TaxonImage

use of org.eol.globi.domain.TaxonImage in project eol-globi-data by jhpoelen.

the class EOLTaxonImageServiceIT method imageLookupGBIF.

@Test
public void imageLookupGBIF() throws URISyntaxException, IOException {
    TaxonImage taxonImage = imageService.lookupImageForExternalId("GBIF:7270064");
    assertThat(taxonImage.getPageId(), is(nullValue()));
    assertThat(taxonImage.getThumbnailURL(), is(nullValue()));
    assertThat(taxonImage.getImageURL(), is(nullValue()));
    assertThat(taxonImage.getInfoURL(), is("http://www.gbif.org/species/7270064"));
    assertThat(taxonImage.getScientificName(), is(nullValue()));
    assertThat(taxonImage.getCommonName(), is(nullValue()));
}
Also used : TaxonImage(org.eol.globi.domain.TaxonImage) Test(org.junit.Test)

Example 5 with TaxonImage

use of org.eol.globi.domain.TaxonImage in project eol-globi-data by jhpoelen.

the class EOLTaxonImageServiceIT method imageLookupWoRMSNoEOLPageId.

@Test
public void imageLookupWoRMSNoEOLPageId() throws IOException {
    TaxonImage taxonImage = imageService.lookupImageForExternalId(TaxonomyProvider.ID_PREFIX_WORMS + "585857");
    assertThat(taxonImage.getInfoURL(), notNullValue());
}
Also used : TaxonImage(org.eol.globi.domain.TaxonImage) Test(org.junit.Test)

Aggregations

TaxonImage (org.eol.globi.domain.TaxonImage)12 Test (org.junit.Test)7 IOException (java.io.IOException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Taxon (org.eol.globi.domain.Taxon)3 TaxonImpl (org.eol.globi.domain.TaxonImpl)3 ImageSearch (org.eol.globi.service.ImageSearch)3 TreeMap (java.util.TreeMap)2 EOLTaxonImageService (org.eol.globi.service.EOLTaxonImageService)1 EOLService (org.eol.globi.taxon.EOLService)1 Before (org.junit.Before)1 ExecutionEngine (org.neo4j.cypher.javacompat.ExecutionEngine)1 ExecutionResult (org.neo4j.cypher.javacompat.ExecutionResult)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1