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