Search in sources :

Example 96 with ResourceSet

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

Example 97 with ResourceSet

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

Example 98 with ResourceSet

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

Example 99 with ResourceSet

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

Example 100 with ResourceSet

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

Aggregations

ResourceSet (org.xmldb.api.base.ResourceSet)383 XPathQueryService (org.xmldb.api.modules.XPathQueryService)123 Test (org.junit.Test)117 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)100 XMLResource (org.xmldb.api.modules.XMLResource)80 Collection (org.xmldb.api.base.Collection)55 Resource (org.xmldb.api.base.Resource)45 XQueryService (org.xmldb.api.modules.XQueryService)29 XMLDBException (org.xmldb.api.base.XMLDBException)23 EXistResource (org.exist.xmldb.EXistResource)20 BinaryResource (org.xmldb.api.modules.BinaryResource)17 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)14 Node (org.w3c.dom.Node)11 IndexQueryService (org.exist.xmldb.IndexQueryService)9 Diff (org.xmlunit.diff.Diff)9 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)8 UserManagementService (org.exist.xmldb.UserManagementService)8 Source (javax.xml.transform.Source)7 ResourceIterator (org.xmldb.api.base.ResourceIterator)7 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)6