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