/** A more realitic query with a version decl, no encoding. . */ @org.junit.Test public void prologVersion7V3() { final XQuery query = new XQuery( "\n" + " xquery version \"3.0\"; \n" + " declare boundary-space preserve; \n" + " declare default order empty greatest; \n" + " declare namespace ns = \"http://www.example.org/\"; \n" + " for $b in //book stable order by xs:decimal($b/price[1]) empty greatest \n" + " return $b/title", ctx); try { query.context(node(file("op/union/bib2.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<title>Data on the Web</title><title>TCP/IP Illustrated</title><title>Advanced Programming in the Unix environment</title><title>The Economics of Technology and Content for Digital TV</title>", false)); }
/** . */ @org.junit.Test public void treeQueriesResultsQ6() { final XQuery query = new XQuery( "\n" + " declare function local:section-summary($book-or-section as element()*) as element()* { \n" + " for $section in $book-or-section \n" + " return <section> { $section/@* } { $section/title } <figcount> { count($section/figure) } </figcount> { local:section-summary($section/section) } </section> \n" + " }; \n" + " <toc> { \n" + " for $s in /book/section \n" + " return local:section-summary($s) \n" + " } </toc>\n" + " ", ctx); try { query.context(node(file("docs/book.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<toc><section id=\"intro\" difficulty=\"easy\"><title>Introduction</title><figcount>0</figcount><section><title>Audience</title><figcount>0</figcount></section><section><title>Web Data and the Two Cultures</title><figcount>1</figcount></section></section><section id=\"syntax\" difficulty=\"medium\"><title>A Syntax For Data</title><figcount>1</figcount><section><title>Base Types</title><figcount>0</figcount></section><section><title>Representing Relational Databases</title><figcount>1</figcount></section><section><title>Representing Object Databases</title><figcount>0</figcount></section></section></toc>", false)); }
/** arg: text node & node . */ @org.junit.Test public void fnUnionNodeArgs008() { final XQuery query = new XQuery("/bib/book[3]/title/text() | /bib/book[1]/title", ctx); try { query.context(node(file("op/union/bib2.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertSerialization("<title>TCP/IP Illustrated</title>Data on the Web", false)); }
/** arg: incorrect nodes . */ @org.junit.Test public void fnUnionNodeArgs002() { final XQuery query = new XQuery("(/bib/book/title | /bib/book)/local-name()", ctx); try { query.context(node(file("op/union/bib2.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertStringValue(false, "book title book title book title book title")); }
/** . */ @org.junit.Test public void treeQueriesResultsQ4() { final XQuery query = new XQuery("<top_section_count> { count(/book/section) } </top_section_count>", ctx); try { query.context(node(file("docs/book.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertSerialization("<top_section_count>2</top_section_count>", false)); }
/** context item expression where context item used as argumet to fn:sum. . */ @org.junit.Test public void externalcontextitem9() { final XQuery query = new XQuery("for $var in (/works/employee[1]) return $var/fn:sum((hours,hours))", ctx); try { query.context(node(file("docs/works-mod.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertEq("80")); }
/** Extract the boolean value from a union expression(different keyword). . */ @org.junit.Test public void k2SeqUnion44() { final XQuery query = new XQuery("boolean(//employee[location = \"Denver\"] | //employee[last()])", ctx); try { query.context(node(file("op/union/acme_corp.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertBoolean(true)); }
/** context item expression where context item is used as string. . */ @org.junit.Test public void externalcontextitem2() { final XQuery query = new XQuery( "for $var in /works/employee[1] return $var/xs:string(exactly-one(empnum))", ctx); try { query.context(node(file("docs/works-mod.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertStringValue(false, "E1")); }
/** arg: processing-instruction node & node . */ @org.junit.Test public void fnUnionNodeArgs010() { final XQuery query = new XQuery("/processing-instruction(PI1) | /bib/book[3]/title", ctx); try { query.context(node(file("op/union/bib2.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<?PI1 Processing Instruction 1?><title>Data on the Web</title>", false)); }
/** arg: processing-instruction node & node . */ @org.junit.Test public void fnUnionNodeArgs009() { final XQuery query = new XQuery("/processing-instruction() | /bib/book[2]/title", ctx); try { query.context(node(file("op/union/bib2.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<?PI1 Processing Instruction 1?><title>Advanced Programming in the Unix environment</title><?PI2 Processing Instruction 2?>", false)); }
/** arg: comment node & node . */ @org.junit.Test public void fnUnionNodeArgs011() { final XQuery query = new XQuery("/comment() | /bib/book[1]/title", ctx); try { query.context(node(file("op/union/bib2.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<!-- this file is a copy of bib.xml; just adds a few comments and PI nodes for testing --><!-- Comment 1 --><title>TCP/IP Illustrated</title><!-- Comment 2 -->", false)); }
/** * Simple call of "fn:trace" function used numbers manipulation queried from an xml file and the * entire query is given as argument to the function. . */ @org.junit.Test public void fnTrace12() { final XQuery query = new XQuery( "fn:trace((for $var in (/works//hours) return $var + $var) ,\"The Value of the given expression is: \")", ctx); try { query.context(node(file("docs/works-mod.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertStringValue(false, "80 140 40 160 40 80 40 60 24 80 160 40 40 40 80 160")); }
/** Reference to a context item that has not been bound. . */ @org.junit.Test public void externalcontextitem24() { final XQuery query = new XQuery("works/employee[1]", ctx); try { query.context(node(file("docs/works-mod.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<employee name=\"Jane Doe 1\" gender=\"female\">\n <empnum>E1</empnum>\n <pnum>P1</pnum>\n <hours>40</hours>\n </employee>", false)); }
/** context item expression where context item is an xs:boolean used with fn:not(). . */ @org.junit.Test public void externalcontextitem8() { final XQuery query = new XQuery( "for $var in (/works/employee[1]) return $var/fn:not(xs:boolean(exactly-one(hours) - 39))", ctx); try { query.context(node(file("docs/works-mod.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertBoolean(false)); }
/** Simple call of "fn:trace" function used numbers manipulation queried from an xml file. . */ @org.junit.Test public void fnTrace11() { final XQuery query = new XQuery( "for $var in (/works//hours) return fn:trace(($var div 2) ,\"The Value of hours div/2 is: \")", ctx); try { query.context(node(file("docs/works-mod.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertStringValue(false, "20 35 10 40 10 20 10 15 6 20 40 10 10 10 20 40")); }
/** arg: node & node . */ @org.junit.Test public void fnUnionNodeArgs023() { final XQuery query = new XQuery( "string-join(for $node in ((//price/text()) , (//price/text())) union ((//price/text()) , (//price/text())) return $node, \"|\")", ctx); try { query.context(node(file("op/union/bib2.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test(assertStringValue(false, " 65.95|65.95| 39.95|129.95")); }
/** arg: node & empty sequence . */ @org.junit.Test public void fnUnionNodeArgs013() { final XQuery query = new XQuery("//author | ()", ctx); try { query.context(node(file("op/union/bib2.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<author><last>Stevens</last><first>W.</first></author><author><last>Stevens</last><first>W.</first></author><author><last>Abiteboul</last><first>Serge</first></author><author><last>Buneman</last><first>Peter</first></author><author><last>Suciu</last><first>Dan</first></author>", false)); }
/** arg: node . */ @org.junit.Test public void fnUnionNodeArgs003() { final XQuery query = new XQuery("/bib/book[3]/title | root(fn:exactly-one(/bib/book[3]/title))", ctx); try { query.context(node(file("op/union/bib2.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<!-- this file is a copy of bib.xml; just adds a few comments and PI nodes for testing --><!-- Comment 1 --><?PI1 Processing Instruction 1?><bib>\n <book year=\"1994\">\n <title>TCP/IP Illustrated</title>\n <author><last>Stevens</last><first>W.</first></author>\n <publisher>Addison-Wesley</publisher>\n <price> 65.95</price>\n </book>\n \n <book year=\"1992\">\n <title>Advanced Programming in the Unix environment</title>\n <author><last>Stevens</last><first>W.</first></author>\n <publisher>Addison-Wesley</publisher>\n <price>65.95</price>\n </book>\n \n <book year=\"2000\">\n <title>Data on the Web</title>\n <author><last>Abiteboul</last><first>Serge</first></author>\n <author><last>Buneman</last><first>Peter</first></author>\n <author><last>Suciu</last><first>Dan</first></author>\n <publisher>Morgan Kaufmann Publishers</publisher>\n <price> 39.95</price>\n </book>\n \n <book year=\"1999\">\n <title>The Economics of Technology and Content for Digital TV</title>\n <editor>\n <last>Gerbarg</last><first>Darcy</first>\n <affiliation>CITI</affiliation>\n </editor>\n <publisher>Kluwer Academic Publishers</publisher>\n <price>129.95</price>\n </book>\n</bib><!-- Comment 2 --><?PI2 Processing Instruction 2?><title>Data on the Web</title>", false)); }
/** * Simple combination of node sequences involving integers and the empty sequence. Uses "union" * operator . */ @org.junit.Test public void combiningnodeseqhc6() { final XQuery query = new XQuery("for $h in ( () union (//hours)) order by number($h) return $h", ctx); try { query.context(node(file("docs/works.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<hours>12</hours><hours>20</hours><hours>20</hours><hours>20</hours><hours>20</hours><hours>20</hours><hours>20</hours><hours>40</hours><hours>40</hours><hours>40</hours><hours>80</hours><hours>80</hours><hours>80</hours>", false)); }
/** . */ @org.junit.Test public void treeQueriesResultsQ5() { final XQuery query = new XQuery( "<section_list> { for $s in //section let $f := $s/figure return <section title=\"{ $s/title/text() }\" figcount=\"{ count($f) }\"/> } </section_list>", ctx); try { query.context(node(file("docs/book.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<section_list><section title=\"Introduction\" figcount=\"0\"/><section title=\"Audience\" figcount=\"0\"/><section title=\"Web Data and the Two Cultures\" figcount=\"1\"/><section title=\"A Syntax For Data\" figcount=\"1\"/><section title=\"Base Types\" figcount=\"0\"/><section title=\"Representing Relational Databases\" figcount=\"1\"/><section title=\"Representing Object Databases\" figcount=\"0\"/></section_list>", false)); }
/** Explicitly sort the result of a union expression. . */ @org.junit.Test public void k2SeqUnion45() { final XQuery query = new XQuery( " <r> { //(employee[location = \"Denver\"] union //employee[last()])/./location } </r>", ctx); try { query.context(node(file("op/union/acme_corp.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<r><location>Denver</location><location>Denver</location><location>Denver</location><location>Boston</location></r>", false)); }
/** . */ @org.junit.Test public void treeQueriesResultsQ2() { final XQuery query = new XQuery( "<figlist> { for $f in //figure return <figure> { $f/@* } { $f/title } </figure> } </figlist>", ctx); try { query.context(node(file("docs/book.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( assertSerialization( "<figlist><figure height=\"400\" width=\"400\"><title>Traditional client/server architecture</title></figure><figure height=\"200\" width=\"500\"><title>Graph representations of structures</title></figure><figure height=\"250\" width=\"400\"><title>Examples of Relations</title></figure></figlist>", false)); }
/** get the employees who worked the maximum number of hours . */ @org.junit.Test public void foldLeft008() { final XQuery query = new XQuery( "\n" + " let $hours := function ($emp as element(employee)) as xs:integer { sum($emp/hours/xs:integer(.)) },\n" + " $highest := function ($f as function(item()) as xs:anyAtomicType, $seq as item()*) { \n" + " fold-left(\n" + " function($highestSoFar as item()*, $this as item()*) as item()* {\n" + " if (empty($highestSoFar))\n" + " then $this\n" + " else let $thisValue := $f($this),\n" + " $highestValue := $f($highestSoFar[1])\n" + " return if ($thisValue gt $highestValue)\n" + " then $this\n" + " else if ($thisValue eq $highestValue)\n" + " then ($highestSoFar, $this)\n" + " else $highestSoFar\n" + " }, (), $seq)\n" + " }\n" + " \n" + " return $highest($hours, /works/employee) \n" + " ", ctx); try { query.context(node(file("docs/works-mod.xml"))); result = new QT3Result(query.value()); } catch (final Throwable trw) { result = new QT3Result(trw); } finally { query.close(); } test( (assertCount(1) && assertType("element(employee)") && assertQuery("$result/@name = \"John Doe 2\""))); }