Search in sources :

Example 1 with KettleDatabaseRepositoryCreationHelper

use of org.pentaho.di.repository.kdr.KettleDatabaseRepositoryCreationHelper in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryIT method testDatabaseRepository.

public void testDatabaseRepository() throws Exception {
    KettleEnvironment.init();
    String filename = File.createTempFile("kdrtest", "").getAbsolutePath();
    System.out.println("Using file '" + filename + "' as a H2 database repository");
    try {
        DatabaseMeta databaseMeta = new DatabaseMeta("H2Repo", "H2", "JDBC", null, filename, null, null, null);
        repositoryMeta = new KettleDatabaseRepositoryMeta("KettleDatabaseRepository", "H2Repo", "H2 Repository", databaseMeta);
        repository = new KettleDatabaseRepository();
        repository.init(repositoryMeta);
        repository.connectionDelegate.connect(true, true);
        KettleDatabaseRepositoryCreationHelper helper = new KettleDatabaseRepositoryCreationHelper(repository);
        helper.createRepositorySchema(null, false, new ArrayList<String>(), false);
        repository.disconnect();
        // Test connecting...
        // 
        repository.connect("admin", "admin");
        assertTrue(repository.isConnected());
        // Test database save
        DatabaseMeta dataBaseForSave = new DatabaseMeta("H2Test", "H2", "JDBC", null, filename, null, null, null);
        repository.save(dataBaseForSave, "User creates new database");
        // load new database from repository by generated id on save step
        DatabaseMeta loadedDataBase = repository.loadDatabaseMeta(dataBaseForSave.getObjectId(), "User creates new database");
        assertEquals("Database object before save and after load form database is diffenert", dataBaseForSave, loadedDataBase);
        // Test loading the directory tree
        tree = repository.loadRepositoryDirectoryTree();
        assertNotNull(tree);
        // Test directory creation
        // 
        RepositoryDirectoryInterface fooDirectory = repository.createRepositoryDirectory(tree, "foo");
        RepositoryDirectoryInterface barDirectory = repository.createRepositoryDirectory(fooDirectory, "bar");
        RepositoryDirectoryInterface samplesDirectory = repository.createRepositoryDirectory(fooDirectory, "samples");
        // Test directory path lookup
        RepositoryDirectoryInterface checkBar = tree.findDirectory("/foo/bar");
        assertNotNull(checkBar);
        assertTrue(checkBar.equals(barDirectory));
        // Save all the transformations samples.
        // 
        verifyTransformationSamples(samplesDirectory);
        verifyJobSamples(samplesDirectory);
        // Verify metastore functionality
        // 
        IMetaStore metaStore = repository.getMetaStore();
        KettleMetaStoreTestBase testBase = new KettleMetaStoreTestBase();
        testBase.testFunctionality(metaStore);
        // Finally test disconnecting
        repository.disconnect();
        assertFalse(repository.isConnected());
    } catch (Exception e) {
        e.printStackTrace();
        throw new KettleException("Error during database repository unit testing", e);
    } finally {
        // Remove the H2 database file
        // 
        assertTrue(new File(filename + ".h2.db").delete());
        assertTrue(new File(filename + ".trace.db").delete());
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseRepositoryMeta(org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta) KettleDatabaseRepository(org.pentaho.di.repository.kdr.KettleDatabaseRepository) KettleDatabaseRepositoryCreationHelper(org.pentaho.di.repository.kdr.KettleDatabaseRepositoryCreationHelper) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) File(java.io.File) KettleException(org.pentaho.di.core.exception.KettleException)

Example 2 with KettleDatabaseRepositoryCreationHelper

use of org.pentaho.di.repository.kdr.KettleDatabaseRepositoryCreationHelper in project pentaho-kettle by pentaho.

the class RepositoryUnitIT method setUpBeforeClass.

/**
 * setUpBeforeClass is a method called once before all tests are run. For this test suite, it is
 * used to set up and connect to the test database repository, to increase performance and reduce
 * unnecessary initialization, connects/disconnects from each test case. If repository
 * initialization and/or connection/disconnection
 *
 * @throws java.lang.Exception
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    KettleEnvironment.init();
    registry = PluginRegistry.getInstance();
    filename = File.createTempFile("kdrtest", "").getAbsolutePath();
    System.out.println("Using file '" + filename + "' as a H2 database repository");
    try {
        DatabaseMeta databaseMeta = new DatabaseMeta("H2Repo", "H2", "JDBC", null, filename, null, null, null);
        repositoryMeta = new KettleDatabaseRepositoryMeta("KettleDatabaseRepository", "H2Repo", "H2 Repository", databaseMeta);
        repository = new KettleDatabaseRepository();
        repository.init(repositoryMeta);
        repository.connectionDelegate.connect(true, true);
        KettleDatabaseRepositoryCreationHelper helper = new KettleDatabaseRepositoryCreationHelper(repository);
        helper.createRepositorySchema(null, false, new ArrayList<String>(), false);
        // Reconnect as admin
        repository.disconnect();
        repository.connect("admin", "admin");
    } catch (Exception e) {
        e.printStackTrace();
        throw new KettleException("Error during database repository unit testing", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseRepositoryMeta(org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta) KettleDatabaseRepository(org.pentaho.di.repository.kdr.KettleDatabaseRepository) KettleDatabaseRepositoryCreationHelper(org.pentaho.di.repository.kdr.KettleDatabaseRepositoryCreationHelper) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleException(org.pentaho.di.core.exception.KettleException) BeforeClass(org.junit.BeforeClass)

Aggregations

DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 KettleException (org.pentaho.di.core.exception.KettleException)2 KettleDatabaseRepository (org.pentaho.di.repository.kdr.KettleDatabaseRepository)2 KettleDatabaseRepositoryCreationHelper (org.pentaho.di.repository.kdr.KettleDatabaseRepositoryCreationHelper)2 KettleDatabaseRepositoryMeta (org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta)2 File (java.io.File)1 BeforeClass (org.junit.BeforeClass)1 IMetaStore (org.pentaho.metastore.api.IMetaStore)1