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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations