use of org.pentaho.di.core.exception.KettleDatabaseException 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.exception.KettleDatabaseException in project pentaho-kettle by pentaho.
the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithMaxAllowedPacketException.
/**
* PDI-5153
* Test that in case of MaxAllowedPacketException exception there will be no stack trace in log (MariaDB)
*/
@Test
public void testExceptionStrategyWithMaxAllowedPacketException() {
DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
DatabaseInterface databaseInterface = new MariaDBDatabaseMeta();
MaxAllowedPacketException e = new MaxAllowedPacketException();
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.exception.KettleDatabaseException in project pentaho-kettle by pentaho.
the class DatabaseTest method testCheckTableExistsByDbMetaThrowsKettleDatabaseException_WhenUnableToGetTableNames.
@Test
public void testCheckTableExistsByDbMetaThrowsKettleDatabaseException_WhenUnableToGetTableNames() {
KettleDatabaseException kettleDatabaseException = new KettleDatabaseException("Unable to get table-names from the database meta-data.", SQL_EXCEPTION);
try {
when(rs.next()).thenReturn(true, false);
when(dbMetaDataMock.getTables(any(), anyString(), anyString(), aryEq(TABLE_TYPES_TO_GET))).thenThrow(SQL_EXCEPTION);
Database db = new Database(log, dbMetaMock);
db.setConnection(mockConnection(dbMetaDataMock));
db.checkTableExistsByDbMeta(SCHEMA_TO_CHECK, EXISTING_TABLE_NAME);
fail("There should be thrown KettleDatabaseException but was not.");
} catch (KettleDatabaseException e) {
assertTrue(e instanceof KettleDatabaseException);
assertEquals(kettleDatabaseException.getLocalizedMessage(), e.getLocalizedMessage());
} catch (Exception ex) {
fail("There should be thrown KettleDatabaseException but was :" + ex.getMessage());
}
}
use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.
the class DatabaseTest method testCheckTableExistsByDbMetaThrowsKettleDatabaseException.
@Test
public void testCheckTableExistsByDbMetaThrowsKettleDatabaseException() {
KettleDatabaseException kettleDatabaseException = new KettleDatabaseException("Unable to check if table [" + EXISTING_TABLE_NAME + "] exists on connection [" + TEST_NAME_OF_DB_CONNECTION + "].", SQL_EXCEPTION);
try {
when(dbMetaMock.getName()).thenReturn(TEST_NAME_OF_DB_CONNECTION);
when(rs.next()).thenReturn(true, false);
when(rs.getString("TABLE_NAME")).thenThrow(SQL_EXCEPTION);
when(dbMetaDataMock.getTables(any(), anyString(), anyString(), aryEq(TABLE_TYPES_TO_GET))).thenReturn(rs);
Database db = new Database(log, dbMetaMock);
db.setConnection(mockConnection(dbMetaDataMock));
db.checkTableExistsByDbMeta(SCHEMA_TO_CHECK, EXISTING_TABLE_NAME);
fail("There should be thrown KettleDatabaseException but was not.");
} catch (KettleDatabaseException e) {
assertTrue(e instanceof KettleDatabaseException);
assertEquals(kettleDatabaseException.getLocalizedMessage(), e.getLocalizedMessage());
} catch (Exception ex) {
fail("There should be thrown KettleDatabaseException but was :" + ex.getMessage());
}
}
use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.
the class JobEntryXMLWellFormed method saveRep.
public void saveRep(Repository rep, IMetaStore metaStore, ObjectId id_job) throws KettleException {
try {
rep.saveJobEntryAttribute(id_job, getObjectId(), "arg_from_previous", arg_from_previous);
rep.saveJobEntryAttribute(id_job, getObjectId(), "include_subfolders", include_subfolders);
rep.saveJobEntryAttribute(id_job, getObjectId(), "nr_errors_less_than", nr_errors_less_than);
rep.saveJobEntryAttribute(id_job, getObjectId(), "success_condition", success_condition);
rep.saveJobEntryAttribute(id_job, getObjectId(), "resultfilenames", resultfilenames);
// save the arguments...
if (source_filefolder != null) {
for (int i = 0; i < source_filefolder.length; i++) {
rep.saveJobEntryAttribute(id_job, getObjectId(), i, "source_filefolder", source_filefolder[i]);
rep.saveJobEntryAttribute(id_job, getObjectId(), i, "wildcard", wildcard[i]);
}
}
} catch (KettleDatabaseException dbe) {
throw new KettleException(BaseMessages.getString(PKG, "JobXMLWellFormed.Error.Exception.UnableSaveRep") + id_job, dbe);
}
}
Aggregations