From d61a12a333e16183fa958e60b053da0135d75e38 Mon Sep 17 00:00:00 2001 From: Jorrit Poelen Date: Thu, 4 Apr 2024 18:25:59 -0500 Subject: [PATCH] refactor/add integration tests; related to https://github.com/globalbioticinteractions/nomer/issues/161 --- .../org/eol/globi/taxon/DiscoverLifeUtil.java | 18 +- .../eol/globi/taxon/DiscoverLifeUtil2.java | 169 ++++++++++++++++++ .../DiscoverLifeUtil2IntegrationTest.java | 40 +++++ .../globi/taxon/DiscoverLifeUtil2Test.java | 158 +--------------- .../DiscoverLifeUtilIntegrationTest.java | 78 ++++++++ .../eol/globi/taxon/DiscoverLifeUtilTest.java | 53 ------ 6 files changed, 300 insertions(+), 216 deletions(-) create mode 100644 nomer-taxon-resolver/src/main/java/org/eol/globi/taxon/DiscoverLifeUtil2.java create mode 100644 nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtil2IntegrationTest.java create mode 100644 nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtilIntegrationTest.java diff --git a/nomer-taxon-resolver/src/main/java/org/eol/globi/taxon/DiscoverLifeUtil.java b/nomer-taxon-resolver/src/main/java/org/eol/globi/taxon/DiscoverLifeUtil.java index c5417259..9533608b 100644 --- a/nomer-taxon-resolver/src/main/java/org/eol/globi/taxon/DiscoverLifeUtil.java +++ b/nomer-taxon-resolver/src/main/java/org/eol/globi/taxon/DiscoverLifeUtil.java @@ -65,7 +65,7 @@ static void parseNames(Node familyNameNode, Node nameNodeCandidate, TermMatchLis if (StringUtils.equals("i", currentNode.getNodeName())) { Map taxonMap = new TreeMap<>(); - String taxonName = trimNameNodeTextContent(nameNodeCandidate); + String taxonName = trimNameNodeTextContent(nameNodeCandidate.getTextContent()); taxonMap.put(PropertyAndValueDictionary.NAME, taxonName); Node expectedTextNode = currentNode.getNextSibling(); @@ -135,7 +135,8 @@ private static void handleRelatedNames( Map relatedName = new TreeMap<>(); - String authorshipString = enrichFromNameString(currentNode, relatedName); + Node authorshipNodeCandidate = currentNode.getNextSibling(); + String authorshipString = enrichFromNameString(relatedName, currentNode.getTextContent(), authorshipNodeCandidate == null ? null : authorshipNodeCandidate.getTextContent()); currentNode = currentNode.getNextSibling(); @@ -251,13 +252,12 @@ private static void enrichFromAuthorString(String authorshipString, Map relatedName) { - String altName = trimNameNodeTextContent(currentNode); + private static String enrichFromNameString(Map relatedName, String altNameText, String authorshipText) { + String altName = trimNameNodeTextContent(altNameText); String authorship = null; - Node authorshipNode = currentNode.getNextSibling(); - if (authorshipNode != null) { - authorship = StringUtils.trim(authorshipNode.getTextContent()); + if (StringUtils.isNotBlank(authorshipText)) { + authorship = StringUtils.trim(authorshipText); if (StringUtils.startsWith(authorship, ",")) { authorship = StringUtils.trim(authorship.substring(1)); } @@ -275,9 +275,9 @@ private static String enrichFromNameString(Node currentNode, Map return authorship; } - private static String trimNameNodeTextContent(Node currentNode) { + private static String trimNameNodeTextContent(String textContent) { return StringUtils.replace( - StringUtils.trim(currentNode.getTextContent()), + StringUtils.trim(textContent), "_sic", ""); } diff --git a/nomer-taxon-resolver/src/main/java/org/eol/globi/taxon/DiscoverLifeUtil2.java b/nomer-taxon-resolver/src/main/java/org/eol/globi/taxon/DiscoverLifeUtil2.java new file mode 100644 index 00000000..f449b120 --- /dev/null +++ b/nomer-taxon-resolver/src/main/java/org/eol/globi/taxon/DiscoverLifeUtil2.java @@ -0,0 +1,169 @@ +package org.eol.globi.taxon; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.eol.globi.data.CharsetConstant; +import org.eol.globi.domain.NameType; +import org.eol.globi.domain.PropertyAndValueDictionary; +import org.eol.globi.service.TaxonUtil; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Scanner; +import java.util.TreeMap; +import java.util.function.Consumer; + +import static org.eol.globi.service.TaxonUtil.generateTaxonPathNames; + +public class DiscoverLifeUtil2 { + + public static final List RANKS = Arrays.asList("Family", "Subfamily", "Tribe", "Subtribe", "Genus", "Subgenus"); + + public static void splitRecords(InputStream is, Consumer lineConsumer) { + Scanner scanner = new Scanner(is, StandardCharsets.UTF_8.name()); + while (scanner.hasNext()) { + String record = nextRecord(scanner); + if (StringUtils.isNotBlank(record)) { + lineConsumer.accept(record); + } + } + } + + public static String nextRecord(Scanner scanner) { + String record = null; + scanner.useDelimiter("__START__"); + scanner.next(); + if (scanner.hasNext()) { + scanner.useDelimiter("\n() { + @Override + public void accept(String recordXml) { + try { + // escape unescaped ampersands + String scrubbedXml = StringUtils.replace(recordXml, " & ", " & "); + Document doc = builder.parse(IOUtils.toInputStream(scrubbedXml, StandardCharsets.UTF_8)); + Map nameMap = parseFocalTaxon(doc); + listener.foundTaxonForTerm( + null, + TaxonUtil.mapToTaxon(nameMap), + NameType.HAS_ACCEPTED_NAME, + TaxonUtil.mapToTaxon(nameMap) + ); + + } catch (SAXException | IOException | XPathExpressionException e) { + try { + IOUtils.copy(IOUtils.toInputStream(recordXml, StandardCharsets.UTF_8), System.err); + } catch (IOException e1) { + // + } + throw new RuntimeException("failed to parse DiscoverLife record [" + recordXml + "]", e); + } + + } + }); + } + + static Map parseFocalTaxon(Document doc) throws XPathExpressionException { + Map nameMap = new TreeMap() {{ + put("kingdom", "Animalia"); + put("phylum", "Arthropoda"); + put("class", "Insecta"); + put("order", "Hymenoptera"); + put("superfamily", "Apoidea"); + }}; + + Node setNode = (Node) XmlUtil.applyXPath(doc, "set", XPathConstants.NODE); + + + putTextValueForElement(nameMap, setNode, "name", PropertyAndValueDictionary.NAME); + putTextValueForElement(nameMap, setNode, "authority", PropertyAndValueDictionary.AUTHORSHIP); + + Node level = setNode.getAttributes().getNamedItem("level"); + String taxonomicRank = level == null ? null : level.getTextContent(); + nameMap.put(PropertyAndValueDictionary.RANK, taxonomicRank); + nameMap.put(taxonomicRank, nameMap.get(PropertyAndValueDictionary.NAME)); + + + NodeList attr = (NodeList) XmlUtil.applyXPath(setNode, "//attributes", XPathConstants.NODESET); + + if (attr != null && attr.getLength() > 0) { + + NodeList childNodes = attr.item(0).getChildNodes(); + + String keyCurrent = ""; + ObjectNode objectNode = new ObjectMapper().createObjectNode(); + ArrayNode valuesCurrent = new ObjectMapper().createArrayNode(); + + for (int i = 0; i < childNodes.getLength(); i++) { + Node childNode = childNodes.item(i); + String key = childNode.getNodeName(); + if (StringUtils.equals("character", key)) { + keyCurrent = childNode.getTextContent(); + valuesCurrent = new ObjectMapper().createArrayNode(); + } else if (StringUtils.equals("state", key)) { + if (StringUtils.isNotBlank(keyCurrent)) { + valuesCurrent.add(childNode.getTextContent()); + if (valuesCurrent.size() > 0 && objectNode != null) { + if (RANKS.contains(keyCurrent)) { + nameMap.put(StringUtils.lowerCase(keyCurrent), valuesCurrent.get(0).asText()); + } + } + } + } + } + + String pathNames = generateTaxonPathNames(nameMap, Arrays.asList("kingdom", "phylum", "class", "order", "family", "subfamily", "tribe", "subtribe", "genus", "subgenus", "subspecies"), "", "genus", "specificEpithet", "subspecificEpithet", "species"); + + nameMap.put(PropertyAndValueDictionary.PATH_NAMES, pathNames); + + String[] ranks = StringUtils.splitByWholeSeparator(pathNames, CharsetConstant.SEPARATOR); + List path = new ArrayList<>(); + + for (String rank : ranks) { + path.add(nameMap.get(rank)); + } + + String pathString = StringUtils.join(path, CharsetConstant.SEPARATOR); + nameMap.put(PropertyAndValueDictionary.PATH, pathString); + } + return nameMap; + } + + private static void putTextValueForElement(Map nameMap, Node setNode, String sourceElementName, String targetName) throws XPathExpressionException { + Node nameNode = (Node) XmlUtil.applyXPath(setNode, sourceElementName, XPathConstants.NODE); + if (nameNode != null) { + nameMap.put(targetName, nameNode.getTextContent()); + } + } +} diff --git a/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtil2IntegrationTest.java b/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtil2IntegrationTest.java new file mode 100644 index 00000000..51edbfea --- /dev/null +++ b/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtil2IntegrationTest.java @@ -0,0 +1,40 @@ +package org.eol.globi.taxon; + +import org.eol.globi.domain.NameType; +import org.eol.globi.domain.Taxon; +import org.eol.globi.domain.Term; +import org.hamcrest.core.Is; +import org.junit.Test; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.zip.GZIPInputStream; + +import static org.hamcrest.MatcherAssert.assertThat; + +public class DiscoverLifeUtil2IntegrationTest { + + public static final String BEES_XML_GZIP = "/org/globalbioticinteractions/nomer/match/discoverlife/bees.xml.gz"; + + @Test + public void compareLocalVersionToRemoteVersion() throws IOException { + DiscoverLifeTestUtil.compareLocalVersionToRemoteVersion( + BEES_XML_GZIP, + DiscoverLifeUtil.URL_ENDPOINT_DISCOVER_LIFE + "/nh/id/20q/Apoidea_species.xml" + ); + } + + @Test + public void parseNames() throws ParserConfigurationException, IOException { + AtomicInteger counter = new AtomicInteger(0); + DiscoverLifeUtil2.parse(new GZIPInputStream(getClass().getResourceAsStream(BEES_XML_GZIP)), new TermMatchListener() { + @Override + public void foundTaxonForTerm(Long requestId, Term providedTerm, NameType nameType, Taxon resolvedTaxon) { + counter.incrementAndGet(); + } + }); + assertThat(counter.get(), Is.is(20932)); + } + +} \ No newline at end of file diff --git a/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtil2Test.java b/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtil2Test.java index c61fca24..69ac189d 100644 --- a/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtil2Test.java +++ b/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtil2Test.java @@ -1,38 +1,24 @@ package org.eol.globi.taxon; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Triple; -import org.eol.globi.data.CharsetConstant; import org.eol.globi.domain.NameType; -import org.eol.globi.domain.PropertyAndValueDictionary; import org.eol.globi.domain.Taxon; import org.eol.globi.domain.Term; import org.eol.globi.service.TaxonUtil; import org.junit.Test; import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; -import java.util.Scanner; -import java.util.TreeMap; -import java.util.function.Consumer; import static org.eol.globi.service.TaxonUtil.generateTaxonPathNames; import static org.hamcrest.CoreMatchers.is; @@ -40,22 +26,11 @@ public class DiscoverLifeUtil2Test { - public static final List RANKS = Arrays.asList("Family", "Subfamily", "Tribe", "Subtribe", "Genus", "Subgenus"); - - @Test - public void compareLocalVersionToRemoteVersion() throws IOException { - DiscoverLifeTestUtil.compareLocalVersionToRemoteVersion( - "/org/globalbioticinteractions/nomer/match/discoverlife/bees.xml.gz", - DiscoverLifeUtil.URL_ENDPOINT_DISCOVER_LIFE + "/nh/id/20q/Apoidea_species.xml" - ); - } - - @Test public void parseXMLRecord() throws ParserConfigurationException, XPathExpressionException, IOException, SAXException { Document doc = docForResource("/org/globalbioticinteractions/nomer/match/discoverlife/agapostemon_texanus.xml"); - Map nameMap = parseFocalTaxon(doc); + Map nameMap = DiscoverLifeUtil2.parseFocalTaxon(doc); Taxon taxon = TaxonUtil.mapToTaxon(nameMap); assertThat(taxon.getName(), is("Agapostemon texanus")); @@ -76,7 +51,7 @@ private Document docForResource(String resourcePath) throws SAXException, IOExce public void parseAcamptopoeum_melanogaster() throws ParserConfigurationException, XPathExpressionException, IOException, SAXException { Document doc = docForResource("/org/globalbioticinteractions/nomer/match/discoverlife/record_Acamptopoeum_melanogaster.xml"); - Map nameMap = parseFocalTaxon(doc); + Map nameMap = DiscoverLifeUtil2.parseFocalTaxon(doc); Taxon taxon = TaxonUtil.mapToTaxon(nameMap); assertThat(taxon.getName(), is("Acamptopoeum melanogaster")); @@ -92,7 +67,7 @@ public void splitRecords() throws IOException { List records = new ArrayList<>(); - splitRecords(is, records::add); + DiscoverLifeUtil2.splitRecords(is, records::add); assertThat(records.get(0), is(IOUtils.toString(getClass().getResourceAsStream("/org/globalbioticinteractions/nomer/match/discoverlife/record_Adrenidae.xml"), StandardCharsets.UTF_8))); assertThat(records.get(records.size() - 1), is(IOUtils.toString(getClass().getResourceAsStream("/org/globalbioticinteractions/nomer/match/discoverlife/record_Acamptopoeum_melanogaster.xml"), StandardCharsets.UTF_8))); } @@ -103,7 +78,7 @@ public void parseRecords() throws IOException, XPathExpressionException, SAXExce List> records = new ArrayList<>(); - parse(is, new TermMatchListener() { + DiscoverLifeUtil2.parse(is, new TermMatchListener() { @Override public void foundTaxonForTerm(Long requestId, Term providedTerm, NameType nameType, Taxon resolvedTaxon) { records.add(Triple.of(providedTerm, nameType, resolvedTaxon)); @@ -124,130 +99,5 @@ public void foundTaxonForTerm(Long requestId, Term providedTerm, NameType nameTy assertThat(records.get(12).getRight().getPath(), is("Animalia | Arthropoda | Insecta | Hymenoptera | Andrenidae | Panurginae | Calliopsini | None | Acamptopoeum | None | Acamptopoeum melanogaster")); } - private void splitRecords(InputStream is, Consumer lineConsumer) { - Scanner scanner = new Scanner(is, StandardCharsets.UTF_8.name()); - while (scanner.hasNext()) { - String record = nextRecord(scanner); - if (StringUtils.isNotBlank(record)) { - lineConsumer.accept(record); - } - } - } - - private String nextRecord(Scanner scanner) { - String record = null; - scanner.useDelimiter("__START__"); - scanner.next(); - if (scanner.hasNext()) { - scanner.useDelimiter("\n() { - @Override - public void accept(String recordXml) { - try { - Document doc = builder.parse(IOUtils.toInputStream(recordXml, StandardCharsets.UTF_8)); - Map nameMap = parseFocalTaxon(doc); - listener.foundTaxonForTerm( - null, - TaxonUtil.mapToTaxon(nameMap), - NameType.HAS_ACCEPTED_NAME, - TaxonUtil.mapToTaxon(nameMap) - ); - } catch (SAXException | IOException | XPathExpressionException e) { - e.printStackTrace(); - // ignore for now - } - - } - }); - } - - private Map parseFocalTaxon(Document doc) throws XPathExpressionException { - Map nameMap = new TreeMap() {{ - put("kingdom", "Animalia"); - put("phylum", "Arthropoda"); - put("class", "Insecta"); - put("order", "Hymenoptera"); - put("superfamily", "Apoidea"); - }}; - - Node setNode = (Node) XmlUtil.applyXPath(doc, "set", XPathConstants.NODE); - - - putTextValueForElement(nameMap, setNode, "name", PropertyAndValueDictionary.NAME); - putTextValueForElement(nameMap, setNode, "authority", PropertyAndValueDictionary.AUTHORSHIP); - - Node level = setNode.getAttributes().getNamedItem("level"); - String taxonomicRank = level == null ? null : level.getTextContent(); - nameMap.put(PropertyAndValueDictionary.RANK, taxonomicRank); - nameMap.put(taxonomicRank, nameMap.get(PropertyAndValueDictionary.NAME)); - - - NodeList attr = (NodeList) XmlUtil.applyXPath(setNode, "//attributes", XPathConstants.NODESET); - - if (attr != null && attr.getLength() > 0) { - - NodeList childNodes = attr.item(0).getChildNodes(); - - String keyCurrent = ""; - ObjectNode objectNode = new ObjectMapper().createObjectNode(); - ArrayNode valuesCurrent = new ObjectMapper().createArrayNode(); - - for (int i = 0; i < childNodes.getLength(); i++) { - Node childNode = childNodes.item(i); - String key = childNode.getNodeName(); - if (StringUtils.equals("character", key)) { - keyCurrent = childNode.getTextContent(); - valuesCurrent = new ObjectMapper().createArrayNode(); - } else if (StringUtils.equals("state", key)) { - if (StringUtils.isNotBlank(keyCurrent)) { - valuesCurrent.add(childNode.getTextContent()); - if (valuesCurrent.size() > 0 && objectNode != null) { - if (RANKS.contains(keyCurrent)) { - nameMap.put(StringUtils.lowerCase(keyCurrent), valuesCurrent.get(0).asText()); - } - } - } - } - } - - String pathNames = generateTaxonPathNames(nameMap, Arrays.asList("kingdom", "phylum", "class", "order", "family", "subfamily", "tribe", "subtribe", "genus", "subgenus", "subspecies"), "", "genus", "specificEpithet", "subspecificEpithet", "species"); - - nameMap.put(PropertyAndValueDictionary.PATH_NAMES, pathNames); - - String[] ranks = StringUtils.splitByWholeSeparator(pathNames, CharsetConstant.SEPARATOR); - List path = new ArrayList<>(); - - for (String rank : ranks) { - path.add(nameMap.get(rank)); - } - - String pathString = StringUtils.join(path, CharsetConstant.SEPARATOR); - nameMap.put(PropertyAndValueDictionary.PATH, pathString); - } - return nameMap; - } - - private void putTextValueForElement(Map nameMap, Node setNode, String sourceElementName, String targetName) throws XPathExpressionException { - Node nameNode = (Node) XmlUtil.applyXPath(setNode, sourceElementName, XPathConstants.NODE); - if (nameNode != null) { - nameMap.put(targetName, nameNode.getTextContent()); - } - } - } \ No newline at end of file diff --git a/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtilIntegrationTest.java b/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtilIntegrationTest.java new file mode 100644 index 00000000..34298a0e --- /dev/null +++ b/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtilIntegrationTest.java @@ -0,0 +1,78 @@ +package org.eol.globi.taxon; + +import org.apache.commons.io.IOUtils; +import org.eol.globi.domain.NameType; +import org.eol.globi.domain.Taxon; +import org.eol.globi.domain.Term; +import org.eol.globi.service.ResourceService; +import org.hamcrest.core.Is; +import org.junit.Test; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNull; + +public class DiscoverLifeUtilIntegrationTest { + + private static final String DISCOVER_LIFE_URL + = DiscoverLifeUtil.URL_ENDPOINT_DISCOVER_LIFE + + "/mp/20q" + + "?act=x_checklist" + + "&guide=Apoidea_species" + + "&flags=HAS"; + private static final String BEE_NAMES_CACHED = "/org/globalbioticinteractions/nomer/match/discoverlife/bees.html.gz"; + + + @Test + public void parseBees() throws IOException { + + final AtomicReference firstTaxon = new AtomicReference<>(); + + AtomicInteger counter = new AtomicInteger(0); + + TermMatchListener listener = (requestId, providedTerm, nameType, resolvedTaxon) -> { + int index = counter.getAndIncrement(); + if (index == 0) { + firstTaxon.set(resolvedTaxon); + } + }; + + DiscoverLifeUtil.parse(DiscoverLifeUtil.getBeeNameTable(new ResourceService() { + @Override + public InputStream retrieve(URI uri) throws IOException { + return DiscoverLifeTestUtil.getStreamOfBees(BEE_NAMES_CACHED); + } + }, "https://example.org"), listener); + + assertThat(counter.get(), Is.is(58310)); + + Taxon taxon = firstTaxon.get(); + + assertThat(taxon.getPath(), Is.is("Animalia | Arthropoda | Insecta | Hymenoptera | Andrenidae | Acamptopoeum | Acamptopoeum argentinum")); + assertThat(taxon.getPathIds(), Is.is("https://www.discoverlife.org/mp/20q?search=Animalia | https://www.discoverlife.org/mp/20q?search=Arthropoda | https://www.discoverlife.org/mp/20q?search=Insecta | https://www.discoverlife.org/mp/20q?search=Hymenoptera | https://www.discoverlife.org/mp/20q?search=Andrenidae | https://www.discoverlife.org/mp/20q?search=Acamptopoeum | https://www.discoverlife.org/mp/20q?search=Acamptopoeum+argentinum")); + assertThat(taxon.getPathNames(), Is.is("kingdom | phylum | class | order | family | genus | species")); + assertThat(taxon.getName(), Is.is("Acamptopoeum argentinum")); + assertThat(taxon.getRank(), Is.is("species")); + assertThat(taxon.getId(), Is.is("https://www.discoverlife.org/mp/20q?search=Acamptopoeum+argentinum")); + } + + + @Test + public void getCurrentBeeNames() throws IOException { + DiscoverLifeTestUtil.compareLocalVersionToRemoteVersion(BEE_NAMES_CACHED, DISCOVER_LIFE_URL); + } + +} \ No newline at end of file diff --git a/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtilTest.java b/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtilTest.java index c6b0da85..749069f7 100644 --- a/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtilTest.java +++ b/nomer-taxon-resolver/src/test/java/org/eol/globi/taxon/DiscoverLifeUtilTest.java @@ -29,14 +29,6 @@ public class DiscoverLifeUtilTest { - private static final String DISCOVER_LIFE_URL - = DiscoverLifeUtil.URL_ENDPOINT_DISCOVER_LIFE + - "/mp/20q" + - "?act=x_checklist" + - "&guide=Apoidea_species" + - "&flags=HAS"; - private static final String BEE_NAMES_CACHED = "/org/globalbioticinteractions/nomer/match/discoverlife/bees.html.gz"; - @Test public void parseNameAncylandrenaAtoposoma() throws SAXException, ParserConfigurationException, XPathExpressionException, IOException { // see https://github.com/globalbioticinteractions/nomer/issues/149 @@ -735,51 +727,6 @@ public void foundTaxonForTerm(Long requestId, Term providedTerm, NameType nameTy } - @Test - public void parseBees() throws IOException { - - final AtomicReference firstTaxon = new AtomicReference<>(); - - AtomicInteger counter = new AtomicInteger(0); - - TermMatchListener listener = (requestId, providedTerm, nameType, resolvedTaxon) -> { - int index = counter.getAndIncrement(); - if (index == 0) { - firstTaxon.set(resolvedTaxon); - } - }; - - DiscoverLifeUtil.parse(DiscoverLifeUtil.getBeeNameTable(new ResourceService() { - @Override - public InputStream retrieve(URI uri) throws IOException { - return getStreamOfBees(); - } - }, "https://example.org"), listener); - - assertThat(counter.get(), Is.is(58310)); - - Taxon taxon = firstTaxon.get(); - - assertThat(taxon.getPath(), Is.is("Animalia | Arthropoda | Insecta | Hymenoptera | Andrenidae | Acamptopoeum | Acamptopoeum argentinum")); - assertThat(taxon.getPathIds(), Is.is("https://www.discoverlife.org/mp/20q?search=Animalia | https://www.discoverlife.org/mp/20q?search=Arthropoda | https://www.discoverlife.org/mp/20q?search=Insecta | https://www.discoverlife.org/mp/20q?search=Hymenoptera | https://www.discoverlife.org/mp/20q?search=Andrenidae | https://www.discoverlife.org/mp/20q?search=Acamptopoeum | https://www.discoverlife.org/mp/20q?search=Acamptopoeum+argentinum")); - assertThat(taxon.getPathNames(), Is.is("kingdom | phylum | class | order | family | genus | species")); - assertThat(taxon.getName(), Is.is("Acamptopoeum argentinum")); - assertThat(taxon.getRank(), Is.is("species")); - assertThat(taxon.getId(), Is.is("https://www.discoverlife.org/mp/20q?search=Acamptopoeum+argentinum")); - } - - - //@Ignore("see https://github.com/globalbioticinteractions/nomer/issues/80") - @Test - public void getCurrentBeeNames() throws IOException { - DiscoverLifeTestUtil.compareLocalVersionToRemoteVersion(BEE_NAMES_CACHED, DISCOVER_LIFE_URL); - } - - public static InputStream getStreamOfBees() throws IOException { - return DiscoverLifeTestUtil.getStreamOfBees(BEE_NAMES_CACHED); - } - - @Test public void guessRank() throws IOException { assertThat(DiscoverLifeUtil.guessRankFromName("Bla bla"), Is.is("species"));