2014-09-17 6 views
1

Я хотел бы проверить функцию XQuery eXist-db, которая принимает аргумент Map datatype. Согласно eXist-db test framework guide:Как проверить функцию XQuery с аргументом карты

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.

Однако, я не мог найти, как определить тип данных карты в виде строки. Вот пример кода, который у меня есть:

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) 
}; 

тест завершается с ошибкой при слежении:

<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> 

Любые идеи, как сделать его работу?

ответ

1

Получил следующий ответ в списке рассылки:

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

Смежные вопросы