Search in sources :

Example 1 with KettleDatabaseRepository

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

the class KettleDatabaseRepositoryStepDelegateUnitTest method getStepTypeIDs_WhenNeedToUseNotAllValues.

@Test
public void getStepTypeIDs_WhenNeedToUseNotAllValues() throws Exception {
    final int amount = 1;
    final String[] values = new String[] { "1", "2", "3" };
    KettleDatabaseRepository rep = new KettleDatabaseRepository();
    rep.connectionDelegate = mock(KettleDatabaseRepositoryConnectionDelegate.class);
    when(rep.connectionDelegate.getDatabaseMeta()).thenReturn(mock(DatabaseMeta.class));
    KettleDatabaseRepositoryStepDelegate delegate = new KettleDatabaseRepositoryStepDelegate(rep);
    delegate.getStepTypeIDs(values, amount);
    verify(rep.connectionDelegate).getIDsWithValues(anyString(), anyString(), anyString(), argThat(new BaseMatcher<String[]>() {

        @Override
        public boolean matches(Object item) {
            return (((String[]) item).length == amount) && (((String[]) item)[0].equals(values[0]));
        }

        @Override
        public void describeTo(Description description) {
        }
    }));
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) Matchers.anyString(org.mockito.Matchers.anyString) KettleDatabaseRepository(org.pentaho.di.repository.kdr.KettleDatabaseRepository) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 2 with KettleDatabaseRepository

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

the class KettleDatabaseRepositoryStepDelegateUnitTest method testGetStepTypeCodeToIdMap.

@Test
public void testGetStepTypeCodeToIdMap() throws KettleException {
    KettleDatabaseRepository repository = mock(KettleDatabaseRepository.class);
    KettleDatabaseRepositoryConnectionDelegate connectionDelegate = mock(KettleDatabaseRepositoryConnectionDelegate.class);
    repository.connectionDelegate = connectionDelegate;
    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
    when(connectionDelegate.getDatabaseMeta()).thenReturn(databaseMeta);
    when(databaseMeta.quoteField(anyString())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocationOnMock) throws Throwable {
            return "QUOTE_" + String.valueOf(invocationOnMock.getArguments()[0] + "_QUOTE");
        }
    });
    when(databaseMeta.getQuotedSchemaTableCombination(anyString(), anyString())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocationOnMock) throws Throwable {
            return "QUOTE_" + String.valueOf(invocationOnMock.getArguments()[0]) + "____" + String.valueOf(invocationOnMock.getArguments()[1] + "_QUOTE");
        }
    });
    when(connectionDelegate.getDatabaseMeta()).thenReturn(databaseMeta);
    KettleDatabaseRepositoryStepDelegate kettleDatabaseRepositoryStepDelegate = new KettleDatabaseRepositoryStepDelegate(repository);
    Map map = mock(Map.class);
    when(connectionDelegate.getValueToIdMap(kettleDatabaseRepositoryStepDelegate.quoteTable(KettleDatabaseRepository.TABLE_R_STEP_TYPE), kettleDatabaseRepositoryStepDelegate.quote(KettleDatabaseRepository.FIELD_STEP_TYPE_ID_STEP_TYPE), kettleDatabaseRepositoryStepDelegate.quote(KettleDatabaseRepository.FIELD_STEP_TYPE_CODE))).thenReturn(map);
    assertEquals(map, kettleDatabaseRepositoryStepDelegate.getStepTypeCodeToIdMap());
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) KettleDatabaseRepository(org.pentaho.di.repository.kdr.KettleDatabaseRepository) Matchers.anyString(org.mockito.Matchers.anyString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Map(java.util.Map) Test(org.junit.Test)

Example 3 with KettleDatabaseRepository

use of org.pentaho.di.repository.kdr.KettleDatabaseRepository 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 4 with KettleDatabaseRepository

use of org.pentaho.di.repository.kdr.KettleDatabaseRepository 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)

Example 5 with KettleDatabaseRepository

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

the class ExplorerHarness method main.

/**
 * @param args
 */
@SuppressWarnings("nls")
public static void main(String[] args) {
    KettleDatabaseRepositoryMeta repositoryMeta;
    KettleDatabaseRepository repository;
    @SuppressWarnings("unused") UserInfo userInfo;
    repositoryMeta = new KettleDatabaseRepositoryMeta();
    repositoryMeta.setName("Kettle Database Repository");
    repositoryMeta.setDescription("Kettle database test repository");
    DatabaseMeta connection = new DatabaseMeta();
    connection.setDatabaseType("Hypersonic");
    connection.setHostname("localhost");
    connection.setDBName("kettle_repository_4x");
    connection.setDBPort("9002");
    connection.setUsername("sa");
    repositoryMeta.setConnection(connection);
    userInfo = new UserInfo("admin", "admin", "Administrator", "The system administrator", true);
    repository = new KettleDatabaseRepository();
    repository.init(repositoryMeta);
    @SuppressWarnings("unused") RepositoryExplorerCallback cb = new RepositoryExplorerCallback() {

        public boolean open(UIRepositoryContent element, String revision) throws Exception {
            System.out.println("Name: ".concat(element.getName()));
            System.out.println("Type: ".concat(element.getRepositoryElementType().name()));
            System.out.println("Directory: ".concat(element.getRepositoryDirectory().toString()));
            System.out.println("Revision: ".concat(revision == null ? "null" : revision));
            // do not close explorer
            return false;
        }

        @Override
        public boolean error(String message) throws Exception {
            System.out.println("Error message: ".concat(message));
            return true;
        }
    };
/*
     * try { repository.connect(userInfo.getLogin(), userInfo.getPassword()); //RepositoryExplorer explorer = new
     * RepositoryExplorer(new Shell(), repository, cb, null); //explorer.show(); } catch (XulException e) {
     * e.printStackTrace(); } catch (KettleSecurityException e) { e.printStackTrace(); } catch (KettleException e) {
     * e.printStackTrace(); }
     */
}
Also used : KettleDatabaseRepositoryMeta(org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta) UIRepositoryContent(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryContent) UserInfo(org.pentaho.di.repository.UserInfo) KettleDatabaseRepository(org.pentaho.di.repository.kdr.KettleDatabaseRepository) RepositoryExplorerCallback(org.pentaho.di.ui.repository.repositoryexplorer.RepositoryExplorerCallback) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Aggregations

KettleDatabaseRepository (org.pentaho.di.repository.kdr.KettleDatabaseRepository)7 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 KettleDatabaseRepositoryMeta (org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta)5 KettleException (org.pentaho.di.core.exception.KettleException)4 MessageBox (org.eclipse.swt.widgets.MessageBox)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 RepositoryPluginType (org.pentaho.di.core.plugins.RepositoryPluginType)2 Repository (org.pentaho.di.repository.Repository)2 KettleDatabaseRepositoryCreationHelper (org.pentaho.di.repository.kdr.KettleDatabaseRepositoryCreationHelper)2 EnterPasswordDialog (org.pentaho.di.ui.core.dialog.EnterPasswordDialog)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 File (java.io.File)1 Map (java.util.Map)1 BaseMatcher (org.hamcrest.BaseMatcher)1 Description (org.hamcrest.Description)1 BeforeClass (org.junit.BeforeClass)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 UserInfo (org.pentaho.di.repository.UserInfo)1