use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method evalLoosesContext_1740891.
/**
* @see http://sourceforge.net/support/tracker.php?aid=1740891
*/
@Test
public void evalLoosesContext_1740891() throws XMLDBException {
String module = "module namespace tst = \"urn:test\"; " + "declare namespace util = \"http://exist-db.org/xquery/util\";" + "declare function tst:bar() as element(Bar)* { " + "let $foo := <Foo><Bar/><Bar/><Bar/></Foo> " + "let $query := \"$foo/Bar\" " + "let $bar := util:eval($query) " + "return $bar };";
String module_name = "module.xqy";
Resource doc;
// Store module
Collection testCollection = getTestCollection();
doc = testCollection.createResource(module_name, "BinaryResource");
doc.setContent(module);
((EXistResource) doc).setMimeType("application/xquery");
testCollection.storeResource(doc);
String query = "import module namespace tst = \"urn:test\"" + "at \"xmldb:exist:///db/test/module.xqy\"; " + "tst:bar()";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
assertEquals(3, result.getSize());
assertEquals("First", "<Bar/>", result.getResource(0).getContent().toString());
assertEquals("Second", "<Bar/>", result.getResource(1).getContent().toString());
assertEquals("Third", "<Bar/>", result.getResource(2).getContent().toString());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method functionDoc.
@Test
public void functionDoc() throws XMLDBException, IOException, SAXException {
ResourceSet result;
String query;
@SuppressWarnings("unused") boolean exceptionThrown;
@SuppressWarnings("unused") String message;
XPathQueryService service = storeXMLStringAndGetQueryService(NUMBERS_XML, numbers);
query = "doc('" + XmldbURI.ROOT_COLLECTION + "/test/" + NUMBERS_XML + "')";
result = service.query(query);
assertEquals("XQuery: " + query, 1, result.getSize());
Node n = ((XMLResource) result.getResource(0)).getContentAsDOM();
DetailedDiff d = new DetailedDiff(compareXML(numbers, n.toString()));
assertEquals(0, d.getAllDifferences().size());
// ignore eXist namespace's attributes
// assertEquals(1, d.getAllDifferences().size());
query = "let $v := ()\n" + "return doc($v)";
result = service.query(query);
assertEquals("XQuery: " + query, 0, result.getSize());
query = "doc('" + XmldbURI.ROOT_COLLECTION + "/test/dummy" + NUMBERS_XML + "')";
try {
exceptionThrown = false;
result = service.query(query);
} catch (XMLDBException e) {
exceptionThrown = true;
message = e.getMessage();
}
// TODO : to be decided !
// assertTrue(exceptionThrown);
assertEquals(0, result.getSize());
query = "doc-available('" + XmldbURI.ROOT_COLLECTION + "/test/" + NUMBERS_XML + "')";
result = service.query(query);
assertEquals("XQuery: " + query, 1, result.getSize());
assertEquals("XQuery: " + query, "true", result.getResource(0).getContent());
query = "let $v := ()\n" + "return doc-available($v)";
result = service.query(query);
assertEquals("XQuery: " + query, 1, result.getSize());
assertEquals("XQuery: " + query, "false", result.getResource(0).getContent());
query = "doc-available('" + XmldbURI.ROOT_COLLECTION + "/test/dummy" + NUMBERS_XML + "')";
assertEquals("XQuery: " + query, 1, result.getSize());
assertEquals("XQuery: " + query, "false", result.getResource(0).getContent());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XQueryTest method attribute_1691177.
/**
* @see http://sourceforge.net/tracker/index.php?func=detail&aid=1691177&group_id=17691&atid=117691
*/
@Test
public void attribute_1691177() throws XMLDBException {
String query = "declare namespace xmldb = \"http://exist-db.org/xquery/xmldb\"; " + "let $uri := xmldb:store(\"/db\", \"insertAttribDoc.xml\", <C/>) " + "let $node := doc($uri)/element() " + "let $attrib := <Value f=\"ATTRIB VALUE\"/>/@* " + "return update insert $attrib into $node ";
XPathQueryService service = (XPathQueryService) getTestCollection().getService("XPathQueryService", "1.0");
ResourceSet result = service.query(query);
assertEquals("XQuery: " + query, 0, result.getSize());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class ValueIndexByQNameTest method strings.
@Test
@Override
public void strings() throws XMLDBException, URISyntaxException {
configureCollection(config);
XPathQueryService service = storeXMLFileAndGetQueryService(ITEMS_FILENAME, ITEMS_FILE);
// queryResource(service, "items.xml", "//item[name > 'Racing Bicycle']", 4 );
queryResource(service, "items.xml", "util:qname-index-lookup( xs:QName('name'), 'Racing Bicycle' ) / parent::item", 1);
queryResource(service, "items.xml", "util:qname-index-lookup( xs:QName('itemno'), 3) / parent::item", 1);
queryResource(service, "items.xml", "declare namespace xx='http://test.com'; " + "util:qname-index-lookup( xs:QName('xx:test'), 123, false() )", 1);
// queryResource(service, "items.xml", "//item[name &= 'Racing Bicycle']", 1);
// queryResource(service, "items.xml", "//item[mixed = 'uneven']", 1);
queryResource(service, "items.xml", "util:qname-index-lookup( xs:QName('mixed'), 'external' )", 1);
// queryResource(service, "items.xml", "//item[fn:matches(mixed, 'un.*')]", 2);
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class RemoveAppendTest method testRemoveAppend.
@Ignore
@Test
public void testRemoveAppend() throws Exception {
XUpdateQueryService service = (XUpdateQueryService) testCol.getService("XUpdateQueryService", "1.0");
XPathQueryService query = (XPathQueryService) testCol.getService("XPathQueryService", "1.0");
for (int i = 1; i < 1000; i++) {
int which = rand.nextInt(ITEM_COUNT) + 1;
insert(service, which);
remove(service, which);
ResourceSet result = query.query("/test/item[@id='" + which + "']");
assertEquals(result.getSize(), 1);
result.getResource(0).getContent();
}
}
Aggregations