use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class UnionTest method unionPersistentAndConstructedNodes.
@Test
public void unionPersistentAndConstructedNodes() throws XMLDBException {
final XQueryService service = storeXMLStringAndGetQueryService(PUBMED_DOC_NAME, PUBMED);
final String xquery = "doc('" + testCollection.getName() + "/" + PUBMED_DOC_NAME + "')//Language | <a/> | <b/>";
final ResourceSet results = service.query(xquery);
assertEquals(3, results.getSize());
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class UnionTest method storeXMLStringAndGetQueryService.
private XQueryService storeXMLStringAndGetQueryService(String documentName, String content) throws XMLDBException {
final XMLResource doc = (XMLResource) testCollection.createResource(documentName, "XMLResource");
doc.setContent(content);
testCollection.storeResource(doc);
final XQueryService service = (XQueryService) testCollection.getService("XPathQueryService", "1.0");
return service;
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class ConstructedNodesTest method constructedTextNodes.
/**
* Test storing constructed (text) nodes
* Tests absence of bug #2646744 which gave err:XPTY0018 for $hello-text-first
* cf org.exist.xquery.XQueryTest.testXPTY0018_mixedsequences_2429093()
*/
@Test
public void constructedTextNodes() throws XMLDBException {
String xquery = "declare variable $hello-text-first := <a>{ \"hello\" }<b>world</b></a>;\n" + "declare variable $hello-text-last := <a><b>world</b>{ \"hello\" }</a>;\n" + "($hello-text-first, $hello-text-last)";
String[] expectedResults = { "<a>hello<b>world</b></a>", "<a><b>world</b>hello</a>" };
final XQueryService xpathQueryService = (XQueryService) existEmbeddedServer.getRoot().getService("XQueryService", "1.0");
String oki = xpathQueryService.getProperty(OutputKeys.INDENT);
xpathQueryService.setProperty(OutputKeys.INDENT, "no");
ResourceSet result = xpathQueryService.query(xquery);
assertEquals(expectedResults.length, result.getSize());
for (int i = 0; i < result.getSize(); i++) {
assertEquals(expectedResults[i], result.getResource(i).getContent());
}
// Restore indent property to ensure test atomicity
xpathQueryService.setProperty(OutputKeys.INDENT, oki);
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class XPathQueryTest method ancestorIndex.
@Test
public void ancestorIndex() throws XMLDBException {
final XQueryService service = storeXMLStringAndGetQueryService("nested2.xml", nested2);
queryResource(service, "nested2.xml", "//ChildB/ancestor::*[1]/self::ChildA", 1);
queryResource(service, "nested2.xml", "//ChildB/ancestor::*[2]/self::RootElement", 1);
queryResource(service, "nested2.xml", "//ChildB/ancestor::*[position() = 1]/self::ChildA", 1);
queryResource(service, "nested2.xml", "//ChildB/ancestor::*[position() = 2]/self::RootElement", 1);
queryResource(service, "nested2.xml", "//ChildB/ancestor::*[position() = 2]/self::RootElement", 1);
queryResource(service, "nested2.xml", "(<a/>, <b/>, <c/>)/ancestor::*", 0);
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class XPathQueryTest method cardinalitySelf_bug_wiki_2.
/**
* removing Self: makes the query work OK
* @see http://wiki.exist-db.org/space/XQueryBugs
*/
@Test
public void cardinalitySelf_bug_wiki_2() throws XMLDBException {
final String xQuery = "let $test := <test><works><employee>a</employee><employee>b</employee></works></test> " + "for $h in $test/works/employee[2] return fn:name($h/self::employee)";
final XQueryService service = getQueryService();
final ResourceSet rs = service.query(xQuery);
assertEquals("CardinalitySelfBUG bug wiki_2", 1, rs.getSize());
assertEquals("CardinalitySelfBUG bug wiki_2", "employee", rs.getResource(0).getContent().toString());
}
Aggregations