use of org.exist.util.StringInputSource in project exist by eXist-db.
the class MoveResourceRecoveryTest method store.
private void store() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException, URISyntaxException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
final Collection test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(test);
broker.saveCollection(transaction, test);
final Collection test2 = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI2);
assertNotNull(test2);
broker.saveCollection(transaction, test2);
final String sample;
try (final InputStream is = SAMPLES.getRomeoAndJulietSample()) {
sample = InputStreamUtil.readString(is, UTF_8);
}
broker.storeDocument(transaction, TestConstants.TEST_XML_URI, new StringInputSource(sample), MimeType.XML_TYPE, test2);
final DocumentImpl doc = test2.getDocument(broker, TestConstants.TEST_XML_URI);
assertNotNull(doc);
broker.moveResource(transaction, doc, test, XmldbURI.create("new_test.xml"));
broker.saveCollection(transaction, test);
transact.commit(transaction);
}
}
use of org.exist.util.StringInputSource in project exist by eXist-db.
the class MoveCollectionRecoveryTest method store.
private void store() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
final Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(root);
broker.saveCollection(transaction, root);
final Collection test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI2);
assertNotNull(test);
broker.saveCollection(transaction, test);
final String sample;
try (final InputStream is = SAMPLES.getBiblioSample()) {
assertNotNull(is);
sample = InputStreamUtil.readString(is, UTF_8);
}
broker.storeDocument(transaction, TestConstants.TEST_XML_URI, new StringInputSource(sample), MimeType.XML_TYPE, test);
final Collection dest = broker.getOrCreateCollection(transaction, TestConstants.DESTINATION_COLLECTION_URI);
assertNotNull(dest);
broker.saveCollection(transaction, dest);
broker.moveCollection(transaction, test, dest, XmldbURI.create("test3"));
transact.commit(transaction);
}
}
use of org.exist.util.StringInputSource in project exist by eXist-db.
the class MarshallerTest method startDB.
@BeforeClass
public static void startDB() throws EXistException, DatabaseConfigurationException, PermissionDeniedException, IOException, SAXException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
final Collection root = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI);
broker.saveCollection(transaction, root);
broker.storeDocument(transaction, XmldbURI.create("test.xml"), new StringInputSource(TEST_DOC), MimeType.XML_TYPE, root);
transact.commit(transaction);
}
}
use of org.exist.util.StringInputSource in project exist by eXist-db.
the class ResourceTest method setContentAsSourceXml.
@Test
public void setContentAsSourceXml() throws XMLDBException, SAXException, IOException, XpathException {
final Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
assertNotNull(testCollection);
final XMLResource doc = (XMLResource) testCollection.createResource("source.xml", "XMLResource");
final String xml = "<test><title>Title1</title>" + "<para>Paragraph3</para>" + "<para>Paragraph4</para>" + "</test>";
doc.setContent(new StringInputSource(xml));
testCollection.storeResource(doc);
final XMLResource newDoc = (XMLResource) testCollection.getResource("source.xml");
final String newDocXml = (String) newDoc.getContent();
assertXpathEvaluatesTo("Title1", "/test/title/text()", newDocXml);
assertXpathEvaluatesTo("2", "count(/test/para)", newDocXml);
assertXpathEvaluatesTo("Paragraph3", "/test/para[1]/text()", newDocXml);
assertXpathEvaluatesTo("Paragraph4", "/test/para[2]/text()", newDocXml);
}
use of org.exist.util.StringInputSource in project exist by eXist-db.
the class ResourceTest method setContentAsSourceBinary.
@Test
public void setContentAsSourceBinary() throws XMLDBException {
final Collection testCollection = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/" + TEST_COLLECTION);
assertNotNull(testCollection);
final BinaryResource doc = (BinaryResource) testCollection.createResource("source.bin", "BinaryResource");
final byte[] bin = "Stuff And Things".getBytes(UTF_8);
doc.setContent(new StringInputSource(bin));
testCollection.storeResource(doc);
final BinaryResource newDoc = (BinaryResource) testCollection.getResource("source.bin");
final byte[] newDocBin = (byte[]) newDoc.getContent();
assertArrayEquals(bin, newDocBin);
}
Aggregations