I'd like to test an eXist-db XQuery function that takes Map datatype argument. According to the eXist-db test framework guide:
XQuery annotation parameters need to be literal values, so only strings and numbers are allowed. XQSuite thus applies type conversion to every argument as well as to values used in assertions.
However, I could not find how to specify a Map datatype as a string. Here is an example code that I have:
declare
%test:arg("input", "{p1}?id={id}")
%test:arg("props", "id")
%test:arg("props", "ABC")
%test:assertEquals("{p1}?id=ABC")
function properties:substitute($input as xs:string, $props as map (xs:string, xs:string)) as xs:string {
let $keys := map:keys($props)
let $tokens := $keys ! concat('\{', ., '\}')
let $replacements := $keys ! $props(.)
return functx:replace-multi($input, $tokens, $replacements)
};
The test fails with the following error:
<testcase name="substitute" class="properties:substitute">
<error type="java:org.exist.xquery.XPathException" message="exerr:ERROR XPTY0004: The actual cardinality for parameter 2 does not match the cardinality declared in the function's signature: properties:substitute($input as xs:string, $props as map) xs:string. Expected cardinality: exactly one, got 3. [at line 7, column 5]
In function:
properties:substitute(xs:string, map) [7:5:/db/apps/ssg/modules/properties.xql]
test:apply(function, item()*) [327:9:jar:file:/C:/Programs/eXist-db/exist.jar!/org/exist/xquery/lib/xqsuite/xqsuite.xql]
test:apply(function, element(), item()*) [234:9:jar:file:/C:/Programs/eXist-db/exist.jar!/org/exist/xquery/lib/xqsuite/xqsuite.xql]
test:call-test(function, element(), element()*) [135:32:jar:file:/C:/Programs/eXist-db/exist.jar!/org/exist/xquery/lib/xqsuite/xqsuite.xql]"/>
</testcase>
Any ideas how to make it working?
Got the following reply in the mailing list:
Sorry, that’s not possible. A map does not have a simple string representation. You will have to write a helper function for the test, which generates the map, e.g. by taking an xml fragment and converting it.
Wolfgang