libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 88126d05cfc90f0c7de09270e71ec8457142b447
parent 96b5026a26fafea09d738de1814205db4b341992
Author: Marcello Stanisci <ms@taler.net>
Date:   Thu, 30 Apr 2020 22:13:55 +0200

Check XPath outcome on string length.

Diffstat:
Mnexus/src/test/kotlin/XPathTest.kt | 5++---
Mutil/src/main/kotlin/XMLUtil.kt | 6++++--
2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/nexus/src/test/kotlin/XPathTest.kt b/nexus/src/test/kotlin/XPathTest.kt @@ -3,6 +3,7 @@ package tech.libeufin.nexus import org.junit.Test import org.w3c.dom.Document import tech.libeufin.util.XMLUtil +import tech.libeufin.util.pickString class XPathTest { @@ -13,9 +14,7 @@ class XPathTest { <node>lorem ipsum</node> </root>""".trimIndent() val doc: Document = XMLUtil.parseStringIntoDom(xml) - XMLUtil.getNodeFromXpath(doc, "/*[local-name()='root']") - val text = XMLUtil.getStringFromXpath(doc, "//*[local-name()='node']") - println(text) + println(doc.pickString( "//*[local-name()='node']")) } } diff --git a/util/src/main/kotlin/XMLUtil.kt b/util/src/main/kotlin/XMLUtil.kt @@ -417,8 +417,10 @@ class XMLUtil private constructor() { fun getStringFromXpath(doc: Document, query: String): String { val xpath = XPathFactory.newInstance().newXPath() - val ret = xpath.evaluate(query, doc, XPathConstants.STRING) - ?: throw UtilError(HttpStatusCode.NotFound, "Unsuccessful XPath query string: $query") + val ret = xpath.evaluate(query, doc, XPathConstants.STRING) as String + if (ret.isEmpty()) { + throw UtilError(HttpStatusCode.NotFound, "Unsuccessful XPath query string: $query") + } return ret as String } }