use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class Base64BinaryTest method castToBase64ThenBackToString.
@Test
public void castToBase64ThenBackToString() throws XMLDBException {
final String base64String = "QWxhZGRpbjpvcGVuIHNlc2FtZQ==";
final String query = "let $data := '" + base64String + "' cast as xs:base64Binary return $data cast as xs:string";
final XQueryService service = (XQueryService) server.getRoot().getService("XQueryService", "1.0");
final ResourceSet result = service.query(query);
final String queryResult = (String) result.getResource(0).getContent();
assertEquals(base64String, queryResult);
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class XQueryTest method globalVars.
@Test
public void globalVars() throws XMLDBException {
Collection testCollection = getTestCollection();
Resource doc = testCollection.createResource(MODULE5_NAME, "BinaryResource");
doc.setContent(module5);
((EXistResource) doc).setMimeType("application/xquery");
testCollection.storeResource(doc);
doc = testCollection.createResource(MODULE6_NAME, "BinaryResource");
doc.setContent(module6);
((EXistResource) doc).setMimeType("application/xquery");
testCollection.storeResource(doc);
XQueryService service = (XQueryService) testCollection.getService("XPathQueryService", "1.0");
String query = "xquery version \"1.0\";\n" + "import module namespace foo=\"foo\" at \"" + URI + "/test/" + MODULE5_NAME + "\";\n" + "$foo:bar";
ResourceSet result = service.query(query);
assertEquals(result.getSize(), 1);
assertEquals(result.getResource(0).getContent(), "bar");
query = "xquery version \"1.0\";\n" + "declare variable $local:a := 'abc';" + "$local:a";
result = service.query(query);
assertEquals(result.getSize(), 1);
assertEquals(result.getResource(0).getContent(), "abc");
boolean gotException = false;
try {
query = "xquery version \"1.0\";\n" + "import module namespace foo=\"foo\" at \"" + URI + "/test/" + MODULE6_NAME + "\";\n" + "$foo:bar";
result = service.query(query);
} catch (XMLDBException e) {
assertTrue("Test should generate err:XQST0049, got: " + e.getMessage(), e.getMessage().indexOf("err:XQST0049") > -1);
gotException = true;
}
assertTrue("Duplicate global variable should generate error", gotException);
gotException = false;
try {
query = "xquery version \"1.0\";\n" + "declare variable $local:a := 'abc';" + "declare variable $local:a := 'abc';" + "$local:a";
result = service.query(query);
} catch (XMLDBException e) {
assertTrue("Test should generate err:XQST0049, got: " + e.getMessage(), e.getMessage().indexOf("err:XQST0049") > -1);
gotException = true;
}
assertTrue("Duplicate global variable should generate error", gotException);
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class OptimizerTest method execute.
private void execute(String query, boolean optimize, String message, long expected) throws XMLDBException {
XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
if (optimize) {
query = NAMESPACES + OPTIMIZE + query;
} else {
query = NAMESPACES + NO_OPTIMIZE + query;
}
ResourceSet result = service.query(query);
assertEquals(message, expected, result.getSize());
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class OptimizerTest method execute.
private long execute(String query, boolean optimize) throws XMLDBException {
XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
if (optimize) {
query = OPTIMIZE + query;
} else {
query = NO_OPTIMIZE + query;
}
query = NAMESPACES + query;
ResourceSet result = service.query(query);
return result.getSize();
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class UpdateInsertTest method insertNamespacedAttribute.
@Test
public void insertNamespacedAttribute() throws XMLDBException {
final String docName = "pathNs2.xml";
final XQueryService service = storeXMLStringAndGetQueryService(docName, "<test/>");
queryResource(service, docName, "//t[@xml:id]", 0);
String update = "update insert <t xml:id=\"id1\"/> into /test";
queryResource(service, docName, update, 0);
queryResource(service, docName, "//t[@xml:id eq 'id1']", 1);
queryResource(service, docName, "/test/id('id1')", 1);
update = "update value //t/@xml:id with 'id2'";
queryResource(service, docName, update, 0);
queryResource(service, docName, "//t[@xml:id eq 'id2']", 1);
queryResource(service, docName, "id('id2', /test)", 1);
}
Aggregations