use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.
the class AbstractDescendantOrSelfNodeKindTest method documentNodeCount.
@Test
public void documentNodeCount() throws XMLDBException {
final ResourceSet result = executeQueryOnDoc("count($doc//document-node())");
assertEquals(1, result.getSize());
assertEquals(0, Integer.parseInt((String) result.getResource(0).getContent()));
}
use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.
the class AbstractDescendantOrSelfNodeKindTest method textCount.
@Test
public void textCount() throws XMLDBException {
final ResourceSet result = executeQueryOnDoc("count($doc//text())");
assertEquals(1, result.getSize());
assertEquals(14, Integer.parseInt((String) result.getResource(0).getContent()));
}
use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.
the class AnnotationsTest method annotationWithLiterals.
@Test
public void annotationWithLiterals() throws XMLDBException {
final String TEST_VALUE_CONSTANT = "hello world";
final String query = "declare namespace hello = 'http://world.com';\n" + "declare\n" + "%hello:world('a=b', 'b=c')\n" + "function local:hello() {\n" + "'" + TEST_VALUE_CONSTANT + "'\n" + "};\n" + "local:hello()";
final XPathQueryService service = getQueryService();
final ResourceSet result = service.query(query);
assertEquals(1, result.getSize());
Resource res = result.getIterator().nextResource();
assertEquals(TEST_VALUE_CONSTANT, res.getContent());
}
use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.
the class ConstructedNodesTest method iterateConstructNodes.
/**
* Iteratively constructs some nodes
*/
@Test
public void iterateConstructNodes() throws XPathException, XMLDBException {
String xquery = "declare variable $categories := \n" + " <categories>\n" + " <category uid=\"1\">Fruit</category>\n" + " <category uid=\"2\">Vegetable</category>\n" + " <category uid=\"3\">Meat</category>\n" + " <category uid=\"4\">Dairy</category>\n" + " </categories>\n" + ";\n\n" + "for $category in $categories/category return\n" + " element option {\n" + " attribute value {\n" + " $category/@uid\n" + " },\n" + " text { $category }\n" + " }";
String[] expectedResults = { "<option value=\"1\">Fruit</option>", "<option value=\"2\">Vegetable</option>", "<option value=\"3\">Meat</option>", "<option value=\"4\">Dairy</option>" };
ResourceSet result = existEmbeddedServer.executeQuery(xquery);
assertEquals(expectedResults.length, result.getSize());
for (int i = 0; i < result.getSize(); i++) {
assertEquals(expectedResults[i], result.getResource(i).getContent());
}
}
use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.
the class ConstructedNodesTest method constructedNodesSort.
/**
* Test sorting of constructed nodes
*/
@Test
public void constructedNodesSort() throws XMLDBException {
String xquery = "declare variable $categories := \n" + " <categories>\n" + " <category uid=\"1\">Fruit</category>\n" + " <category uid=\"2\">Vegetable</category>\n" + " <category uid=\"3\">Meat</category>\n" + " <category uid=\"4\">Dairy</category>\n" + " </categories>\n" + ";\n\n" + "for $category in $categories/category order by $category/@uid descending return $category";
String[] expectedResults = { "<category uid=\"4\">Dairy</category>", "<category uid=\"3\">Meat</category>", "<category uid=\"2\">Vegetable</category>", "<category uid=\"1\">Fruit</category>" };
ResourceSet result = existEmbeddedServer.executeQuery(xquery);
assertEquals(expectedResults.length, result.getSize());
for (int i = 0; i < result.getSize(); i++) {
assertEquals(expectedResults[i], result.getResource(i).getContent());
}
}
Aggregations