|
From: Joe W. <jo...@gm...> - 2023-03-15 15:45:30
|
Hi Bernie,
No, I'm saying that
%test:assertXPath("$result/self::*:html")
should work.
Joe
On Wed, Mar 15, 2023 at 11:39 AM Harris, Bernard T. (GSFC-5870) <
ber...@na...> wrote:
> Are you saying
>
> %test:assertXPath("$result//*:html")
>
> Should work now? It does not.
>
>
>
> Bernie
>
>
>
> *From: *Joe Wicentowski <jo...@gm...>
> *Date: *Wednesday, March 15, 2023 at 11:33 AM
> *To: *"Harris, Bernard T. (GSFC-5870)" <ber...@na...>
> *Cc: *Juri Leino <ju...@ex...>, "
> exi...@li..." <exi...@li...>
> *Subject: *Re: [Exist-open] [EXTERNAL] Re: %test:assertXPath help
>
>
>
> Hi Bernie,
>
>
>
> When I said:
>
>
>
> > 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 "http://www.w3.org/1999/xhtml
> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7Cc9e07b1122764716731f08db256aa1c0%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638144912136503017%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=5rvwzLyiQSblAo1v%2BVEHKiSawWHPuEPwXj002k7xyyw%3D&reserved=0>
> ".
>
>
>
> ... I was conveying how I expected XQSuite *should* work.
>
>
>
> But upon closer examination, I see that XQSuite does *not* provide
> %test:assertXPath annotation with any mechanism to address elements whose
> namespace is not bound to a namespace prefix.
>
>
>
> For situations such as the one you raised, you are currently limited to
> wildcards.
>
>
>
> I will submit a PR fixing this - adjusting XQSuite to work as I originally
> described. With the PR, you'll be able to use annotations like:
>
>
>
> %test:assertXPath("$result/self::html")
>
> %test:assertXPath("$result/head[title = 'Bad Request']")
>
> %test:assertXPath("$result/body/p[@class = 'ErrorMessage']")
>
>
>
> (Note here that $result is the <html> element, not a container around it.
> Thus, the expressions are slightly different from your originals.)
>
>
>
> Joe
>
>
>
> On Wed, Mar 15, 2023 at 9:23 AM Harris, Bernard T. (GSFC-5870) via
> Exist-open <exi...@li...> wrote:
>
> Thanks for the suggestions. If I replace the import statement with the
> declaration of the test namespace, I get
>
>
>
> Cannot compile xquery: err:XPST0017 Call to undeclared function: test:suite
>
>
>
> Your other suggestion to simplify the assertXPath expression might work on
> this simple case, but I actually want to get the assertXPath working for
> other, more complicated, functions. I was trying to get this simple case
> working before using assertXPath on other, more important and complex
> functions. Any other suggestions? Thanks.
>
>
>
> Bernie
>
>
>
> *From: *Juri Leino <ju...@ex...>
> *Date: *Wednesday, March 15, 2023 at 8:58 AM
> *To: *"Harris, Bernard T. (GSFC-5870)" <ber...@na...>
> *Cc: *"exi...@li..." <exi...@li...
> >
> *Subject: *[EXTERNAL] Re: [Exist-open] %test:assertXPath help
>
>
>
> Hi Bernard!
>
> I would replace
>
> import module namespace test="http://exist-db.org/xquery/xqsuite" <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fexist-db.org%2Fxquery%2Fxqsuite&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7Cc9e07b1122764716731f08db256aa1c0%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638144912136659229%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=7o6yO6gI6F8rbwboU5UwlPSWCko913IGZ0GBrOMde0o%3D&reserved=0>
>
> at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
>
>
> with
>
> declare namespace test="http://exist-db.org/xquery/xqsuite"
> <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fexist-db.org%2Fxquery%2Fxqsuite&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7Cc9e07b1122764716731f08db256aa1c0%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638144912136659229%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=7o6yO6gI6F8rbwboU5UwlPSWCko913IGZ0GBrOMde0o%3D&reserved=0>
> ;
>
> Now to your actual problem:
>
> The namespace declared in the testsuite is very likely not seen by
> XQSuite.
> This is non-obvious. The reason for this is that test argument and
> assertion annotation values
> are string literals that get cast to the expected type in the context of
> the XQSuite module
> *and not in the context of the testsuite*.
>
> Many tests in exist-db core serialize XML an assert that the result
> *string* matches the expected
> value instead of which could be a workaround for your tests as well.
>
> In your case it might be easiest to just return the evaluated xpath from
> the testcase and to assert the strings equal
>
> declare
>
> %test:arg("error", "Bad Request")
>
> %test:arg("description", "Invalid ResourceID")
>
> %test:arg("extraHtml")
>
> %test:assertXPath("Bad Request")
>
> function local:errorHtml(
>
> $error as xs:string,
>
> $description as xs:string,
>
> $extraHtml as node()?)
>
> as node()
>
> {
>
> let $result :=
>
> <html xmlns="http://www.w3.org/1999/xhtml" <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7Cc9e07b1122764716731f08db256aa1c0%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638144912136659229%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=OluYPpFs2N27fx966IHk2lBY8WrO4Y61ava08NlD7F8%3D&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/xhtml:html/xhtml:body/xhtml:p[@class = 'ErrorMessage']
>
> };
>
>
>
>
>
>
>
> Harris, Bernard T. (GSFC-5870) via Exist-open wrote on 14.03.23 13:35:
>
> 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="http://exist-db.org/xquery/inspection" <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fexist-db.org%2Fxquery%2Finspection&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7Cc9e07b1122764716731f08db256aa1c0%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638144912136659229%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=eglg7PwI1xpl0%2FIWlEwBa73FynyjKHfgjK6UnXogsQ0%3D&reserved=0>;
>
> import module namespace test="http://exist-db.org/xquery/xqsuite" <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fexist-db.org%2Fxquery%2Fxqsuite&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7Cc9e07b1122764716731f08db256aa1c0%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638144912136659229%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=7o6yO6gI6F8rbwboU5UwlPSWCko913IGZ0GBrOMde0o%3D&reserved=0>
>
> at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql";
>
>
>
> declare namespace xhtml = "http://www.w3.org/1999/xhtml" <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7Cc9e07b1122764716731f08db256aa1c0%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638144912136659229%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=OluYPpFs2N27fx966IHk2lBY8WrO4Y61ava08NlD7F8%3D&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="http://www.w3.org/1999/xhtml" <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7Cc9e07b1122764716731f08db256aa1c0%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638144912136659229%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=OluYPpFs2N27fx966IHk2lBY8WrO4Y61ava08NlD7F8%3D&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="http://www.w3.org/2005/xquery-local-functions" <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2005%2Fxquery-local-functions&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7Cc9e07b1122764716731f08db256aa1c0%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638144912136659229%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=3qNMXxBWnpwoxkClwgryRh%2Bp73xprYL0HIrAXaTtAoA%3D&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="http://www.w3.org/1999/xhtml" <https://gcc02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7Cc9e07b1122764716731f08db256aa1c0%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638144912136659229%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=OluYPpFs2N27fx966IHk2lBY8WrO4Y61ava08NlD7F8%3D&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
>
> Exi...@li...
>
> https://lists.sourceforge.net/lists/listinfo/exist-open <https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fexist-open&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7Cc9e07b1122764716731f08db256aa1c0%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638144912136659229%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=H1qtamN52Grn9BtR0kViVdnt5GZfcB3vkFKGpIlMGY8%3D&reserved=0>
>
>
>
>
>
> _______________________________________________
> Exist-open mailing list
> Exi...@li...
> https://lists.sourceforge.net/lists/listinfo/exist-open
> <https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fexist-open&data=05%7C01%7Cbernard.t.harris%40nasa.gov%7Cc9e07b1122764716731f08db256aa1c0%7C7005d45845be48ae8140d43da96dd17b%7C0%7C0%7C638144912136659229%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=H1qtamN52Grn9BtR0kViVdnt5GZfcB3vkFKGpIlMGY8%3D&reserved=0>
>
>
|