Search in sources :

Example 1 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class SerializationTest method xqueryUpdateNsTest.

@Test
public void xqueryUpdateNsTest() throws XMLDBException {
    final XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
    final ResourceSet result = service.query("xquery version \"1.0\";" + EOL + "declare namespace foo=\"http://foo.com\";" + EOL + "let $in-memory :=" + EOL + XML + EOL + "let $on-disk := doc('/db/" + TEST_COLLECTION_NAME + '/' + XML_DOC_NAME + "')" + EOL + "let $new-node := <entry xml:id='aargh'/>" + EOL + "let $update := update insert $new-node into $on-disk/foo:root" + EOL + "return" + EOL + "    (" + EOL + "        $in-memory," + EOL + "        $on-disk" + EOL + "    )" + EOL);
    assertEquals(2, result.getSize());
    final Resource inMemoryResource = result.getResource(0);
    assertXMLEquals(XML, inMemoryResource);
    final Resource onDiskResource = result.getResource(1);
    assertXMLEquals(XML_UPDATED_EXPECTED, onDiskResource);
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 2 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class AbstractTestUpdate method storeXMLStringAndGetQueryService.

/**
 * stores XML String and get Query Service
 * @param documentName to be stored in the DB
 * @param content to be stored in the DB
 * @return the XQuery Service
 * @throws XMLDBException
 */
protected XQueryService storeXMLStringAndGetQueryService(final String documentName, final String content) throws XMLDBException {
    final XMLResource doc = (XMLResource) testCollection.createResource(documentName, "XMLResource");
    doc.setContent(content);
    testCollection.storeResource(doc);
    final XQueryService service = (XQueryService) testCollection.getService("XPathQueryService", "1.0");
    return service;
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) XMLResource(org.xmldb.api.modules.XMLResource)

Example 3 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class TriggerConfigTest method updateTriggers.

@Test
public void updateTriggers() {
    try {
        Collection root = DatabaseManager.getCollection(BASE_URI + testCollection, "admin", "");
        IndexQueryService iqs = (IndexQueryService) root.getService("IndexQueryService", "1.0");
        iqs.configureCollection(EMPTY_COLLECTION_CONFIG);
        Collection configCol = DatabaseManager.getCollection(BASE_URI + "/db/system/config" + testCollection, "admin", "");
        Resource resource = configCol.createResource(DEFAULT_COLLECTION_CONFIG_FILE, "XMLResource");
        resource.setContent(COLLECTION_CONFIG);
        configCol.storeResource(resource);
        resource = root.createResource("data.xml", "XMLResource");
        resource.setContent(DOCUMENT_CONTENT);
        root.storeResource(resource);
        XQueryService qs = (XQueryService) root.getService("XQueryService", "1.0");
        ResourceSet result = qs.query("if (doc-available('" + testCollection + "/messages.xml')) then doc('" + testCollection + "/messages.xml')/events/event[@id = 'STORE-DOCUMENT']/string(@collection) else ()");
        assertEquals(1, result.getSize());
        assertEquals(testCollection, result.getResource(0).getContent());
    } catch (XMLDBException e) {
        LOG.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService)

Example 4 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class TriggerConfigTest method storeDocument.

@Test
public void storeDocument() {
    try {
        Collection root = DatabaseManager.getCollection(BASE_URI + testCollection, "admin", "");
        IndexQueryService iqs = (IndexQueryService) root.getService("IndexQueryService", "1.0");
        iqs.configureCollection(COLLECTION_CONFIG);
        Resource resource = root.createResource("data.xml", "XMLResource");
        resource.setContent(DOCUMENT_CONTENT);
        root.storeResource(resource);
        XQueryService qs = (XQueryService) root.getService("XQueryService", "1.0");
        ResourceSet result = qs.queryResource("messages.xml", "string(//event[last()]/@collection)");
        assertEquals(1, result.getSize());
        assertEquals(testCollection, result.getResource(0).getContent());
    } catch (XMLDBException e) {
        LOG.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService)

Example 5 with XQueryService

use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.

the class TriggerConfigTest method removeDocument.

@Test
public void removeDocument() {
    try {
        Collection root = DatabaseManager.getCollection(BASE_URI + testCollection, "admin", "");
        IndexQueryService iqs = (IndexQueryService) root.getService("IndexQueryService", "1.0");
        iqs.configureCollection(COLLECTION_CONFIG);
        Resource resource = root.createResource("data.xml", "XMLResource");
        resource.setContent(DOCUMENT_CONTENT);
        root.storeResource(resource);
        root.removeResource(resource);
        XQueryService qs = (XQueryService) root.getService("XQueryService", "1.0");
        ResourceSet result = qs.queryResource("messages.xml", "string(//event[last()]/@collection)");
        assertEquals(1, result.getSize());
        assertEquals(testCollection, result.getResource(0).getContent());
    } catch (XMLDBException e) {
        LOG.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService)

Aggregations

XQueryService (org.xmldb.api.modules.XQueryService)129 EXistXQueryService (org.exist.xmldb.EXistXQueryService)71 XMLResource (org.xmldb.api.modules.XMLResource)33 ResourceSet (org.xmldb.api.base.ResourceSet)29 Test (org.junit.Test)28 Resource (org.xmldb.api.base.Resource)8 Node (org.w3c.dom.Node)6 EXistResource (org.exist.xmldb.EXistResource)5 Document (org.w3c.dom.Document)5 Collection (org.xmldb.api.base.Collection)5 Source (javax.xml.transform.Source)4 IndexQueryService (org.exist.xmldb.IndexQueryService)4 CompiledExpression (org.xmldb.api.base.CompiledExpression)4 XMLDBException (org.xmldb.api.base.XMLDBException)4 Diff (org.xmlunit.diff.Diff)4 Path (java.nio.file.Path)2 XmlRpcTest (org.exist.xmlrpc.XmlRpcTest)2 StringWriter (java.io.StringWriter)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1