use of org.exist.xmldb.IndexQueryService in project exist by eXist-db.
the class AbstractTestUpdate method setUp.
@Before
public void setUp() throws Exception {
final CollectionManagementService service = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
testCollection = service.createCollection("test");
final IndexQueryService idx = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
idx.configureCollection(XCONF);
}
use of org.exist.xmldb.IndexQueryService 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());
}
}
use of org.exist.xmldb.IndexQueryService 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());
}
}
use of org.exist.xmldb.IndexQueryService 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());
}
}
use of org.exist.xmldb.IndexQueryService 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());
}
Aggregations