use of org.exist.xmldb.IndexQueryService in project exist by eXist-db.
the class TriggerConfigTest method removeTriggers.
@Test
public void removeTriggers() {
try {
Collection root = DatabaseManager.getCollection(BASE_URI + testCollection, "admin", "");
IndexQueryService iqs = (IndexQueryService) root.getService("IndexQueryService", "1.0");
iqs.configureCollection(EMPTY_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.query("if (doc-available('" + testCollection + "/messages.xml')) then doc('" + testCollection + "/messages.xml')/events/event[@id = 'STORE-DOCUMENT'] else ()");
assertEquals("No trigger should have fired. Configuration was removed", 0, result.getSize());
} catch (XMLDBException e) {
LOG.error(e.getMessage(), e);
fail(e.getMessage());
}
}
use of org.exist.xmldb.IndexQueryService in project exist by eXist-db.
the class XQueryTriggerTest method storeDocument_invalidTriggerForPrepare.
@Test
public void storeDocument_invalidTriggerForPrepare() throws XMLDBException {
final BinaryResource invalidModule = (BinaryResource) testCollection.createResource(MODULE_NAME, "BinaryResource");
((EXistResource) invalidModule).setMimeType("application/xquery");
invalidModule.setContent(INVALID_MODULE.getBytes());
testCollection.storeResource(invalidModule);
// configure the Collection with the trigger under test
final IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
idxConf.configureCollection(COLLECTION_CONFIG);
final int max_store_attempts = 10;
int count_prepare_exceptions = 0;
for (int i = 0; i < max_store_attempts; i++) {
try {
// this will fire the trigger
final XMLResource doc = (XMLResource) testCollection.createResource(DOCUMENT_NAME, "XMLResource");
doc.setContent(DOCUMENT_CONTENT);
testCollection.storeResource(doc);
} catch (XMLDBException xdbe) {
if (xdbe.getCause() instanceof TriggerException) {
if (xdbe.getCause().getMessage().equals(XQueryTrigger.PREPARE_EXCEPTION_MESSAGE)) {
count_prepare_exceptions++;
}
}
}
}
assertEquals(max_store_attempts, count_prepare_exceptions);
}
use of org.exist.xmldb.IndexQueryService in project exist by eXist-db.
the class XQueryTriggerTest method collectionCopy.
/**
* test a trigger fired by a Collection manipulations
*/
@Test
public void collectionCopy() throws XMLDBException, URISyntaxException {
final IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
idxConf.configureCollection(COLLECTION_CONFIG);
final XmldbURI srcURI = XmldbURI.xmldbUriFor("/db/testXQueryTrigger/test");
final XmldbURI dstURI = XmldbURI.xmldbUriFor("/db/testXQueryTrigger/test-dst");
final EXistCollectionManagementService service = (EXistCollectionManagementService) testCollection.getService("CollectionManagementService", "1.0");
final Collection src = service.createCollection("test");
assertNotNull(src);
final Collection dst = service.createCollection("test-dst");
assertNotNull(dst);
service.copy(srcURI, dstURI, null);
// remove the trigger for the Collection under test
idxConf.configureCollection(EMPTY_COLLECTION_CONFIG);
ResourceSet result = existEmbeddedServer.executeQuery(BEFORE + CREATE + COLLECTION + testCollectionURI);
assertEquals(1, result.getSize());
result = existEmbeddedServer.executeQuery(AFTER + CREATE + COLLECTION + testCollectionURI);
assertEquals(1, result.getSize());
result = existEmbeddedServer.executeQuery(BEFORE + CREATE + COLLECTION + testDstCollectionURI);
assertEquals(1, result.getSize());
result = existEmbeddedServer.executeQuery(AFTER + CREATE + COLLECTION + testDstCollectionURI);
assertEquals(1, result.getSize());
result = existEmbeddedServer.executeQuery(BEFORE + COPY + COLLECTION + testCollectionURI);
assertEquals(1, result.getSize());
result = existEmbeddedServer.executeQuery(AFTER + COPY + COLLECTION + testDstTestCollectionURI);
assertEquals(1, result.getSize());
result = existEmbeddedServer.executeQuery(EVENTS);
assertEquals(6, result.getSize());
}
use of org.exist.xmldb.IndexQueryService in project exist by eXist-db.
the class XQueryTriggerTest method documentUpdate.
/**
* test a trigger fired by a Document Update
*/
@Test
public void documentUpdate() 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);
// TODO : trigger UPDATE events !
final XUpdateQueryService update = (XUpdateQueryService) testCollection.getService("XUpdateQueryService", "1.0");
update.updateResource(DOCUMENT_NAME, DOCUMENT_UPDATE);
idxConf.configureCollection(EMPTY_COLLECTION_CONFIG);
final XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
// this is necessary to compare with MODIFIED_DOCUMENT_CONTENT ; TODO better compare with XML diff tool
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 + UPDATE + DOCUMENT + documentURI);
assertEquals(1, result.getSize());
result = service.query(AFTER + UPDATE + DOCUMENT + documentURI);
assertEquals(1, result.getSize());
result = service.query(EVENTS);
assertEquals(4, result.getSize());
// TODO: document itself
// result = service.query("/events/event[@id = 'trigger2']/document/test");
// assertEquals(2, result.getSize());
// assertXMLEqual(DOCUMENT_CONTENT, result.getResource(0).getContent().toString());
// assertXMLEqual(MODIFIED_DOCUMENT_CONTENT, result.getResource(1).getContent().toString());
}
use of org.exist.xmldb.IndexQueryService in project exist by eXist-db.
the class XQueryTriggerTest method collectionCreate.
/**
* test a trigger fired by a Collection manipulations
*/
@Test
public void collectionCreate() throws XMLDBException {
final IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
idxConf.configureCollection(COLLECTION_CONFIG);
final CollectionManagementService service = (CollectionManagementService) testCollection.getService("CollectionManagementService", "1.0");
final Collection collection = service.createCollection("test");
assertNotNull(collection);
// remove the trigger for the Collection under test
idxConf.configureCollection(EMPTY_COLLECTION_CONFIG);
final XPathQueryService query = (XPathQueryService) existEmbeddedServer.getRoot().getService("XPathQueryService", "1.0");
ResourceSet result = query.query(BEFORE + CREATE + COLLECTION + testCollectionURI);
assertEquals(1, result.getSize());
result = query.query(AFTER + CREATE + COLLECTION + testCollectionURI);
assertEquals(1, result.getSize());
result = query.query(EVENTS);
assertEquals(2, result.getSize());
}
Aggregations