Search in sources :

Example 76 with XQueryService

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());
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 77 with XQueryService

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;
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) XMLResource(org.xmldb.api.modules.XMLResource)

Example 78 with XQueryService

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);
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 79 with XQueryService

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);
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Example 80 with XQueryService

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());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XQueryService(org.xmldb.api.modules.XQueryService)

Aggregations

XQueryService (org.xmldb.api.modules.XQueryService)129 EXistXQueryService (org.exist.xmldb.EXistXQueryService)71 XMLResource (org.xmldb.api.modules.XMLResource)33 ResourceSet (org.xmldb.api.base.ResourceSet)29 Test (org.junit.Test)28 Resource (org.xmldb.api.base.Resource)8 Node (org.w3c.dom.Node)6 EXistResource (org.exist.xmldb.EXistResource)5 Document (org.w3c.dom.Document)5 Collection (org.xmldb.api.base.Collection)5 Source (javax.xml.transform.Source)4 IndexQueryService (org.exist.xmldb.IndexQueryService)4 CompiledExpression (org.xmldb.api.base.CompiledExpression)4 XMLDBException (org.xmldb.api.base.XMLDBException)4 Diff (org.xmlunit.diff.Diff)4 Path (java.nio.file.Path)2 XmlRpcTest (org.exist.xmlrpc.XmlRpcTest)2 StringWriter (java.io.StringWriter)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1