use of org.exist.TestDataGenerator in project exist by eXist-db.
the class ProtectedModeTest method setupDb.
@BeforeClass
public static void setupDb() throws XMLDBException, SAXException {
CollectionManagementService mgmt = (CollectionManagementService) existEmbeddedServer.getRoot().getService("CollectionManagementService", "1.0");
final Collection collection = mgmt.createCollection("protected");
mgmt = (CollectionManagementService) collection.getService("CollectionManagementService", "1.0");
final TestDataGenerator generator = new TestDataGenerator("xdb", DOCUMENT_COUNT);
for (int i = 0; i < COLLECTION_COUNT; i++) {
Collection currentColl = mgmt.createCollection("test" + i);
final Path[] files = generator.generate(currentColl, generateXQ);
for (int j = 0; j < files.length; j++) {
final XMLResource resource = (XMLResource) currentColl.createResource("xdb" + j + ".xml", "XMLResource");
resource.setContent(files[j].toFile());
currentColl.storeResource(resource);
}
}
}
use of org.exist.TestDataGenerator in project exist by eXist-db.
the class RemoveCollectionTest method storeDocs.
private Collection storeDocs(final DBBroker broker, final TransactionManager transact) throws PermissionDeniedException, IOException, SAXException, CollectionConfigurationException, LockException, EXistException {
Collection test;
try (final Txn transaction = transact.beginTransaction()) {
test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(test);
broker.saveCollection(transaction, test);
transact.commit(transaction);
}
try (final Txn transaction = transact.beginTransaction()) {
final TestDataGenerator generator = new TestDataGenerator("xdb", COUNT);
final Path[] files = generator.generate(broker, test, generateXQ);
for (final Path file : files) {
final InputSource is = new InputSource(file.toUri().toASCIIString());
broker.storeDocument(transaction, XmldbURI.create(file.getFileName().toString()), is, MimeType.XML_TYPE, test);
}
generator.releaseAll();
transact.commit(transaction);
}
return test;
}
use of org.exist.TestDataGenerator in project exist by eXist-db.
the class QuerySessionTest method startServer.
@BeforeClass
public static void startServer() throws ClassNotFoundException, IllegalAccessException, InstantiationException, XMLDBException, SAXException {
// initialize XML:DB driver
Class<?> cl = Class.forName("org.exist.xmldb.DatabaseImpl");
Database database = (Database) cl.newInstance();
DatabaseManager.registerDatabase(database);
Collection root = DatabaseManager.getCollection(getBaseUri() + "/db", TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
CollectionManagementService mgmt = (CollectionManagementService) root.getService("CollectionManagementService", "1.0");
Collection test = mgmt.createCollection("rpctest");
final TestDataGenerator generator = new TestDataGenerator("xdb", DOC_COUNT);
final Path[] files = generator.generate(test, generateXQ);
for (int i = 0; i < files.length; i++) {
Resource resource = test.createResource(files[i].getFileName().toString(), "XMLResource");
resource.setContent(files[i].toFile());
test.storeResource(resource);
}
generator.releaseAll();
}
use of org.exist.TestDataGenerator in project exist by eXist-db.
the class RemoveCollectionTest method replaceResources.
public void replaceResources(final BrokerPool pool) throws SAXException, PermissionDeniedException, EXistException, LockException, IOException, CollectionConfigurationException, DatabaseConfigurationException {
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Collection test = storeDocs(broker, transact);
try (final Txn transaction = transact.beginTransaction()) {
TestDataGenerator generator = new TestDataGenerator("xdb", COUNT);
final Path[] files = generator.generate(broker, test, generateXQ);
int j = 0;
for (final Iterator<DocumentImpl> i = test.iterator(broker); i.hasNext() && j < files.length; j++) {
final DocumentImpl doc = i.next();
final InputSource is = new InputSource(files[j].toUri().toASCIIString());
broker.storeDocument(transaction, doc.getURI(), is, MimeType.XML_TYPE, test);
}
generator.releaseAll();
transact.commit(transaction);
}
}
}
Aggregations