Skip to content

Commit

Permalink
Add test case for DataSourceConverter.getDataSourceParameter (apache#…
Browse files Browse the repository at this point in the history
  • Loading branch information
victorzhangchn committed Aug 26, 2020
1 parent e3c95f9 commit 0bba6ef
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
import java.util.Map;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import javax.sql.DataSource;

public final class DataSourceConverterTest {

Expand Down Expand Up @@ -76,4 +80,39 @@ private void assertParameter(final DataSourceConfiguration actual) {
assertThat(props.get("username"), is("root"));
assertThat(props.get("password"), is("root"));
}

@Test
public void assertGetDataSourceParameter() {
DataSource dataSource = createDataSource();
DataSourceParameter actual = DataSourceConverter.getDataSourceParameter(dataSource);
assertDataSourceParameter(actual);
}

private DataSource createDataSource() {
HikariDataSource hikariDataSource = new HikariDataSource();
hikariDataSource.setJdbcUrl("jdbc:mysql://localhost:3306/demo_ds");
hikariDataSource.setUsername("root");
hikariDataSource.setPassword("root");
hikariDataSource.setConnectionTimeout(30 * 1000L);
hikariDataSource.setIdleTimeout(60 * 1000L);
hikariDataSource.setMaxLifetime(0L);
hikariDataSource.setMaximumPoolSize(50);
hikariDataSource.setMinimumIdle(1);
hikariDataSource.setReadOnly(true);
return hikariDataSource;
}

private void assertDataSourceParameter(final DataSourceParameter actual) {
assertNotNull(actual);
assertThat(actual.getUrl(), is("jdbc:mysql://localhost:3306/demo_ds"));
assertThat(actual.getUsername(), is("root"));
assertThat(actual.getPassword(), is("root"));
assertThat(actual.getConnectionTimeoutMilliseconds(), is(30 * 1000L));
assertThat(actual.getIdleTimeoutMilliseconds(), is(60 * 1000L));
assertThat(actual.getMaxLifetimeMilliseconds(), is(0L));
assertThat(actual.getMaintenanceIntervalMilliseconds(), is(30 * 1000L));
assertThat(actual.getMaxPoolSize(), is(50));
assertThat(actual.getMinPoolSize(), is(1));
assertTrue(actual.isReadOnly());
}
}

0 comments on commit 0bba6ef

Please sign in to comment.