Search in sources :

Example 6 with FirebirdConnection

use of org.firebirdsql.jdbc.FirebirdConnection in project jaybird by FirebirdSQL.

the class TestPooledConnectionHandlerMock method testException_Notify.

/**
 * Calling a Connection method on an open proxy should notify the owner of
 * the occurrence of an exception.
 *
 * @throws SQLException
 */
@Test
public void testException_Notify() throws SQLException {
    final FirebirdConnection physicalConnection = context.mock(FirebirdConnection.class);
    final FBPooledConnection pooled = context.mock(FBPooledConnection.class);
    final PooledConnectionHandler handler = new PooledConnectionHandler(physicalConnection, pooled);
    final Sequence exceptionSequence = context.sequence("exceptionSequence");
    context.checking(new Expectations() {

        {
            SQLException sqle = new FBSQLException("Mock Exception");
            oneOf(physicalConnection).clearWarnings();
            will(throwException(sqle));
            inSequence(exceptionSequence);
            oneOf(pooled).fireConnectionError(sqle);
            inSequence(exceptionSequence);
        }
    });
    Connection proxy = handler.getProxy();
    expectedException.expect(SQLException.class);
    proxy.clearWarnings();
}
Also used : Expectations(org.jmock.Expectations) SQLException(java.sql.SQLException) FBSQLException(org.firebirdsql.jdbc.FBSQLException) Connection(java.sql.Connection) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) Sequence(org.jmock.Sequence) FBSQLException(org.firebirdsql.jdbc.FBSQLException) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) Test(org.junit.Test)

Example 7 with FirebirdConnection

use of org.firebirdsql.jdbc.FirebirdConnection in project jaybird by FirebirdSQL.

the class TestPooledConnectionHandlerMock method testDoubleClose_allowed.

/**
 * Calling close() on a closed proxy should not throw an exception.
 *
 * @throws SQLException
 */
@Test
public void testDoubleClose_allowed() throws SQLException {
    final FirebirdConnection physicalConnection = context.mock(FirebirdConnection.class);
    final FBPooledConnection pooled = context.mock(FBPooledConnection.class);
    final PooledConnectionHandler handler = new PooledConnectionHandler(physicalConnection, pooled);
    context.checking(new Expectations() {

        {
            ignoring(physicalConnection);
            ignoring(pooled);
        }
    });
    Connection proxy = handler.getProxy();
    proxy.close();
    // Expectation: no exception for double close
    proxy.close();
}
Also used : Expectations(org.jmock.Expectations) Connection(java.sql.Connection) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) Test(org.junit.Test)

Example 8 with FirebirdConnection

use of org.firebirdsql.jdbc.FirebirdConnection in project jaybird by FirebirdSQL.

the class TestPooledConnectionHandlerMock method testClosedProxy_throwsException.

/**
 * Calling any Connection method (except isClosed() and close()) on a proxy
 * that was closed itself should throw an SQLException mentioning the
 * connection was closed; the owner should not be notified of the exception.
 *
 * TODO: Consider testing for all Connection methods
 *
 * @throws SQLException
 */
@Test
public void testClosedProxy_throwsException() throws SQLException {
    final FirebirdConnection physicalConnection = context.mock(FirebirdConnection.class);
    final FBPooledConnection pooled = context.mock(FBPooledConnection.class);
    final PooledConnectionHandler handler = new PooledConnectionHandler(physicalConnection, pooled);
    context.checking(new Expectations() {

        {
            connectionHandleReleaseExpectations(this, physicalConnection);
            allowing(pooled).releaseConnectionHandler(handler);
            allowing(pooled).fireConnectionClosed();
            never(pooled).fireConnectionError(with(any(SQLException.class)));
        }
    });
    Connection proxy = handler.getProxy();
    proxy.close();
    expectedException.expect(SQLException.class);
    expectedException.expectMessage(PooledConnectionHandler.CLOSED_MESSAGE);
    proxy.clearWarnings();
}
Also used : Expectations(org.jmock.Expectations) SQLException(java.sql.SQLException) FBSQLException(org.firebirdsql.jdbc.FBSQLException) Connection(java.sql.Connection) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) Test(org.junit.Test)

Example 9 with FirebirdConnection

use of org.firebirdsql.jdbc.FirebirdConnection in project jaybird by FirebirdSQL.

the class TestPooledConnectionHandlerMock method testHandlerClose_IsClosed.

/**
 * The isClosed() method of PooledConnectionHandler and its proxy should
 * report <code>true</code> after handler close.
 *
 * @throws SQLException
 */
@Test
public void testHandlerClose_IsClosed() throws SQLException {
    final FirebirdConnection physicalConnection = context.mock(FirebirdConnection.class);
    final FBPooledConnection pooled = context.mock(FBPooledConnection.class);
    final PooledConnectionHandler handler = new PooledConnectionHandler(physicalConnection, pooled);
    context.checking(new Expectations() {

        {
            connectionHandleReleaseExpectations(this, physicalConnection);
            allowing(pooled).releaseConnectionHandler(handler);
        }
    });
    Connection proxy = handler.getProxy();
    handler.close();
    assertTrue("Closed handler should report isClosed() true", handler.isClosed());
    assertTrue("Proxy of closed handler should report isClosed() true", proxy.isClosed());
}
Also used : Expectations(org.jmock.Expectations) Connection(java.sql.Connection) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) FirebirdConnection(org.firebirdsql.jdbc.FirebirdConnection) Test(org.junit.Test)

Aggregations

FirebirdConnection (org.firebirdsql.jdbc.FirebirdConnection)9 Expectations (org.jmock.Expectations)9 Test (org.junit.Test)9 Connection (java.sql.Connection)7 SQLException (java.sql.SQLException)3 FBSQLException (org.firebirdsql.jdbc.FBSQLException)3 Sequence (org.jmock.Sequence)2