use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method modulesAndNS.
@Test
public void modulesAndNS() throws XMLDBException, IOException, SAXException {
Collection testCollection = getTestCollection();
Resource doc = testCollection.createResource(MODULE7_NAME, "BinaryResource");
doc.setContent(module7);
((EXistResource) doc).setMimeType("application/xquery");
testCollection.storeResource(doc);
XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
service.setProperty(OutputKeys.INDENT, "no");
String query = "xquery version \"1.0\";\n" + "import module namespace foo=\"foo\" at \"" + URI + "/test/" + MODULE7_NAME + "\";\n" + "<div xmlns='http://www.w3.org/1999/xhtml'>" + "{ foo:link() }" + "</div>";
ResourceSet result = service.query(query);
assertEquals(1, result.getSize());
result.getResource(0).getContent();
assertXMLEqual("<div xmlns='http://www.w3.org/1999/xhtml'><a xmlns=\"\" href='#'>Link</a></div>", result.getResource(0).getContent().toString());
query = "xquery version \"1.0\";\n" + "import module namespace foo=\"foo\" at \"" + URI + "/test/" + MODULE7_NAME + "\";\n" + "<div xmlns='http://www.w3.org/1999/xhtml'>" + "{ foo:copy(<a>Link</a>) }" + "</div>";
result = service.query(query);
assertEquals(1, result.getSize());
result.getResource(0).getContent();
assertXMLEqual("<div xmlns='http://www.w3.org/1999/xhtml'><a>Link</a></div>", result.getResource(0).getContent().toString());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method attributeForNoResult.
/**
* Tests that no result will be returned if an attribute's value is selected on a node which wasn't found
*/
@Test
public void attributeForNoResult() throws XMLDBException {
String query = //
"let $a := <a><b>-1</b><b>-2</b></a> " + "return /a[./c]/@id/string()";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
assertEquals(0, result.getSize());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method wrongAttributeTypeCheck_1805612.
/**
* Regression
*
* @see http://sourceforge.net/support/tracker.php?aid=1805612
*
* Same as {@link #asDouble_1840775()}
*/
@Ignore
@Test
public void wrongAttributeTypeCheck_1805612() throws XMLDBException {
// OK
String query = "declare namespace tst = \"http://test\"; " + "declare function tst:foo($a as element()?) { $a }; " + "tst:foo( <result/> )";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
assertEquals(1, result.getSize());
assertEquals(query, "<result/>", result.getResource(0).getContent().toString());
// NOK
query = "declare namespace tst = \"http://test\"; " + "declare function tst:foo($a as element()?) { $a }; " + "tst:foo( " + " let $a as xs:boolean := true() " + " return <result/> " + ")";
service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
result = service.query(query);
assertEquals(1, result.getSize());
assertEquals(query, "<result/>", result.getResource(0).getContent().toString());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method largeAttributeKeywordOperator.
@Test
public void largeAttributeKeywordOperator() throws XMLDBException {
ResourceSet result;
String query;
@SuppressWarnings("unused") XMLResource resu;
String large = createXMLContentWithLargeString();
XPathQueryService service = storeXMLStringAndGetQueryService(file_name, xml);
query = "doc('" + file_name + "') / details/metadata[ @docid = '" + large + "' ]";
result = service.queryResource(file_name, query);
assertEquals("XQuery: " + query, nbElem, result.getSize());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method attributeNamespace.
@Test
public void attributeNamespace() throws XMLDBException {
String query = "declare function local:copy($nodes as node()*) as node()* {" + "for $n in $nodes return " + "if ($n instance of element()) then " + " element {node-name($n)} {(local:copy($n/@*), local:copy($n/node()))} " + "else if ($n instance of attribute()) then " + " attribute {node-name($n)} {$n} " + "else if ($n instance of text()) then " + " text {$n} " + "else " + " <Other/>" + "};" + "let $c :=" + "<c:C xmlns:c=\"http://c\" xmlns:d=\"http://d\" d:d=\"ddd\">" + "ccc" + "</c:C>" + "return local:copy($c)";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
assertEquals(1, result.getSize());
assertEquals("<c:C xmlns:c=\"http://c\" xmlns:d=\"http://d\" d:d=\"ddd\">" + "ccc" + "</c:C>", result.getResource(0).getContent().toString());
}
Aggregations