Search in sources :

Example 11 with XPathQueryService

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

the class CollectionConfigurationTest method invalidConfiguration1.

@Test
public void invalidConfiguration1() throws XMLDBException {
    Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
    CollectionManagementService cms = (CollectionManagementService) testCollection.getService("CollectionManagementService", "1.0");
    Collection sub2 = cms.createCollection(COLLECTION_SUB2.toString());
    UserManagementService ums = (UserManagementService) sub2.getService("UserManagementService", "1.0");
    ums.chmod("rwxr-xr-x");
    IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(INVALID_CONFIG1);
    // ... then index document
    XMLResource doc = (XMLResource) sub2.createResource(TestConstants.TEST_XML_URI.toString(), "XMLResource");
    doc.setContent(DOCUMENT_CONTENT);
    sub2.storeResource(doc);
    XPathQueryService service = (XPathQueryService) sub2.getService("XPathQueryService", "1.0");
    // index should be empty since configuration was invalid
    ResourceSet result = service.query("util:index-key-occurrences(/test/a, 1)");
    assertEquals(0, result.getSize());
    result = service.query("util:qname-index-lookup(xs:QName(\"a\"), 1 ) ");
    assertEquals(0, result.getSize());
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) XPathQueryService(org.xmldb.api.modules.XPathQueryService) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 12 with XPathQueryService

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

the class XQueryTriggerTest method documentBinaryCreate.

/**
 * test a trigger fired by creating a new Binary Document
 */
@Test
public void documentBinaryCreate() throws XMLDBException {
    // configure the Collection with the trigger under test
    final IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(COLLECTION_CONFIG);
    // this will fire the trigger
    final Resource res = testCollection.createResource(BINARY_DOCUMENT_NAME, "BinaryResource");
    final byte[] content = Base64.decodeBase64(BINARY_DOCUMENT_CONTENT);
    res.setContent(content);
    testCollection.storeResource(res);
    // remove the trigger for the Collection under test
    idxConf.configureCollection(EMPTY_COLLECTION_CONFIG);
    final XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    // TODO : understand why it is necessary !
    service.setProperty(OutputKeys.INDENT, "no");
    ResourceSet result = service.query(BEFORE + CREATE + DOCUMENT + binaryURI);
    assertEquals(1, result.getSize());
    result = service.query(AFTER + CREATE + DOCUMENT + binaryURI);
    assertEquals(1, result.getSize());
    result = service.query(EVENTS);
    assertEquals(2, result.getSize());
// TODO: document itself
// result = service.query("/events/event[@id = 'trigger1'][@type = 'finish'][collection = '" + DBBroker.ROOT_COLLECTION +  "/" + TEST_COLLECTION + "'][uri = '" + DBBroker.ROOT_COLLECTION +  "/" + TEST_COLLECTION + "/" + BINARY_DOCUMENT_NAME + "'][event = 'CREATE-DOCUMENT']/document");
// assertEquals(1, result.getSize());
// assertEquals("<document>" + BINARY_DOCUMENT_CONTENT + "</document>", result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService) EXistResource(org.exist.xmldb.EXistResource) BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 13 with XPathQueryService

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

the class XQueryTriggerTest method documentDelete.

/**
 * test a trigger fired by a Document Delete
 */
@Test
public void documentDelete() throws XMLDBException {
    final IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(COLLECTION_CONFIG);
    final XMLResource doc = (XMLResource) testCollection.createResource(DOCUMENT_NAME, "XMLResource");
    doc.setContent(DOCUMENT_CONTENT);
    testCollection.storeResource(doc);
    testCollection.removeResource(testCollection.getResource(DOCUMENT_NAME));
    idxConf.configureCollection(EMPTY_COLLECTION_CONFIG);
    final XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    service.setProperty(OutputKeys.INDENT, "no");
    ResourceSet result = service.query(BEFORE + CREATE + DOCUMENT + documentURI);
    assertEquals(1, result.getSize());
    result = service.query(AFTER + CREATE + DOCUMENT + documentURI);
    assertEquals(1, result.getSize());
    result = service.query(BEFORE + DELETE + DOCUMENT + documentURI);
    assertEquals(1, result.getSize());
    result = service.query(AFTER + DELETE + DOCUMENT + documentURI);
    assertEquals(1, result.getSize());
    result = service.query(EVENTS);
    assertEquals(4, result.getSize());
// TODO: document itself
// result = service.query("/events/event[@id = 'trigger3']/document/test");
// assertEquals(1, result.getSize());
// assertXMLEqual(MODIFIED_DOCUMENT_CONTENT, result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 14 with XPathQueryService

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

the class XQueryTriggerTest method documentBinaryDelete.

/**
 * test a trigger fired by a Binary Document Delete
 */
@Test
public void documentBinaryDelete() throws XMLDBException {
    final IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(COLLECTION_CONFIG);
    // this will fire the trigger
    final Resource res = testCollection.createResource(BINARY_DOCUMENT_NAME, "BinaryResource");
    final byte[] content = Base64.decodeBase64(BINARY_DOCUMENT_CONTENT);
    res.setContent(content);
    testCollection.storeResource(res);
    testCollection.removeResource(testCollection.getResource(BINARY_DOCUMENT_NAME));
    idxConf.configureCollection(EMPTY_COLLECTION_CONFIG);
    final XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    service.setProperty(OutputKeys.INDENT, "no");
    ResourceSet result = service.query(BEFORE + CREATE + DOCUMENT + binaryURI);
    assertEquals(1, result.getSize());
    result = service.query(AFTER + CREATE + DOCUMENT + binaryURI);
    assertEquals(1, result.getSize());
    result = service.query(BEFORE + DELETE + DOCUMENT + binaryURI);
    assertEquals(1, result.getSize());
    result = service.query(AFTER + DELETE + DOCUMENT + binaryURI);
    assertEquals(1, result.getSize());
    result = service.query(EVENTS);
    assertEquals(4, result.getSize());
// TODO: document itself
// result = service.query("/events/event[@id = 'trigger3'][@type = 'prepare'][collection = '" + DBBroker.ROOT_COLLECTION +  "/" + TEST_COLLECTION + "'][uri = '" + DBBroker.ROOT_COLLECTION +  "/" + TEST_COLLECTION + "/" + BINARY_DOCUMENT_NAME + "'][event = 'DELETE-DOCUMENT']/document");
// assertEquals(1, result.getSize());
// assertEquals("<document>" + BINARY_DOCUMENT_CONTENT + "</document>", result.getResource(0).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService) EXistResource(org.exist.xmldb.EXistResource) BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 15 with XPathQueryService

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

the class XQueryTriggerTest method documentCreate.

/**
 * test a trigger fired by storing a new Document
 */
@Test
public void documentCreate() throws XMLDBException {
    // configure the Collection with the trigger under test
    final IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(COLLECTION_CONFIG);
    // this will fire the trigger
    final XMLResource doc = (XMLResource) testCollection.createResource(DOCUMENT_NAME, "XMLResource");
    doc.setContent(DOCUMENT_CONTENT);
    testCollection.storeResource(doc);
    // remove the trigger for the Collection under test
    idxConf.configureCollection(EMPTY_COLLECTION_CONFIG);
    final XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
    ResourceSet result = service.query(BEFORE + CREATE + DOCUMENT + documentURI);
    assertEquals(1, result.getSize());
    result = service.query(AFTER + CREATE + DOCUMENT + documentURI);
    assertEquals(1, result.getSize());
    result = service.query(EVENTS);
    assertEquals(2, result.getSize());
// TODO: document itself
// result = service.query(afterCreate+objDocument+documentURI+"/document/test");
// assertEquals(1, result.getSize());
// assertXMLEqual(DOCUMENT_CONTENT, ((XMLResource)result.getResource(0)).getContent().toString());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Aggregations

XPathQueryService (org.xmldb.api.modules.XPathQueryService)148 ResourceSet (org.xmldb.api.base.ResourceSet)123 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)92 XMLResource (org.xmldb.api.modules.XMLResource)60 Collection (org.xmldb.api.base.Collection)31 Test (org.junit.Test)22 Resource (org.xmldb.api.base.Resource)18 XMLDBException (org.xmldb.api.base.XMLDBException)14 EXistResource (org.exist.xmldb.EXistResource)10 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)9 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)8 IndexQueryService (org.exist.xmldb.IndexQueryService)6 IOException (java.io.IOException)3 ResourceIterator (org.xmldb.api.base.ResourceIterator)3 BinaryResource (org.xmldb.api.modules.BinaryResource)3 MalformedURLException (java.net.MalformedURLException)2 Path (java.nio.file.Path)2 Node (org.w3c.dom.Node)2 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1