use of org.xmldb.api.modules.XMLResource 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.XMLResource 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.XMLResource 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());
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class ProtectedModeTest method setupDb.
@BeforeClass
public static void setupDb() throws XMLDBException, SAXException {
CollectionManagementService mgmt = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
final Collection collection = mgmt.createCollection("protected");
mgmt = (CollectionManagementService) collection.getService("CollectionManagementService", "1.0");
final TestDataGenerator generator = new TestDataGenerator("xdb", DOCUMENT_COUNT);
for (int i = 0; i < COLLECTION_COUNT; i++) {
Collection currentColl = mgmt.createCollection("test" + i);
final Path[] files = generator.generate(currentColl, generateXQ);
for (int j = 0; j < files.length; j++) {
final XMLResource resource = (XMLResource) currentColl.createResource("xdb" + j + ".xml", "XMLResource");
resource.setContent(files[j].toFile());
currentColl.storeResource(resource);
}
}
}
use of org.xmldb.api.modules.XMLResource in project exist by eXist-db.
the class NodeTypeTest method load.
/**
* Loads the xml document identified by <code>document</code> from the database.
*
* @param document the document to load
*/
@SuppressWarnings("unused")
private Node load(final String document) throws XMLDBException {
final StringBuilder query = new StringBuilder();
query.append("let $result := doc(string-join(('" + XmldbURI.ROOT_COLLECTION + "', $document), '/'))");
query.append("return ($result)");
final XQueryService service = (XQueryService) server.getRoot().getService("XQueryService", "1.0");
service.declareVariable("document", document);
final CompiledExpression cQuery = service.compile(query.toString());
final ResourceSet set = service.execute(cQuery);
if (set != null && set.getSize() > 0) {
return ((XMLResource) set.getIterator().nextResource()).getContentAsDOM();
}
return null;
}
Aggregations