use of org.xmldb.api.modules.BinaryResource in project exist by eXist-db.
the class LoginModuleTest method afterClass.
@AfterClass
public static void afterClass() throws XMLDBException {
final BinaryResource res = (BinaryResource) root.getResource(XQUERY_FILENAME);
root.removeResource(res);
}
use of org.xmldb.api.modules.BinaryResource 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());
}
use of org.xmldb.api.modules.BinaryResource 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());
}
use of org.xmldb.api.modules.BinaryResource in project exist by eXist-db.
the class XQueryTriggerTest method setup.
/**
* create "log" document that will be updated by the trigger,
* and store the XQuery module implementing the trigger under test
*/
@Before
public void setup() throws XMLDBException {
final CollectionManagementService service = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
testCollection = service.createCollection(TEST_COLLECTION);
assertNotNull(testCollection);
final XMLResource doc = (XMLResource) testCollection.createResource(LOG_NAME, "XMLResource");
doc.setContent(EMPTY_LOG);
testCollection.storeResource(doc);
final BinaryResource module = (BinaryResource) testCollection.createResource(MODULE_NAME, "BinaryResource");
((EXistResource) module).setMimeType("application/xquery");
module.setContent(MODULE.getBytes());
testCollection.storeResource(module);
}
use of org.xmldb.api.modules.BinaryResource in project exist by eXist-db.
the class StoredModuleTest method writeModule.
private void writeModule(Collection collection, String modulename, String module) throws XMLDBException {
BinaryResource res = (BinaryResource) collection.createResource(modulename, "BinaryResource");
((EXistResource) res).setMimeType("application/xquery");
res.setContent(module.getBytes());
collection.storeResource(res);
collection.close();
}
Aggregations