Search in sources :

Example 26 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.

the class DataHandlerTest method testLoadConnectionData.

@Test
public void testLoadConnectionData() throws Exception {
    DatabaseInterface dbInterface = mock(DatabaseInterface.class);
    when(dbInterface.getDefaultDatabasePort()).thenReturn(5309);
    DataHandler.connectionMap.put("myDb", dbInterface);
    dataHandler.loadConnectionData();
    // Should immediately return if called again since the connectionBox will have been loaded
    dataHandler.loadConnectionData();
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) Test(org.junit.Test)

Example 27 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.

the class FragmentHandlerTest method testRefreshOptions.

@Test
public void testRefreshOptions() throws Exception {
    XulListbox connectionBox = mock(XulListbox.class);
    when(document.getElementById("connection-type-list")).thenReturn(connectionBox);
    when(connectionBox.getSelectedItem()).thenReturn("myDb");
    XulListbox accessBox = mock(XulListbox.class);
    when(document.getElementById("access-type-list")).thenReturn(accessBox);
    when(accessBox.getSelectedItem()).thenReturn("Native");
    DataHandler dataHandler = mock(DataHandler.class);
    when(xulDomContainer.getEventHandler("dataHandler")).thenReturn(dataHandler);
    DatabaseInterface dbInterface = mock(DatabaseInterface.class);
    when(dbInterface.getDefaultDatabasePort()).thenReturn(5309);
    DataHandler.connectionMap.put("myDb", dbInterface);
    XulComponent component = mock(XulComponent.class);
    XulComponent parent = mock(XulComponent.class);
    when(component.getParent()).thenReturn(parent);
    when(document.getElementById("database-options-box")).thenReturn(component);
    XulDomContainer fragmentContainer = mock(XulDomContainer.class);
    Document mockDoc = mock(Document.class);
    XulComponent firstChild = mock(XulComponent.class);
    when(mockDoc.getFirstChild()).thenReturn(firstChild);
    when(fragmentContainer.getDocumentRoot()).thenReturn(mockDoc);
    when(xulDomContainer.loadFragment(anyString(), any(Object.class))).thenReturn(fragmentContainer);
    XulTextbox portBox = mock(XulTextbox.class);
    when(document.getElementById("port-number-text")).thenReturn(portBox);
    fragmentHandler.refreshOptions();
    // Iterate through the other database access types
    when(accessBox.getSelectedItem()).thenReturn("JNDI");
    fragmentHandler.refreshOptions();
    when(accessBox.getSelectedItem()).thenReturn("ODBC");
    fragmentHandler.refreshOptions();
    when(accessBox.getSelectedItem()).thenReturn("OCI");
    fragmentHandler.refreshOptions();
    when(accessBox.getSelectedItem()).thenReturn("Plugin");
    fragmentHandler.refreshOptions();
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) XulTextbox(org.pentaho.ui.xul.components.XulTextbox) XulListbox(org.pentaho.ui.xul.containers.XulListbox) XulDomContainer(org.pentaho.ui.xul.XulDomContainer) Document(org.pentaho.ui.xul.dom.Document) XulComponent(org.pentaho.ui.xul.XulComponent) Test(org.junit.Test)

Example 28 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.

the class ValueMetaBaseTest method testGetValueFromSQLTypeBinaryMysql.

// PDI-14721 ESR-5021
@Test
public void testGetValueFromSQLTypeBinaryMysql() throws Exception {
    final int binaryColumnIndex = 1;
    ValueMetaBase valueMetaBase = new ValueMetaBase();
    DatabaseMeta dbMeta = Mockito.spy(new DatabaseMeta());
    DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
    dbMeta.setDatabaseInterface(databaseInterface);
    ResultSet resultSet = Mockito.mock(ResultSet.class);
    ResultSetMetaData metaData = Mockito.mock(ResultSetMetaData.class);
    Mockito.when(resultSet.getMetaData()).thenReturn(metaData);
    Mockito.when(metaData.getColumnType(binaryColumnIndex)).thenReturn(Types.LONGVARBINARY);
    ValueMetaInterface binaryValueMeta = valueMetaBase.getValueFromSQLType(dbMeta, TEST_NAME, metaData, binaryColumnIndex, false, false);
    Assert.assertEquals(ValueMetaInterface.TYPE_BINARY, binaryValueMeta.getType());
    Assert.assertTrue(binaryValueMeta.isBinary());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) ResultSet(java.sql.ResultSet) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) NetezzaDatabaseMeta(org.pentaho.di.core.database.NetezzaDatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) Vertica5DatabaseMeta(org.pentaho.di.core.database.Vertica5DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 29 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.

the class ValueMetaBaseTest method testGetValueFromSQLTypeTypeOverride.

@Test
public void testGetValueFromSQLTypeTypeOverride() throws Exception {
    final int varbinaryColumnIndex = 2;
    ValueMetaBase valueMetaBase = new ValueMetaBase(), valueMetaBaseSpy = Mockito.spy(valueMetaBase);
    DatabaseMeta dbMeta = Mockito.mock(DatabaseMeta.class);
    DatabaseInterface databaseInterface = Mockito.mock(DatabaseInterface.class);
    Mockito.doReturn(databaseInterface).when(dbMeta).getDatabaseInterface();
    ResultSetMetaData metaData = Mockito.mock(ResultSetMetaData.class);
    valueMetaBaseSpy.getValueFromSQLType(dbMeta, TEST_NAME, metaData, varbinaryColumnIndex, false, false);
    Mockito.verify(databaseInterface, Mockito.times(1)).customizeValueFromSQLType(Mockito.any(ValueMetaInterface.class), Mockito.any(ResultSetMetaData.class), Mockito.anyInt());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) NetezzaDatabaseMeta(org.pentaho.di.core.database.NetezzaDatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) Vertica5DatabaseMeta(org.pentaho.di.core.database.Vertica5DatabaseMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 30 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.

the class ValueMetaBaseTest method testVerticaTimeType.

@Test
public void testVerticaTimeType() throws Exception {
    // PDI-12244
    ResultSet resultSet = Mockito.mock(ResultSet.class);
    ResultSetMetaData metaData = Mockito.mock(ResultSetMetaData.class);
    ValueMetaInterface valueMetaInterface = Mockito.mock(ValueMetaInternetAddress.class);
    Mockito.when(resultSet.getMetaData()).thenReturn(metaData);
    Mockito.when(metaData.getColumnType(1)).thenReturn(Types.TIME);
    Mockito.when(resultSet.getTime(1)).thenReturn(new Time(0));
    Mockito.when(valueMetaInterface.getOriginalColumnType()).thenReturn(Types.TIME);
    Mockito.when(valueMetaInterface.getType()).thenReturn(ValueMetaInterface.TYPE_DATE);
    DatabaseInterface databaseInterface = new Vertica5DatabaseMeta();
    Object ret = databaseInterface.getValueFromResultSet(resultSet, valueMetaInterface, 0);
    assertEquals(new Time(0), ret);
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) Vertica5DatabaseMeta(org.pentaho.di.core.database.Vertica5DatabaseMeta) ResultSet(java.sql.ResultSet) Time(java.sql.Time) LoggingObject(org.pentaho.di.core.logging.LoggingObject) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Aggregations

DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)35 Test (org.junit.Test)22 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)16 MySQLDatabaseMeta (org.pentaho.di.core.database.MySQLDatabaseMeta)7 ResultSetMetaData (java.sql.ResultSetMetaData)5 ResultSet (java.sql.ResultSet)4 MariaDBDatabaseMeta (org.pentaho.di.core.database.MariaDBDatabaseMeta)4 NetezzaDatabaseMeta (org.pentaho.di.core.database.NetezzaDatabaseMeta)4 Vertica5DatabaseMeta (org.pentaho.di.core.database.Vertica5DatabaseMeta)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 GenericDatabaseMeta (org.pentaho.di.core.database.GenericDatabaseMeta)3 PacketTooBigException (com.mysql.jdbc.PacketTooBigException)2 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)2 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)2 TableOutputMeta (org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)2 AnalysisContext (org.pentaho.metaverse.api.AnalysisContext)2 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)2 XulTextbox (org.pentaho.ui.xul.components.XulTextbox)2 MysqlDataTruncation (com.mysql.jdbc.MysqlDataTruncation)1