Search in sources :

Example 56 with ResourceSet

use of org.xmldb.api.base.ResourceSet 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 57 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class XQueryTriggerTest method collectionMove.

/**
 * test a trigger fired by a Collection manipulations
 */
@Test
public void collectionMove() throws XMLDBException, URISyntaxException {
    final IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(COLLECTION_CONFIG);
    final XmldbURI srcURI = XmldbURI.xmldbUriFor("/db/testXQueryTrigger/test");
    final XmldbURI dstURI = XmldbURI.xmldbUriFor("/db/testXQueryTrigger/test-dst");
    final EXistCollectionManagementService service = (EXistCollectionManagementService) testCollection.getService("CollectionManagementService", "1.0");
    final Collection src = service.createCollection("test");
    assertNotNull(src);
    final Collection dst = service.createCollection("test-dst");
    assertNotNull(dst);
    service.move(srcURI, dstURI, null);
    // remove the trigger for the Collection under test
    idxConf.configureCollection(EMPTY_COLLECTION_CONFIG);
    ResourceSet result = existEmbeddedServer.executeQuery(BEFORE + CREATE + COLLECTION + testCollectionURI);
    assertEquals(1, result.getSize());
    result = existEmbeddedServer.executeQuery(AFTER + CREATE + COLLECTION + testCollectionURI);
    assertEquals(1, result.getSize());
    result = existEmbeddedServer.executeQuery(BEFORE + CREATE + COLLECTION + testDstCollectionURI);
    assertEquals(1, result.getSize());
    result = existEmbeddedServer.executeQuery(AFTER + CREATE + COLLECTION + testDstCollectionURI);
    assertEquals(1, result.getSize());
    result = existEmbeddedServer.executeQuery(BEFORE + MOVE + COLLECTION + testCollectionURI);
    assertEquals(1, result.getSize());
    result = existEmbeddedServer.executeQuery(AFTER + MOVE + COLLECTION + testDstTestCollectionURI);
    assertEquals(1, result.getSize());
    result = existEmbeddedServer.executeQuery(EVENTS);
    assertEquals(6, result.getSize());
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) IndexQueryService(org.exist.xmldb.IndexQueryService) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet) XmldbURI(org.exist.xmldb.XmldbURI)

Example 58 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class XQueryTriggerTest method collectionDelete.

/**
 * test a trigger fired by a Collection manipulations
 */
@Test
public void collectionDelete() throws XMLDBException {
    final IndexQueryService idxConf = (IndexQueryService) testCollection.getService("IndexQueryService", "1.0");
    idxConf.configureCollection(COLLECTION_CONFIG);
    final CollectionManagementService service = (CollectionManagementService) testCollection.getService("CollectionManagementService", "1.0");
    final Collection collection = service.createCollection("test");
    assertNotNull(collection);
    service.removeCollection("test");
    // remove the trigger for the Collection under test
    idxConf.configureCollection(EMPTY_COLLECTION_CONFIG);
    ResourceSet result = existEmbeddedServer.executeQuery(BEFORE + CREATE + COLLECTION + testCollectionURI);
    assertEquals(1, result.getSize());
    result = existEmbeddedServer.executeQuery(AFTER + CREATE + COLLECTION + testCollectionURI);
    assertEquals(1, result.getSize());
    result = existEmbeddedServer.executeQuery(BEFORE + DELETE + COLLECTION + testCollectionURI);
    assertEquals(1, result.getSize());
    result = existEmbeddedServer.executeQuery(AFTER + DELETE + COLLECTION + testCollectionURI);
    assertEquals(1, result.getSize());
    result = existEmbeddedServer.executeQuery("/events/event");
    assertEquals(4, result.getSize());
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) IndexQueryService(org.exist.xmldb.IndexQueryService) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 59 with ResourceSet

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

Example 60 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class FilterInputStreamCacheMonitorTest method binaryResult.

@Test
public void binaryResult() throws XMLDBException {
    final FilterInputStreamCacheMonitor monitor = FilterInputStreamCacheMonitor.getInstance();
    // assert no binaries in use yet
    int activeCount = monitor.getActive().size();
    if (activeCount != 0) {
        fail("FilterInputStreamCacheMonitor should have no active binaries, but found: " + activeCount + "." + System.getProperty("line.separator") + monitor.dump());
    }
    ResourceSet resourceSet = null;
    try {
        resourceSet = existXmldbEmbeddedServer.executeQuery("util:binary-doc('/db/" + TEST_COLLECTION_NAME + "/icon.png')");
        assertEquals(1, resourceSet.getSize());
        try (final EXistResource resource = (EXistResource) resourceSet.getResource(0)) {
            assertTrue(resource instanceof LocalBinaryResource);
            assertTrue(((ExtendedResource) resource).getExtendedContent() instanceof BinaryValue);
            // one active binary (as it is in the result set)
            assertEquals(1, monitor.getActive().size());
        }
        // assert no active binaries as we just closed the resource in the try-with-resources
        activeCount = monitor.getActive().size();
        if (activeCount != 0) {
            fail("FilterInputStreamCacheMonitor should again have no active binaries, but found: " + activeCount + "." + System.getProperty("line.separator") + monitor.dump());
        }
    } finally {
        resourceSet.clear();
    }
}
Also used : EXistResource(org.exist.xmldb.EXistResource) LocalBinaryResource(org.exist.xmldb.LocalBinaryResource) ExtendedResource(org.exist.xmldb.ExtendedResource) BinaryValue(org.exist.xquery.value.BinaryValue) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Aggregations

ResourceSet (org.xmldb.api.base.ResourceSet)383 XPathQueryService (org.xmldb.api.modules.XPathQueryService)123 Test (org.junit.Test)117 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)100 XMLResource (org.xmldb.api.modules.XMLResource)80 Collection (org.xmldb.api.base.Collection)55 Resource (org.xmldb.api.base.Resource)45 XQueryService (org.xmldb.api.modules.XQueryService)29 XMLDBException (org.xmldb.api.base.XMLDBException)23 EXistResource (org.exist.xmldb.EXistResource)20 BinaryResource (org.xmldb.api.modules.BinaryResource)17 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)14 Node (org.w3c.dom.Node)11 IndexQueryService (org.exist.xmldb.IndexQueryService)9 Diff (org.xmlunit.diff.Diff)9 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)8 UserManagementService (org.exist.xmldb.UserManagementService)8 Source (javax.xml.transform.Source)7 ResourceIterator (org.xmldb.api.base.ResourceIterator)7 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)6