use of org.pentaho.di.core.database.MySQLDatabaseMeta in project pentaho-kettle by pentaho.
the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithMysqlDataTruncationException.
/**
* PDI-5153
* Test that in case of MysqlDataTruncation exception there will be no stack trace in log
*/
@Test
public void testExceptionStrategyWithMysqlDataTruncationException() {
DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
MysqlDataTruncation e = new MysqlDataTruncation();
when(logTable.getDatabaseMeta()).thenReturn(databaseMeta);
when(databaseMeta.getDatabaseInterface()).thenReturn(databaseInterface);
LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy(logTable, new KettleDatabaseException(e));
String strategyName = exceptionStrategy.getClass().getName();
assertEquals(SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName);
}
use of org.pentaho.di.core.database.MySQLDatabaseMeta in project pentaho-kettle by pentaho.
the class DatabaseLookupUTest method createDatabaseMeta.
private DatabaseLookupMeta createDatabaseMeta() throws KettleException {
MySQLDatabaseMeta mysql = new MySQLDatabaseMeta();
mysql.setName("MySQL");
DatabaseMeta dbMeta = new DatabaseMeta();
dbMeta.setDatabaseInterface(mysql);
DatabaseLookupMeta meta = new DatabaseLookupMeta();
meta.setDatabaseMeta(dbMeta);
meta.setTablename("VirtualTable");
meta.setTableKeyField(new String[] { ID_FIELD });
meta.setKeyCondition(new String[] { "=" });
meta.setReturnValueNewName(new String[] { "returned value" });
meta.setReturnValueField(new String[] { BINARY_FIELD });
meta.setReturnValueDefaultType(new int[] { ValueMetaInterface.TYPE_BINARY });
meta.setStreamKeyField1(new String[0]);
meta.setStreamKeyField2(new String[0]);
meta.setReturnValueDefault(new String[] { "" });
meta = spy(meta);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
RowMetaInterface row = (RowMetaInterface) invocation.getArguments()[0];
ValueMetaInterface v = new ValueMetaBinary(BINARY_FIELD);
row.addValueMeta(v);
return null;
}
}).when(meta).getFields(any(RowMetaInterface.class), anyString(), any(RowMetaInterface[].class), any(StepMeta.class), any(VariableSpace.class), any(Repository.class), any(IMetaStore.class));
return meta;
}
use of org.pentaho.di.core.database.MySQLDatabaseMeta 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.MySQLDatabaseMeta in project pentaho-kettle by pentaho.
the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithPacketTooBigExceptionPropSetY.
/**
* Property value has priority
*/
@Test
public void testExceptionStrategyWithPacketTooBigExceptionPropSetY() {
System.setProperty(DatabaseLogExceptionFactory.KETTLE_GLOBAL_PROP_NAME, PROPERTY_VALUE_TRUE);
DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
PacketTooBigException e = new PacketTooBigException();
when(logTable.getDatabaseMeta()).thenReturn(databaseMeta);
when(databaseMeta.getDatabaseInterface()).thenReturn(databaseInterface);
LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy(logTable, new KettleDatabaseException(e));
String strategyName = exceptionStrategy.getClass().getName();
assertEquals(THROWABLE, strategyName);
}
use of org.pentaho.di.core.database.MySQLDatabaseMeta in project pentaho-kettle by pentaho.
the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithPacketTooBigException.
/**
* PDI-5153
* Test that in case of PacketTooBigException exception there will be no stack trace in log
*/
@Test
public void testExceptionStrategyWithPacketTooBigException() {
DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
PacketTooBigException e = new PacketTooBigException();
when(logTable.getDatabaseMeta()).thenReturn(databaseMeta);
when(databaseMeta.getDatabaseInterface()).thenReturn(databaseInterface);
LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy(logTable, new KettleDatabaseException(e));
String strategyName = exceptionStrategy.getClass().getName();
assertEquals(SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName);
}
Aggregations