|
From: Harris, B. T. (GSFC-5870) <ber...@na...> - 2023-03-14 17:55:39
|
That's what I originally tried. I changed the code back and get
<testsuites>
<testsuite package="http://www.w3.org/2005/xquery-local-functions" timestamp="2023-03-14T13:50:22.852-04:00" tests="1" failures="1" errors="0" pending="0" time="PT0.003S">
<testcase name="errorHtml" class="local:errorHtml">
<failure message="assertXPath failed." type="failure-error-code-1">$result//html</failure>
<output>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Bad Request</title>
</head>
<body>
<p class="ErrorMessage">
<b>Message: </b>Bad Request</p>
<p class="ErrorDescription">
<b>Description: </b>Invalid ResourceID</p>
</body>
</html>
</output>
</testcase>
</testsuite>
</testsuites>
Do you have any other ideas? Thanks.
Bernie
From: Joe Wicentowski <jo...@gm...>
Date: Tuesday, March 14, 2023 at 1:00 PM
To: "Harris, Bernard T. (GSFC-5870)" <ber...@na...>
Cc: "exi...@li..." <exi...@li...>
Subject: [EXTERNAL] Re: [Exist-open] %test:assertXPath help
Hi Bernie,
I've just had a look at the XQSuite source where %assertXPath annotations are processed (https://gcc02.safelinks.protection.outlook.com/?url=https://github.com/eXist-db/exist/blob/develop/exist-core/src/main/resources/org/exist/xquery/lib/xqsuite/xqsuite.xql#L944-L992&data=05|01|ber...@na...|63bac86b07ad49cf2d0608db24ada9aa|7005d45845be48ae8140d43da96dd17b|0|0|638144100514332470|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|3000|||&sdata=ITdkPxaexxeE3xqBqSVGuOC2OmKOFq6RjMeRgmvoAFQ=&reserved=0). It appears to me that XQSuite dynamically constructs namespace declarations based on the in-scope namespaces in the return value of the function.
So if your function's return value contained an HTML element with namespace prefix bindings, like:
<html:html xmlns:html="https://gcc02.safelinks.protection.outlook.com/?url=http://www.w3.org/1999/xhtml&data=05|01|ber...@na...|63bac86b07ad49cf2d0608db24ada9aa|7005d45845be48ae8140d43da96dd17b|0|0|638144100514488671|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|3000|||&sdata=oZctXzxHQ3W+XkWhuDkn/cligiXBNykhy67+BD7R+3k=&reserved=0">
... XQSuite would dynamically create the following namespace declaration:
declare namespace xhtml='https://gcc02.safelinks.protection.outlook.com/?url=http://www.w3.org/1999/xhtml&data=05|01|ber...@na...|63bac86b07ad49cf2d0608db24ada9aa|7005d45845be48ae8140d43da96dd17b|0|0|638144100514488671|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|3000|||&sdata=oZctXzxHQ3W+XkWhuDkn/cligiXBNykhy67+BD7R+3k=&reserved=0';
... which would be prepended to your %assertXPath annotation and evaluated.
Since your function's return value doesn't associate <html> with any namespace prefix - only a namespace URI - then you should construct your %assertXPath annotations with the expectation that elements have a default namespace of "https://gcc02.safelinks.protection.outlook.com/?url=http://www.w3.org/1999/xhtml&data=05|01|ber...@na...|63bac86b07ad49cf2d0608db24ada9aa|7005d45845be48ae8140d43da96dd17b|0|0|638144100514488671|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|3000|||&sdata=oZctXzxHQ3W+XkWhuDkn/cligiXBNykhy67+BD7R+3k=&reserved=0".
Thus I would suggest that you try modifying your %assertXPath annotations to be:
%test:assertXPath("$result//html")
%test:assertXPath("$result//html/head[title = 'Bad Request']")
%test:assertXPath("$result/html/body/p[@class = 'ErrorMessage']")
I haven't tested this myself, so if you give this a try, could you let us know the result?
If we confirm that my hunch is correct, then we could supply some additional hints in the documentation for this annotation at https://gcc02.safelinks.protection.outlook.com/?url=https://exist-db.org/exist/apps/doc/xqsuite#annotations&data=05|01|ber...@na...|63bac86b07ad49cf2d0608db24ada9aa|7005d45845be48ae8140d43da96dd17b|0|0|638144100514488671|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|3000|||&sdata=RT7os5HKMQtvqb0XmDSSrYDlRFsSnaGS4fXMOE9ISxY=&reserved=0.
Thanks!
Joe
On Tue, Mar 14, 2023 at 8:52 AM Harris, Bernard T. (GSFC-5870) via Exist-open <mailto:exi...@li...> wrote:
No matter what I do, I cannot get a useful (more than "$result") %:assertXPath to work in this case
xquery version "3.1";
import module namespace inspect="https://gcc02.safelinks.protection.outlook.com/?url=http://exist-db.org/xquery/inspection&data=05|01|ber...@na...|63bac86b07ad49cf2d0608db24ada9aa|7005d45845be48ae8140d43da96dd17b|0|0|638144100514488671|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|3000|||&sdata=KNfQpepOm8OabDBKGh9SuD+fNhm5Wq5ZQ0qhRz8e66s=&reserved=0";
import module namespace test="https://gcc02.safelinks.protection.outlook.com/?url=http://exist-db.org/xquery/xqsuite&data=05|01|ber...@na...|63bac86b07ad49cf2d0608db24ada9aa|7005d45845be48ae8140d43da96dd17b|0|0|638144100514488671|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|3000|||&sdata=taWxbBzutRB6d2qCdeLsokylN0mmLUa41U0NXa4vquM=&reserved=0"
at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
declare namespace xhtml = "https://gcc02.safelinks.protection.outlook.com/?url=http://www.w3.org/1999/xhtml&data=05|01|ber...@na...|63bac86b07ad49cf2d0608db24ada9aa|7005d45845be48ae8140d43da96dd17b|0|0|638144100514488671|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|3000|||&sdata=oZctXzxHQ3W+XkWhuDkn/cligiXBNykhy67+BD7R+3k=&reserved=0";
declare
%test:arg("error", "Bad Request")
%test:arg("description", "Invalid ResourceID")
%test:arg("extraHtml")
%test:assertXPath("$result//*:html")
(:
%test:assertXPath("$result//*:html/*:head[*:title = 'Bad Request']")
%test:assertXPath("$result/xhtml:html/xhtml:body/xhtml:p[@class = 'ErrorMessage']")
:)
function local:errorHtml(
$error as xs:string,
$description as xs:string,
$extraHtml as node()?)
as node()
{
let $result :=
<html xmlns="https://gcc02.safelinks.protection.outlook.com/?url=http://www.w3.org/1999/xhtml&data=05|01|ber...@na...|63bac86b07ad49cf2d0608db24ada9aa|7005d45845be48ae8140d43da96dd17b|0|0|638144100514488671|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|3000|||&sdata=oZctXzxHQ3W+XkWhuDkn/cligiXBNykhy67+BD7R+3k=&reserved=0" lang="en" xml:lang="en">
<head>
<title>{$error}</title>
</head>
<body>
<p class='ErrorMessage'><b>Message: </b>{$error}</p>
<p class='ErrorDescription'><b>Description: </b>{$description}</p>
{$extraHtml}
</body>
</html>
return
$result
};
let $f := local:errorHtml#3
return
test:suite($f)
It always results in
<testsuites>
<testsuite package="https://gcc02.safelinks.protection.outlook.com/?url=http://www.w3.org/2005/xquery-local-functions&data=05|01|ber...@na...|63bac86b07ad49cf2d0608db24ada9aa|7005d45845be48ae8140d43da96dd17b|0|0|638144100514488671|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|3000|||&sdata=zD6rei5wcfZb3pRb8s3DxkscfQGDmo0rwIJgyuftpz8=&reserved=0" timestamp="2023-03-14T08:28:16.065-04:00" tests="1" failures="1" errors="0" pending="0" time="PT0.002S">
<testcase name="errorHtml" class="local:errorHtml">
<failure message="assertXPath failed." type="failure-error-code-1">$result//*:html</failure>
<output>
<html xmlns="https://gcc02.safelinks.protection.outlook.com/?url=http://www.w3.org/1999/xhtml&data=05|01|ber...@na...|63bac86b07ad49cf2d0608db24ada9aa|7005d45845be48ae8140d43da96dd17b|0|0|638144100514488671|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|3000|||&sdata=oZctXzxHQ3W+XkWhuDkn/cligiXBNykhy67+BD7R+3k=&reserved=0" lang="en" xml:lang="en">
<head>
<title>Bad Request</title>
</head>
<body>
<p class="ErrorMessage">
<b>Message: </b>Bad Request</p>
<p class="ErrorDescription">
<b>Description: </b>Invalid ResourceID</p>
</body>
</html>
</output>
</testcase>
</testsuite>
</testsuites>
Or
<testcase name="errorHtml" class="spasexq:errorHtml">
<error type="err:XPST0081" message="It is a static error if a QName used in an expression contains a namespace prefix that cannot be expanded into a namespace URI by using the statically known namespaces. Error while evaluating expression: $result//xhtml:html. No namespace defined for prefix xhtml:html"/>
</testcase>
If I use the xhtml namespace in the assertXPath annotation. I found someone report a similar problem on stackoverflow in 2016 but it is not clear to me how it was resolved. This is on exist-db 6.2.0 and Java 11. Does anyone know what I am doing wrong? Thanks.
Bernie Harris
_______________________________________________
Exist-open mailing list
mailto:Exi...@li...
https://gcc02.safelinks.protection.outlook.com/?url=https://lists.sourceforge.net/lists/listinfo/exist-open&data=05|01|ber...@na...|63bac86b07ad49cf2d0608db24ada9aa|7005d45845be48ae8140d43da96dd17b|0|0|638144100514488671|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|3000|||&sdata=QC1qUFB+nnxtZiDTjM7K29YVMsXgWKuRamKCZ2tbhVA=&reserved=0
|