Search in sources :

Example 36 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class SystemExportFiltersTest method exportImport.

@Test
public void exportImport() throws Exception {
    Path file;
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        List<String> filters = new ArrayList<>();
        filters.add(FilterForBackup.class.getName());
        broker.getConfiguration().setProperty(SystemExport.CONFIG_FILTERS, filters);
        final Collection test = broker.getCollection(TEST_COLLECTION_URI);
        assertNotNull(test);
        boolean direct = true;
        final SystemExport sysexport = new SystemExport(broker, transaction, null, null, direct);
        final Path backupDir = tempFolder.newFolder().toPath();
        file = sysexport.export(backupDir.toAbsolutePath().toString(), false, false, null);
        transaction.commit();
    }
    TestUtils.cleanupDB();
    final SystemImport restore = new SystemImport(pool);
    final RestoreListener listener = new LogRestoreListener();
    restore.restore(TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD, null, file, listener);
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Collection test = broker.getCollection(TEST_COLLECTION_URI);
        assertNotNull(test);
        DocumentImpl doc = getDoc(broker, test, doc01uri.lastSegment());
        assertEquals(XML1_BACKUP, serializer(broker, doc));
        doc = getDoc(broker, test, doc02uri.lastSegment());
        assertEquals(XML2_PROPER, serializer(broker, doc));
        doc = getDoc(broker, test, doc03uri.lastSegment());
        assertEquals(XML3_PROPER, serializer(broker, doc));
        doc = getDoc(broker, test, doc11uri.lastSegment());
        assertTrue(doc instanceof BinaryDocument);
        try (final InputStream is = broker.getBinaryResource(transaction, ((BinaryDocument) doc))) {
            assertEquals(BINARY, InputStreamUtil.readString(is, UTF_8));
        }
        transaction.commit();
    }
}
Also used : Path(java.nio.file.Path) LogRestoreListener(org.exist.backup.restore.listener.LogRestoreListener) InputStream(java.io.InputStream) Txn(org.exist.storage.txn.Txn) DocumentImpl(org.exist.dom.persistent.DocumentImpl) BinaryDocument(org.exist.dom.persistent.BinaryDocument) DBBroker(org.exist.storage.DBBroker) Collection(org.exist.collections.Collection) LogRestoreListener(org.exist.backup.restore.listener.LogRestoreListener) RestoreListener(org.exist.backup.restore.listener.RestoreListener) BrokerPool(org.exist.storage.BrokerPool)

Example 37 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class HistoryTriggerTest method setup.

@Before
public void setup() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool brokerPool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
        final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
        // create and store the collection.xconf for the test collection
        Collection configCollection = broker.getOrCreateCollection(transaction, TEST_CONFIG_COLLECTION_URI);
        broker.saveCollection(transaction, configCollection);
        broker.storeDocument(transaction, CollectionConfiguration.DEFAULT_COLLECTION_CONFIG_FILE_URI, new StringInputSource(COLLECTION_CONFIG), MimeType.XML_TYPE, configCollection);
        // create the test collection
        Collection testCollection = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI);
        broker.saveCollection(transaction, testCollection);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Example 38 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class HistoryTriggerTest method checkHistoryOfOriginal.

private void checkHistoryOfOriginal(final BrokerPool brokerPool, final XmldbURI originalDocName, final String orginalDocContent) throws EXistException, PermissionDeniedException, LockException {
    try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
        final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
        try (final Collection historyCollection = broker.openCollection(HistoryTrigger.DEFAULT_ROOT_PATH.append(TEST_COLLECTION_URI).append(originalDocName), Lock.LockMode.READ_LOCK)) {
            assertNotNull(historyCollection);
            final DocumentSet documentSet = historyCollection.getDocuments(broker, new DefaultDocumentSet());
            assertEquals(1, documentSet.getDocumentCount());
            final Iterator<DocumentImpl> it = documentSet.getDocumentIterator();
            assertTrue(it.hasNext());
            final DocumentImpl doc = it.next();
            final Diff diff = DiffBuilder.compare(Input.from(orginalDocContent)).withTest(Input.from(doc)).build();
            assertFalse(diff.toString(), diff.hasDifferences());
            assertFalse(it.hasNext());
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) Diff(org.xmlunit.diff.Diff) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) DocumentSet(org.exist.dom.persistent.DocumentSet) DocumentImpl(org.exist.dom.persistent.DocumentImpl)

Example 39 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class HistoryTriggerTest method storeInTestCollection.

private void storeInTestCollection(final Txn transaction, final DBBroker broker, final XmldbURI docName, final String docContent) throws PermissionDeniedException, LockException, SAXException, EXistException, IOException {
    try (final Collection testCollection = broker.openCollection(TEST_COLLECTION_URI, Lock.LockMode.WRITE_LOCK)) {
        assertNotNull(testCollection);
        broker.storeDocument(transaction, docName, new StringInputSource(docContent), MimeType.XML_TYPE, testCollection);
    }
}
Also used : StringInputSource(org.exist.util.StringInputSource) Collection(org.exist.collections.Collection)

Example 40 with Collection

use of org.exist.collections.Collection in project exist by eXist-db.

the class AbstractXMLReaderSecurityTest method removeTestData.

@After
public void removeTestData() throws EXistException, PermissionDeniedException, IOException, TriggerException {
    final BrokerPool brokerPool = getExistEmbeddedServer().getBrokerPool();
    try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
        final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
        final Collection testCollection = broker.getCollection(TEST_COLLECTION);
        if (testCollection != null && !broker.removeCollection(transaction, testCollection)) {
            transaction.abort();
            fail("Unable to remove test collection");
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Aggregations

Collection (org.exist.collections.Collection)297 Txn (org.exist.storage.txn.Txn)160 XmldbURI (org.exist.xmldb.XmldbURI)99 DBBroker (org.exist.storage.DBBroker)89 TransactionManager (org.exist.storage.txn.TransactionManager)86 BrokerPool (org.exist.storage.BrokerPool)69 StringInputSource (org.exist.util.StringInputSource)57 Test (org.junit.Test)57 EXistException (org.exist.EXistException)43 PermissionDeniedException (org.exist.security.PermissionDeniedException)43 DocumentImpl (org.exist.dom.persistent.DocumentImpl)42 IOException (java.io.IOException)33 LockedDocument (org.exist.dom.persistent.LockedDocument)31 SAXException (org.xml.sax.SAXException)26 InputStream (java.io.InputStream)19 Path (java.nio.file.Path)19 Permission (org.exist.security.Permission)19 LockException (org.exist.util.LockException)16 TriggerException (org.exist.collections.triggers.TriggerException)15 BinaryDocument (org.exist.dom.persistent.BinaryDocument)15