JdbcWrapper { public DataSource createDataSourceProxy(DataSource dataSource) { return createDataSourceProxy(null, dataSource); } private  JdbcWrapper(Counter sqlCounter); static int getUsedConnectionCount(); static int getActiveConnectionCount(); static long getTransactionCount(); static int getActiveThreadCount(); static int getRunningBuildCount(); static int getBuildQueueLength(); static long getBuildQueueWaitingDurationsSum(); static List<ConnectionInformations> getConnectionInformationsList(); Counter getSqlCounter(); static int getMaxConnectionCount(); static Map<String, Map<String, Object>> getBasicDataSourceProperties(); static Map<String, DataSource> getJndiAndSpringDataSources(); static void registerSpringDataSource(String name, DataSource dataSource); DataSource createDataSourceProxy(DataSource dataSource); DataSource createDataSourceProxy(String name, final DataSource dataSource); Connection createConnectionProxy(Connection connection); static final JdbcWrapper SINGLETON; }
@Test public void testCreateDataSourceProxy() throws Exception { cleanUp(); assertTrue("getBasicDataSourceProperties0", JdbcWrapper.getBasicDataSourceProperties().isEmpty()); assertEquals("getMaxConnectionCount0", -1, JdbcWrapper.getMaxConnectionCount()); final org.apache.tomcat.jdbc.pool.DataSource tomcatJdbcDataSource = new org.apache.tomcat.jdbc.pool.DataSource(); tomcatJdbcDataSource.setUrl(H2_DATABASE_URL); tomcatJdbcDataSource.setDriverClassName("org.h2.Driver"); tomcatJdbcDataSource.setMaxActive(123); final DataSource tomcatJdbcProxy = jdbcWrapper.createDataSourceProxy("test2", tomcatJdbcDataSource); assertNotNull("createDataSourceProxy1", tomcatJdbcProxy); tomcatJdbcProxy.getConnection().close(); assertFalse("getBasicDataSourceProperties1", JdbcWrapper.getBasicDataSourceProperties().isEmpty()); assertEquals("getMaxConnectionCount1", 123, JdbcWrapper.getMaxConnectionCount()); final org.apache.commons.dbcp.BasicDataSource dbcpDataSource = new org.apache.commons.dbcp.BasicDataSource(); dbcpDataSource.setUrl(H2_DATABASE_URL); dbcpDataSource.setMaxActive(456); final DataSource dbcpProxy = jdbcWrapper.createDataSourceProxy(dbcpDataSource); assertNotNull("createDataSourceProxy2", dbcpProxy); assertFalse("getBasicDataSourceProperties2", JdbcWrapper.getBasicDataSourceProperties().isEmpty()); assertEquals("getMaxConnectionCount2", 456, JdbcWrapper.getMaxConnectionCount()); final BasicDataSource tomcatDataSource = new BasicDataSource(); tomcatDataSource.setUrl(H2_DATABASE_URL); tomcatDataSource.setMaxActive(789); final DataSource tomcatProxy = jdbcWrapper.createDataSourceProxy("test", tomcatDataSource); assertNotNull("createDataSourceProxy3", tomcatProxy); assertNotNull("getLogWriter2", tomcatProxy.getLogWriter()); tomcatProxy.getConnection().close(); assertFalse("getBasicDataSourceProperties3", JdbcWrapper.getBasicDataSourceProperties().isEmpty()); assertEquals("getMaxConnectionCount3", 789, JdbcWrapper.getMaxConnectionCount()); final org.apache.commons.dbcp2.BasicDataSource dbcp2DataSource = new org.apache.commons.dbcp2.BasicDataSource(); dbcp2DataSource.setUrl(H2_DATABASE_URL); dbcp2DataSource.setMaxTotal(456); final DataSource dbcp2Proxy = jdbcWrapper.createDataSourceProxy(dbcp2DataSource); assertNotNull("createDataSourceProxy2b", dbcp2Proxy); final org.apache.tomcat.dbcp.dbcp2.BasicDataSource tomcat2DataSource = new org.apache.tomcat.dbcp.dbcp2.BasicDataSource(); tomcat2DataSource.setUrl(H2_DATABASE_URL); tomcat2DataSource.setMaxTotal(789); final DataSource tomcat2Proxy = jdbcWrapper.createDataSourceProxy("test", tomcat2DataSource); assertNotNull("createDataSourceProxy3b", tomcat2Proxy); final DataSource dataSource2 = new MyDataSource(tomcatDataSource); jdbcWrapper.createDataSourceProxy(dataSource2); }