Search in sources :

Example 1 with TestDataGenerator

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);
        }
    }
}
Also used : Path(java.nio.file.Path) CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Collection(org.xmldb.api.base.Collection) XMLResource(org.xmldb.api.modules.XMLResource) TestDataGenerator(org.exist.TestDataGenerator) BeforeClass(org.junit.BeforeClass)

Example 2 with TestDataGenerator

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;
}
Also used : Path(java.nio.file.Path) InputSource(org.xml.sax.InputSource) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) TestDataGenerator(org.exist.TestDataGenerator)

Example 3 with TestDataGenerator

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();
}
Also used : Path(java.nio.file.Path) CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) TestDataGenerator(org.exist.TestDataGenerator)

Example 4 with TestDataGenerator

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);
        }
    }
}
Also used : Path(java.nio.file.Path) InputSource(org.xml.sax.InputSource) TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) DocumentImpl(org.exist.dom.persistent.DocumentImpl) TestDataGenerator(org.exist.TestDataGenerator)

Aggregations

Path (java.nio.file.Path)4 TestDataGenerator (org.exist.TestDataGenerator)4 Collection (org.exist.collections.Collection)2 Txn (org.exist.storage.txn.Txn)2 InputSource (org.xml.sax.InputSource)2 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)2 DocumentImpl (org.exist.dom.persistent.DocumentImpl)1 TransactionManager (org.exist.storage.txn.TransactionManager)1 BeforeClass (org.junit.BeforeClass)1 Collection (org.xmldb.api.base.Collection)1 XMLResource (org.xmldb.api.modules.XMLResource)1