@Test public void testCreateFromSQLException() { SQLException sqlexception = new SQLException("foo", "21"); //$NON-NLS-1$ //$NON-NLS-2$ SQLException nested = new SQLException("bar"); //$NON-NLS-1$ sqlexception.setNextException(nested); String message = "top level message"; //$NON-NLS-1$ TeiidSQLException exception = TeiidSQLException.create(sqlexception, message); exception.printStackTrace(); assertEquals(sqlexception, exception.getCause()); assertEquals(exception.getMessage(), message); assertEquals(exception.getSQLState(), sqlexception.getSQLState()); assertEquals(exception.getNextException().getMessage(), nested.getMessage()); } public static enum Event implements BundleUtil.Event {
@Test public void testMMSQLException() { TeiidSQLException e = new TeiidSQLException(); String sqlState = e.getSQLState(); Throwable cause = e.getCause(); int errorCode = e.getErrorCode(); Throwable nestedException = e.getCause(); SQLException nextException = e.getNextException(); assertTrue( "Expected MMSQLException.getSQLState() to return <null> but got \"" //$NON-NLS-1$ + sqlState + "\" instead.", sqlState == null); //$NON-NLS-1$ assertTrue( "Expected MMSQLException.getCause() to return <null> but got [" //$NON-NLS-1$ + (cause != null ? cause.getClass().getName() : "<unknown>") + "] instead.", cause == null); //$NON-NLS-1$ //$NON-NLS-2$ assertTrue( "Expected MMSQLException.getErrorCode() to return [0] but got [" //$NON-NLS-1$ + errorCode + "] instead.", errorCode == 0); //$NON-NLS-1$ assertTrue( "Expected MMSQLException.getNestedException() to return <null> but got [" //$NON-NLS-1$ + (nestedException != null ? nestedException.getClass() .getName() : "<unknown>") + "] instead.", //$NON-NLS-1$ //$NON-NLS-2$ nestedException == null); assertTrue( "Expected MMSQLException.getNextException() to return <null> but got a SQLException with message \"" //$NON-NLS-1$ + (nextException != null ? nextException.getMessage() : "") + "\" instead.", nextException == null); //$NON-NLS-1$ //$NON-NLS-2$ }
private TeiidSQLException testCreateThrowable(Throwable ecause, String esqlState) { TeiidSQLException e = TeiidSQLException.create(ecause); if (ecause.getClass() == TeiidSQLException.class) { ecause = null; } String sqlState = e.getSQLState(); Throwable cause = e.getCause(); int errorCode = e.getErrorCode(); Throwable nestedException = e.getCause(); SQLException nextException = e.getNextException(); assertEquals(esqlState, sqlState); assertEquals(ecause, cause); assertEquals(0, errorCode); assertEquals(nestedException, ecause); assertNull(nextException); return e; }