Search in sources :

Example 21 with SQLWarning

use of java.sql.SQLWarning in project jaybird by FirebirdSQL.

the class TestV10Database method testWarningOnCallback_warningOnListener.

/**
 * Test if a warning is registered with the callback if the response
 * contains an exception that is a warning.
 */
@Test
public void testWarningOnCallback_warningOnListener() throws Exception {
    AbstractFbWireDatabase db = createDummyDatabase();
    SimpleDatabaseListener callback = new SimpleDatabaseListener();
    db.addDatabaseListener(callback);
    SQLWarning warning = new FbExceptionBuilder().warning(ISCConstants.isc_numeric_out_of_range).toSQLException(SQLWarning.class);
    db.getDatabaseWarningCallback().processWarning(warning);
    List<SQLWarning> warnings = callback.getWarnings();
    assertEquals("Unexpected warnings registered or no warnings registered", Collections.singletonList(warning), warnings);
}
Also used : SQLWarning(java.sql.SQLWarning) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) Test(org.junit.Test)

Example 22 with SQLWarning

use of java.sql.SQLWarning in project jaybird by FirebirdSQL.

the class TestV10Database method testProcessResponseWarnings_warning_noCallback.

/**
 * Test if processing the response warning works even if no warning callback is registered.
 */
@Test
public void testProcessResponseWarnings_warning_noCallback() throws Exception {
    AbstractFbWireDatabase db = createDummyDatabase();
    SQLWarning warning = new FbExceptionBuilder().warning(ISCConstants.isc_numeric_out_of_range).toSQLException(SQLWarning.class);
    db.getDatabaseWarningCallback().processWarning(warning);
}
Also used : SQLWarning(java.sql.SQLWarning) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) Test(org.junit.Test)

Example 23 with SQLWarning

use of java.sql.SQLWarning in project jaybird by FirebirdSQL.

the class TestServiceListenerDispatcher method testWarningReceived.

/**
 * Tests if calls to {@link ServiceListenerDispatcher#warningReceived(FbService, SQLWarning)}
 * forwarded correctly.
 */
@Test
public void testWarningReceived() {
    final Expectations expectations = new Expectations();
    final SQLWarning warning = new SQLWarning();
    expectations.exactly(1).of(listener).warningReceived(service, warning);
    context.checking(expectations);
    dispatcher.warningReceived(service, warning);
}
Also used : Expectations(org.jmock.Expectations) SQLWarning(java.sql.SQLWarning) Test(org.junit.Test)

Example 24 with SQLWarning

use of java.sql.SQLWarning in project jaybird by FirebirdSQL.

the class TestStatementListenerDispatcher method testWarningReceived_withException.

/**
 * Tests if listeners throwing exceptions will still cause other listeners to be notified and not result in
 * exceptions thrown to call of the dispatcher.
 */
@Test
public void testWarningReceived_withException() {
    final StatementListener listener2 = context.mock(StatementListener.class, "listener2");
    dispatcher.addListener(listener2);
    final SQLWarning warning = new SQLWarning();
    final Expectations expectations = new Expectations();
    for (StatementListener currentListener : Arrays.asList(listener, listener2)) {
        expectations.exactly(1).of(currentListener).warningReceived(statement, warning);
        expectations.will(throwException(new RuntimeException()));
    }
    context.checking(expectations);
    dispatcher.warningReceived(statement, warning);
}
Also used : SQLWarning(java.sql.SQLWarning) Expectations(org.jmock.Expectations) Test(org.junit.Test)

Example 25 with SQLWarning

use of java.sql.SQLWarning in project jaybird by FirebirdSQL.

the class TestStatementListenerDispatcher method testWarningReceived.

/**
 * Test if call to {@link org.firebirdsql.gds.ng.listeners.StatementListenerDispatcher#warningReceived(org.firebirdsql.gds.ng.FbStatement, java.sql.SQLWarning)}
 * is forwarded correctly.
 */
@Test
public void testWarningReceived() {
    final Expectations expectations = new Expectations();
    final SQLWarning warning = new SQLWarning();
    expectations.exactly(1).of(listener).warningReceived(statement, warning);
    context.checking(expectations);
    dispatcher.warningReceived(statement, warning);
}
Also used : Expectations(org.jmock.Expectations) SQLWarning(java.sql.SQLWarning) Test(org.junit.Test)

Aggregations

SQLWarning (java.sql.SQLWarning)147 SQLException (java.sql.SQLException)47 Statement (java.sql.Statement)35 PreparedStatement (java.sql.PreparedStatement)30 Connection (java.sql.Connection)24 ResultSet (java.sql.ResultSet)23 Test (org.testng.annotations.Test)19 Test (org.junit.Test)17 BaseTest (util.BaseTest)15 CallableStatement (java.sql.CallableStatement)13 ArrayList (java.util.ArrayList)9 JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)8 ResultSetMetaData (java.sql.ResultSetMetaData)6 Expectations (org.jmock.Expectations)6 IOException (java.io.IOException)4 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)3 PrestoWarning (com.facebook.presto.spi.PrestoWarning)3 HashSet (java.util.HashSet)3 Properties (java.util.Properties)3 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)3