public void testWithConnectionFactoryAndExceptionListenerAndReconnectOnException()
      throws JMSException {
    MockControl cfControl = MockControl.createControl(ConnectionFactory.class);
    ConnectionFactory cf = (ConnectionFactory) cfControl.getMock();
    TestConnection con = new TestConnection();

    TestExceptionListener listener = new TestExceptionListener();
    cf.createConnection();
    cfControl.setReturnValue(con, 2);
    cfControl.replay();

    SingleConnectionFactory scf = new SingleConnectionFactory(cf);
    scf.setExceptionListener(listener);
    scf.setReconnectOnException(true);
    Connection con1 = scf.createConnection();
    assertSame(listener, con1.getExceptionListener());
    con1.start();
    con.getExceptionListener().onException(new JMSException(""));
    Connection con2 = scf.createConnection();
    con2.start();
    scf.destroy(); // should trigger actual close

    cfControl.verify();
    assertEquals(2, con.getStartCount());
    assertEquals(2, con.getCloseCount());
    assertEquals(1, listener.getCount());
  }
 @Override
 protected void starting(Description description) {
   try {
     if (delegate == null || delegate.isClosed()) delegate = getNewConnection();
     if (!autoCommit) delegate.setAutoCommit(false);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
 @Override
 protected void finished(Description description) {
   if (!autoCommit && delegate != null) {
     try {
       if (!delegate.isClosed()) {
         delegate.rollback();
         delegate.reset();
       }
     } catch (SQLException se) {
       throw new RuntimeException(se);
     }
   }
 }
 @Override
 public PreparedStatement prepareStatement(
     String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
     throws SQLException {
   return delegate.prepareStatement(
       sql, resultSetType, resultSetConcurrency, resultSetHoldability);
 }
  protected void setUp() throws java.lang.Exception {

    conn = TestConnection.makeAndCleanTestConnection();
    model = ModelRDB.createModel(conn, TestPackage.M_DB);

    model
        .createResource()
        .addProperty(RDF.type, RDFS.Resource)
        .addProperty(RDFS.label, "foo")
        .addProperty(RDF.value, "123");
    model
        .createResource()
        .addProperty(RDF.type, RDFS.Resource)
        .addProperty(RDFS.label, "bar")
        .addProperty(RDF.value, "123");
  }
 @Override
 public void abort(Executor executor) throws SQLException {
   delegate.abort(executor);
 }
 @Override
 public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
   delegate.setNetworkTimeout(executor, milliseconds);
 }
 @Override
 public CallableStatement prepareCall(String sql) throws SQLException {
   return delegate.prepareCall(sql);
 }
 @Override
 public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
   return delegate.prepareStatement(sql, columnNames);
 }
 @Override
 public Statement createStatement(
     int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
   return delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
 }
 @Override
 public Statement createStatement() throws SQLException {
   return delegate.createStatement();
 }
 @Override
 public String getClientInfo(String name) throws SQLException {
   return delegate.getClientInfo(name);
 }
 @Override
 public boolean isWrapperFor(Class<?> iface) throws SQLException {
   return delegate.isWrapperFor(iface);
 }
 @Override
 public void setClientInfo(String name, String value) throws SQLClientInfoException {
   delegate.setClientInfo(name, value);
 }
 @Override
 public void setClientInfo(Properties properties) throws SQLClientInfoException {
   delegate.setClientInfo(properties);
 }
 @Override
 public boolean isValid(int timeout) throws SQLException {
   return delegate.isValid(timeout);
 }
 @Override
 public SQLXML createSQLXML() throws SQLException {
   return delegate.createSQLXML();
 }
 @Override
 public NClob createNClob() throws SQLException {
   return delegate.createNClob();
 }
 @Override
 public int getNetworkTimeout() throws SQLException {
   return delegate.getNetworkTimeout();
 }
 @Override
 public Properties getClientInfo() throws SQLException {
   return delegate.getClientInfo();
 }
 @Override
 public <T> T unwrap(Class<T> iface) throws SQLException {
   return delegate.unwrap(iface);
 }
 @Override
 public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
   return delegate.createArrayOf(typeName, elements);
 }
 private TestConnection getNewConnection() throws Exception {
   TestConnection conn = connPool.getConnection(userName, password);
   if (schema != null) conn.setSchema(schema);
   return conn;
 }
 @Override
 public void rollback(Savepoint savepoint) throws SQLException {
   delegate.rollback(savepoint);
 }
 @Override
 public void releaseSavepoint(Savepoint savepoint) throws SQLException {
   delegate.releaseSavepoint(savepoint);
 }
 @Override
 public void setSchema(String schema) throws SQLException {
   delegate.setSchema(schema);
 }
 @Override
 public PreparedStatement prepareStatement(String sql) throws SQLException {
   return delegate.prepareStatement(sql);
 }
 @Override
 public String getSchema() throws SQLException {
   return delegate.getSchema();
 }
 @Override
 public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
   return delegate.createStruct(typeName, attributes);
 }
 @Override
 public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
   return delegate.prepareStatement(sql, autoGeneratedKeys);
 }