JdbcPooledDataSourceFactory implements PooledDataSourceFactory { Properties convertToHikari(Properties poolProperties) { final int MILLIS_PER_SECOND = 1000; Properties result = new Properties(); for (String name : poolProperties.stringPropertyNames()) { String hikariName = convertToCamelCase(name); String hikariValue = poolProperties.getProperty(name); if (name.equals("connection-url")) { hikariName = "jdbcUrl"; } else if (name.equals("jdbc-driver-class")) { hikariName = "driverClassName"; } else if (name.equals("user-name")) { hikariName = "username"; } else if (name.equals("max-pool-size")) { hikariName = "maximumPoolSize"; } else if (name.equals("idle-timeout-seconds")) { hikariName = "idleTimeout"; hikariValue = String.valueOf(Integer.valueOf(hikariValue) * MILLIS_PER_SECOND); } result.setProperty(hikariName, hikariValue); } return result; } JdbcPooledDataSourceFactory(); @Override DataSource createDataSource(Properties poolProperties, Properties dataSourceProperties);  }
@Test public void validateThatConnectionUrlConvertedToJdbcUrl() throws Exception { Properties poolProperties = new Properties(); poolProperties.setProperty("connection-url", "foo"); Properties hikariProperties = instance.convertToHikari(poolProperties); assertThat(hikariProperties.stringPropertyNames()).contains("jdbcUrl"); }
@Test public void validateThatUserNameConvertedToUsername() throws Exception { Properties poolProperties = new Properties(); poolProperties.setProperty("user-name", "foo"); Properties hikariProperties = instance.convertToHikari(poolProperties); assertThat(hikariProperties.stringPropertyNames()).contains("username"); }
@Test public void validateThatJdbcDriverClassConvertedToDriverClassName() throws Exception { Properties poolProperties = new Properties(); poolProperties.setProperty("jdbc-driver-class", "foo"); Properties hikariProperties = instance.convertToHikari(poolProperties); assertThat(hikariProperties.stringPropertyNames()).contains("driverClassName"); }
@Test public void validateThatMaxPoolSizeConvertedToMaximumPoolSize() throws Exception { Properties poolProperties = new Properties(); poolProperties.setProperty("max-pool-size", "foo"); Properties hikariProperties = instance.convertToHikari(poolProperties); assertThat(hikariProperties.stringPropertyNames()).contains("maximumPoolSize"); }
@Test public void validateThatIdleTimeoutSecondsConvertedToIdleTimeout() throws Exception { Properties poolProperties = new Properties(); poolProperties.setProperty("idle-timeout-seconds", "20"); Properties hikariProperties = instance.convertToHikari(poolProperties); assertThat(hikariProperties.stringPropertyNames()).contains("idleTimeout"); }
@Test public void validateThatIdleTimeoutSecondsConvertedToMilliseconds() throws Exception { Properties poolProperties = new Properties(); poolProperties.setProperty("idle-timeout-seconds", "20"); Properties hikariProperties = instance.convertToHikari(poolProperties); assertThat(hikariProperties.getProperty("idleTimeout")).isEqualTo("20000"); }
@Test public void validateThatHyphensConvertedToCamelCase() throws Exception { Properties poolProperties = new Properties(); poolProperties.setProperty("foo-bar-zoo", "value"); poolProperties.setProperty("foo", "value"); poolProperties.setProperty("-bar", "value"); poolProperties.setProperty("zoo-", "value"); Properties hikariProperties = instance.convertToHikari(poolProperties); assertThat(hikariProperties.stringPropertyNames()).containsExactlyInAnyOrder("foo", "Bar", "zoo", "fooBarZoo"); }