BoneCPConnectionProvider implements ConnectionProvider,Configurable,Stoppable { public void configure(Properties props) throws HibernateException { try{ this.config = new BoneCPConfig(props); String url = props.getProperty(CONFIG_CONNECTION_URL); String username = props.getProperty(CONFIG_CONNECTION_USERNAME); String password = props.getProperty(CONFIG_CONNECTION_PASSWORD); String driver = props.getProperty(CONFIG_CONNECTION_DRIVER_CLASS); if (url == null){ url = props.getProperty(CONFIG_CONNECTION_URL_ALTERNATE); } if (username == null){ username = props.getProperty(CONFIG_CONNECTION_USERNAME_ALTERNATE); } if (password == null){ password = props.getProperty(CONFIG_CONNECTION_PASSWORD_ALTERNATE); } if (driver == null){ driver = props.getProperty(CONFIG_CONNECTION_DRIVER_CLASS_ALTERNATE); } if (url != null){ this.config.setJdbcUrl(url); } if (username != null){ this.config.setUsername(username); } if (password != null){ this.config.setPassword(password); } this.isolation = ConfigurationHelper.getInteger(AvailableSettings.ISOLATION, props); this.autocommit = ConfigurationHelper.getBoolean(AvailableSettings.AUTOCOMMIT, props); logger.debug(this.config.toString()); if (driver != null && !driver.trim().equals("")){ loadClass(driver); } if (this.config.getConnectionHookClassName() != null){ Object hookClass = loadClass(this.config.getConnectionHookClassName()).newInstance(); this.config.setConnectionHook((ConnectionHook) hookClass); } this.pool = createPool(this.config); } catch (Exception e) { throw new HibernateException(e); } }  void closeConnection(Connection conn); void configure(Properties props); Connection getConnection(); boolean supportsAggressiveRelease(); ClassLoader getClassLoader(); void setClassLoader(ClassLoader classLoader); @Override @SuppressWarnings("rawtypes") boolean isUnwrappableAs(Class unwrapType); @SuppressWarnings("unchecked") @Override T unwrap(Class<T> unwrapType); @SuppressWarnings({ "unchecked", "rawtypes" }) @Override void configure(Map configurationValues); @Override void stop(); void close();  }
@Test @SuppressWarnings("deprecation") public void testConfigure() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, NoSuchMethodException, ClassNotFoundException, SQLException { Class.forName("com.jolbox.bonecp.MockJDBCDriver"); expect(mockProperties.getProperty("bonecp.statementsCacheSize")).andReturn("40").anyTimes(); expect(mockProperties.getProperty("bonecp.minConnectionsPerPartition")).andReturn("20").anyTimes(); expect(mockProperties.getProperty("bonecp.maxConnectionsPerPartition")).andReturn("50").anyTimes(); expect(mockProperties.getProperty("bonecp.acquireIncrement")).andReturn("5").anyTimes(); expect(mockProperties.getProperty("bonecp.partitionCount")).andReturn("5").anyTimes(); expect(mockProperties.getProperty("bonecp.releaseHelperThreads")).andReturn("3").anyTimes(); expect(mockProperties.getProperty("bonecp.idleConnectionTestPeriod")).andReturn("60").anyTimes(); expect(mockProperties.getProperty("bonecp.idleMaxAge")).andReturn("240").anyTimes(); expect(mockProperties.getProperty("javax.persistence.jdbc.url")).andReturn(URL).anyTimes(); expect(mockProperties.getProperty("javax.persistence.jdbc.user")).andReturn(USERNAME).anyTimes(); expect(mockProperties.getProperty("javax.persistence.jdbc.password")).andReturn(PASSWORD).anyTimes(); expect(mockProperties.getProperty("javax.persistence.jdbc.driver")).andReturn(DRIVER).anyTimes(); expect(mockProperties.getProperty("bonecp.connectionHookClassName")).andReturn("com.jolbox.bonecp.provider.CustomHook").anyTimes(); expect(mockProperties.getProperty("bonecp.connectionTestStatement")).andReturn(TEST_QUERY).anyTimes(); expect(mockProperties.getProperty("bonecp.initSQL")).andReturn(TEST_QUERY).anyTimes(); expect(mockProperties.getProperty("bonecp.logStatementsEnabled")).andReturn("true").anyTimes(); BoneCPConnectionProvider partialTestClass = createMockBuilder(BoneCPConnectionProvider.class).addMockedMethod( BoneCPConnectionProvider.class.getDeclaredMethod("createPool", BoneCPConfig.class)).createMock(); expect(partialTestClass.createPool((BoneCPConfig)anyObject())).andReturn(mockPool).once(); replay(mockProperties, partialTestClass); partialTestClass.configure(mockProperties); BoneCPConfig config = partialTestClass.getConfig(); assertEquals(40, config.getStatementsCacheSize()); assertEquals(20, config.getMinConnectionsPerPartition()); assertEquals(50, config.getMaxConnectionsPerPartition()); assertEquals(5, config.getAcquireIncrement()); assertEquals(5, config.getPartitionCount()); assertEquals(3, config.getReleaseHelperThreads()); assertEquals(60, config.getIdleConnectionTestPeriodInMinutes()); assertEquals(240, config.getIdleMaxAgeInMinutes()); assertEquals(URL, config.getJdbcUrl()); assertEquals(USERNAME, config.getUsername()); assertEquals(PASSWORD, config.getPassword()); assertEquals(TEST_QUERY, config.getInitSQL()); assertEquals(true, config.isLogStatementsEnabled()); verify(mockProperties, partialTestClass); reset(mockProperties); expect(mockProperties.getProperty(CONFIG_CONNECTION_DRIVER_CLASS)).andReturn(null).anyTimes(); replay(mockProperties); try{ testClass.configure(mockProperties); fail("Should have failed with exception"); } catch (HibernateException e){ } reset(mockProperties); expect(mockProperties.getProperty(CONFIG_CONNECTION_DRIVER_CLASS)).andReturn(DRIVER).anyTimes(); expect(mockProperties.getProperty(CONFIG_CONNECTION_URL, "JDBC URL NOT SET IN CONFIG")).andReturn("somethinginvalid").anyTimes(); expect(mockProperties.getProperty(CONFIG_CONNECTION_USERNAME, "username not set")).andReturn(USERNAME).anyTimes(); expect(mockProperties.getProperty(CONFIG_CONNECTION_PASSWORD, "password not set")).andReturn(PASSWORD).anyTimes(); replay(mockProperties); try{ testClass.configure(mockProperties); fail("Should have failed with exception"); } catch (HibernateException e){ } verify(mockProperties); reset(mockProperties); expect(mockProperties.getProperty(CONFIG_CONNECTION_DRIVER_CLASS)).andReturn("somethingbad").anyTimes(); expect(mockProperties.getProperty(CONFIG_CONNECTION_URL, "JDBC URL NOT SET IN CONFIG")).andReturn("somethinginvalid").anyTimes(); expect(mockProperties.getProperty(CONFIG_CONNECTION_USERNAME, "username not set")).andReturn(USERNAME).anyTimes(); expect(mockProperties.getProperty(CONFIG_CONNECTION_PASSWORD, "password not set")).andReturn(PASSWORD).anyTimes(); replay(mockProperties); try{ testClass.configure(mockProperties); fail("Should have failed with exception"); } catch (HibernateException e){ } testClass.setClassLoader(getClass().getClassLoader()); testClass.loadClass("java.lang.String"); testClass.setClassLoader(this.getClass().getClassLoader()); assertEquals(this.getClass().getClassLoader(), testClass.getClassLoader()); reset(mockProperties); expect(mockProperties.getProperty("bonecp.partitionCount")).andReturn("something bad"); expect(mockProperties.getProperty("bonecp.logStatementsEnabled")).andReturn("something bad"); expect(mockProperties.getProperty("bonecp.idleMaxAge")).andReturn("something bad"); replay(mockProperties); try{ testClass.configure(mockProperties); fail("Should have failed with exception"); } catch (HibernateException e){ } }