use of org.exist.util.StringInputSource in project exist by eXist-db.
the class ModificationTimeTest method storeBinary.
private BinaryDocument storeBinary(final DBBroker broker, final Txn transaction, final String name, final String data, final String mimeType) throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
final Collection root = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI);
broker.saveCollection(transaction, root);
assertNotNull(root);
root.storeDocument(transaction, broker, XmldbURI.create(name), new StringInputSource(data.getBytes(UTF_8)), new MimeType(mimeType, MimeType.BINARY));
return (BinaryDocument) root.getDocument(broker, XmldbURI.create(name));
}
use of org.exist.util.StringInputSource in project exist by eXist-db.
the class JournalXmlTest method largeJournalEntry_corrupt.
@Test
public void largeJournalEntry_corrupt() throws IllegalAccessException, EXistException, NoSuchFieldException, LockException, SAXException, PermissionDeniedException, IOException, InterruptedException {
checkpointJournalAndSwitchFile();
// generate a string filled with random a-z characters which is larger than the journal buffer
// 3 * the journal buffer size
final byte[] buf = new byte[Journal.BUFFER_SIZE * 3];
final Random random = new Random();
for (int i = 0; i < buf.length; i++) {
final byte singleByteChar = (byte) ('a' + random.nextInt('z' - 'a' - 1));
buf[i] = singleByteChar;
}
final String largeText = new String(buf, UTF_8);
final String xml = "<large-text>" + largeText + "</large-text>";
final InputSource source = new StringInputSource(xml);
source.setEncoding("UTF-8");
BrokerPool.FORCE_CORRUPTION = true;
final TxnDoc<String> stored = store(COMMIT, source, "large-non-corrupt.xml");
flushJournal();
// shutdown the broker pool (without destroying the data dir)
existEmbeddedServer.getBrokerPool().shutdown();
// reset the corruption flag back to normal
BrokerPool.FORCE_CORRUPTION = false;
// check journal entries written for store
assertPartialOrdered(store_expected(stored, 0, largeText), readLatestJournalEntries());
}
use of org.exist.util.StringInputSource in project exist by eXist-db.
the class GetXMLResourceNoLockTest method storeTestResource.
private void storeTestResource() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
final BrokerPool pool = BrokerPool.getInstance();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
final Collection collection = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
broker.saveCollection(transaction, collection);
broker.storeDocument(transaction, DOCUMENT_NAME_URI, new StringInputSource(EMPTY_BINARY_FILE.getBytes(UTF_8)), MimeType.TEXT_TYPE, collection);
transact.commit(transaction);
}
}
use of org.exist.util.StringInputSource in project exist by eXist-db.
the class InspectModuleTest method setup.
@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final Collection testCollection = broker.getOrCreateCollection(transaction, TEST_COLLECTION);
broker.storeDocument(transaction, TEST_MODULE, new StringInputSource(MODULE.getBytes(UTF_8)), MimeType.XQUERY_TYPE, testCollection);
broker.saveCollection(transaction, testCollection);
transaction.commit();
}
}
use of org.exist.util.StringInputSource in project exist by eXist-db.
the class XQueryDeclareContextItemTest method setup.
@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(root);
broker.saveCollection(transaction, root);
broker.storeDocument(transaction, XmldbURI.create("sysevent.xml"), new StringInputSource(SYSEVENT_XML), MimeType.XML_TYPE, root);
transaction.commit();
}
}
Aggregations