Search in sources :

Example 11 with EXistXQueryService

use of org.exist.xmldb.EXistXQueryService in project exist by eXist-db.

the class InternalModuleTest method moduleVariables.

@Test
public void moduleVariables() throws XMLDBException {
    final Source querySource = new StringSource(getModuleVariableQuery("org.exist.xquery.InternalModuleTest$TestModuleWithVariables"));
    final EXistXQueryService queryService = (EXistXQueryService) existServer.getRoot().getService("XQueryService", "1.0");
    moduleVariablesQuery(queryService, querySource, COUNTER.get());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) StringSource(org.exist.source.StringSource) StringSource(org.exist.source.StringSource) Source(org.exist.source.Source) Test(org.junit.Test)

Example 12 with EXistXQueryService

use of org.exist.xmldb.EXistXQueryService in project exist by eXist-db.

the class XPathQueryTest method compile.

@Test
public void compile() throws XMLDBException {
    final String invalidQuery = "for $i in (1 to 10)\n return $b";
    final String validQuery = "for $i in (1 to 10) return $i";
    final String validModule = "module namespace foo=\"urn:foo\";\n" + "declare function foo:test() { \"Hello World!\" };";
    final String invalidModule = "module namespace foo=\"urn:foo\";\n" + "declare function foo:test() { \"Hello World! };";
    final EXistXQueryService service = (EXistXQueryService) getQueryService();
    boolean exceptionOccurred = false;
    try {
        service.compile(invalidQuery);
    } catch (XMLDBException e) {
        assertEquals(((XPathException) e.getCause()).getLine(), 2);
        exceptionOccurred = true;
    }
    assertTrue("Expected an exception", exceptionOccurred);
    exceptionOccurred = false;
    try {
        service.compileAndCheck(invalidModule);
    } catch (XPathException e) {
        exceptionOccurred = true;
    }
    assertTrue("Expected an exception", exceptionOccurred);
    service.compile(validQuery);
    service.compile(validModule);
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService)

Example 13 with EXistXQueryService

use of org.exist.xmldb.EXistXQueryService in project exist by eXist-db.

the class ConcurrencyTest method xupdateDocs.

private void xupdateDocs(final String collectionName) throws XMLDBException, IOException, URISyntaxException {
    storeDocs(collectionName);
    final EXistXQueryService xqs = (EXistXQueryService) test.getService("XQueryService", "1.0");
    ResourceSet result = xqs.query("//SPEECH[ft:query(SPEAKER, 'juliet')]");
    assertEquals(118, result.getSize());
    final String xupdate = LuceneIndexTest.XUPDATE_START + "   <xu:remove select=\"//SPEECH[ft:query(SPEAKER, 'juliet')]\"/>" + LuceneIndexTest.XUPDATE_END;
    final XUpdateQueryService xuqs = (XUpdateQueryService) test.getService("XUpdateQueryService", "1.0");
    xuqs.update(xupdate);
    result = xqs.query("//SPEECH[ft:query(SPEAKER, 'juliet')]");
    assertEquals(0, result.getSize());
    result = xqs.query("//SPEECH[ft:query(LINE, 'king')]");
    assertEquals(98, result.getSize());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XUpdateQueryService(org.xmldb.api.modules.XUpdateQueryService) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 14 with EXistXQueryService

use of org.exist.xmldb.EXistXQueryService in project exist by eXist-db.

the class ConcurrencyTest method storeRemoveDocs.

private void storeRemoveDocs(final String collectionName) throws XMLDBException, IOException, URISyntaxException {
    storeDocs(collectionName);
    final EXistXQueryService xqs = (EXistXQueryService) test.getService("XQueryService", "1.0");
    ResourceSet result = xqs.query("//SPEECH[ft:query(LINE, 'king')]");
    assertEquals(98, result.getSize());
    result = xqs.query("//SPEECH[ft:query(SPEAKER, 'juliet')]");
    assertEquals(118, result.getSize());
    final String[] resources = test.listResources();
    for (int i = 0; i < resources.length; i++) {
        final Resource resource = test.getResource(resources[i]);
        test.removeResource(resource);
    }
    result = xqs.query("//SPEECH[ft:query(LINE, 'king')]");
    assertEquals(0, result.getSize());
    result = xqs.query("//SPEECH[ft:query(SPEAKER, 'juliet')]");
    assertEquals(0, result.getSize());
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet)

Aggregations

EXistXQueryService (org.exist.xmldb.EXistXQueryService)14 StringSource (org.exist.source.StringSource)6 Source (org.exist.source.Source)5 Test (org.junit.Test)4 BuildException (org.apache.tools.ant.BuildException)2 QName (org.exist.dom.QName)2 ResourceSet (org.xmldb.api.base.ResourceSet)2 XMLDBException (org.xmldb.api.base.XMLDBException)2 XMLResource (org.xmldb.api.modules.XMLResource)2 IOException (java.io.IOException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)1 PropertyHelper (org.apache.tools.ant.PropertyHelper)1 FileSet (org.apache.tools.ant.types.FileSet)1 Sequence (org.exist.xquery.value.Sequence)1 Collection (org.xmldb.api.base.Collection)1 Resource (org.xmldb.api.base.Resource)1 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)1