BoneCP implements Serializable, Closeable { protected Connection obtainRawInternalConnection() throws SQLException { Connection result = null; DataSource datasourceBean = this.config.getDatasourceBean(); String url = this.config.getJdbcUrl(); String username = this.config.getUsername(); String password = this.config.getPassword(); Properties props = this.config.getDriverProperties(); boolean externalAuth = this.config.isExternalAuth(); if (externalAuth && props == null){ props = new Properties(); } if (datasourceBean != null){ return (username == null ? datasourceBean.getConnection() : datasourceBean.getConnection(username, password)); } if (!this.driverInitialized ){ try{ this.driverInitialized = true; if (props != null){ result = DriverManager.getConnection(url, props); } else { result = DriverManager.getConnection(url, username, password); } result.close(); }catch (SQLException t){ } } if (props != null){ result = DriverManager.getConnection(url, props); } else { result = DriverManager.getConnection(url, username, password); } if (this.clientInfo != null){ result.setClientInfo(this.clientInfo); } return result; } BoneCP(BoneCPConfig config); synchronized void shutdown(); void close(); Connection getConnection(); ListenableFuture<Connection> getAsyncConnection(); boolean isConnectionHandleAlive(ConnectionHandle connection); int getTotalLeased(); int getTotalFree(); int getTotalCreatedConnections(); BoneCPConfig getConfig(); Statistics getStatistics(); AtomicBoolean getDbIsDown(); static final String MBEAN_CONFIG; static final String MBEAN_BONECP; }
@Test public void testGetRawConnectionWithExternalAuth() throws SQLException, InterruptedException, IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchFieldException { testClass.config = mockConfig; expect(mockConfig.isExternalAuth()).andReturn(true).once(); expect(mockConfig.getDatasourceBean()).andReturn(null).once(); expect(mockConfig.getJdbcUrl()).andReturn(CommonTestUtils.url).once(); replay(mockConfig); assertNotNull(testClass.obtainRawInternalConnection()); verify(mockConfig); reset(mockConfig); expect(mockConfig.isExternalAuth()).andReturn(false).once(); expect(mockConfig.getDriverProperties()).andReturn(new Properties()).once(); expect(mockConfig.getDatasourceBean()).andReturn(null).once(); expect(mockConfig.getJdbcUrl()).andReturn(CommonTestUtils.url).once(); replay(mockConfig); assertNotNull(testClass.obtainRawInternalConnection()); verify(mockConfig); }
@Test public void testGetRawConnectionCoverage() throws SQLException, InterruptedException, IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchFieldException { testClass.config = mockConfig; testClass.driverInitialized = false; reset(mockConfig); expect(mockConfig.isExternalAuth()).andReturn(false).once(); expect(mockConfig.getDriverProperties()).andReturn(new Properties()).once(); expect(mockConfig.getDatasourceBean()).andReturn(null).once(); expect(mockConfig.getJdbcUrl()).andReturn(CommonTestUtils.url).once(); replay(mockConfig); assertNotNull(testClass.obtainRawInternalConnection()); verify(mockConfig); driver.setMockJDBCAnswer(new MockJDBCAnswer() { public Connection answer() throws SQLException { throw new SQLException(); } }); reset(mockConfig); expect(mockConfig.isExternalAuth()).andReturn(false).once(); expect(mockConfig.getDriverProperties()).andReturn(new Properties()).once(); expect(mockConfig.getDatasourceBean()).andReturn(null).once(); expect(mockConfig.getJdbcUrl()).andReturn(CommonTestUtils.url).once(); replay(mockConfig); try{ testClass.obtainRawInternalConnection(); } catch (SQLException e){ } driver.unregister(); }
@Test public void testGetConnectionViaDriverProperties() throws SQLException, InterruptedException, IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchFieldException { expect(mockConfig.getDriverProperties()).andReturn(new Properties()).once().andReturn(null).once(); expect(mockConfig.getDatasourceBean()).andReturn(null).anyTimes(); expect(mockConfig.getJdbcUrl()).andReturn(CommonTestUtils.url).anyTimes(); expect(mockConfig.isExternalAuth()).andReturn(true).once().andReturn(false).once(); replay(mockConfig); testClass.obtainRawInternalConnection(); testClass.obtainRawInternalConnection(); verify(mockConfig); }