Search in sources :

Example 6 with BinaryResource

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);
}
Also used : BinaryResource(org.xmldb.api.modules.BinaryResource) AfterClass(org.junit.AfterClass)

Example 7 with BinaryResource

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());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService) EXistResource(org.exist.xmldb.EXistResource) BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 8 with BinaryResource

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());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) IndexQueryService(org.exist.xmldb.IndexQueryService) EXistResource(org.exist.xmldb.EXistResource) BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 9 with BinaryResource

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);
}
Also used : EXistResource(org.exist.xmldb.EXistResource) CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource)

Example 10 with BinaryResource

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();
}
Also used : EXistResource(org.exist.xmldb.EXistResource) BinaryResource(org.xmldb.api.modules.BinaryResource)

Aggregations

BinaryResource (org.xmldb.api.modules.BinaryResource)25 XMLResource (org.xmldb.api.modules.XMLResource)13 EXistResource (org.exist.xmldb.EXistResource)11 Resource (org.xmldb.api.base.Resource)11 Test (org.junit.Test)8 Collection (org.xmldb.api.base.Collection)8 UserManagementService (org.exist.xmldb.UserManagementService)7 ResourceSet (org.xmldb.api.base.ResourceSet)7 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)6 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)5 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)4 Path (java.nio.file.Path)3 IndexQueryService (org.exist.xmldb.IndexQueryService)3 AfterClass (org.junit.AfterClass)3 BeforeClass (org.junit.BeforeClass)3 XMLDBException (org.xmldb.api.base.XMLDBException)2 XPathQueryService (org.xmldb.api.modules.XPathQueryService)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1