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();
}
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();
}
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();
}
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());
}
Aggregations