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) {
}
}));
}
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());
}
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());
}
}
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);
}
}
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(); }
*/
}
Aggregations