use of org.springframework.jdbc.datasource.SimpleDriverDataSource in project spring-boot by spring-projects.
the class DataSourceBuilderTests method buildWhenDerivedFromExistingDatabaseWithTypeChange.
// gh-26644
@Test
void buildWhenDerivedFromExistingDatabaseWithTypeChange() {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setUsername("test");
dataSource.setPassword("secret");
dataSource.setJdbcUrl("jdbc:postgresql://localhost:5432/postgres");
DataSourceBuilder<?> builder = DataSourceBuilder.derivedFrom(dataSource).type(SimpleDriverDataSource.class);
SimpleDriverDataSource built = (SimpleDriverDataSource) builder.username("test2").password("secret2").build();
assertThat(built.getUsername()).isEqualTo("test2");
assertThat(built.getPassword()).isEqualTo("secret2");
assertThat(built.getUrl()).isEqualTo("jdbc:postgresql://localhost:5432/postgres");
}
use of org.springframework.jdbc.datasource.SimpleDriverDataSource in project spring-boot by spring-projects.
the class DataSourceBuilderTests method buildWhenDerivedFromCustomTypeWithTypeChange.
// gh-27295
@Test
void buildWhenDerivedFromCustomTypeWithTypeChange() {
CustomDataSource dataSource = new CustomDataSource();
dataSource.setUsername("test");
dataSource.setPassword("secret");
dataSource.setUrl("jdbc:postgresql://localhost:5432/postgres");
DataSourceBuilder<?> builder = DataSourceBuilder.derivedFrom(dataSource).type(SimpleDriverDataSource.class);
SimpleDriverDataSource testSource = (SimpleDriverDataSource) builder.build();
assertThat(testSource.getUsername()).isEqualTo("test");
assertThat(testSource.getUrl()).isEqualTo("jdbc:postgresql://localhost:5432/postgres");
assertThat(testSource.getPassword()).isEqualTo("secret");
}
use of org.springframework.jdbc.datasource.SimpleDriverDataSource in project spring-boot by spring-projects.
the class LiquibaseAutoConfigurationTests method overrideUserWhenCustom.
@Test
void overrideUserWhenCustom() {
this.contextRunner.withUserConfiguration(CustomDataSourceConfiguration.class).withPropertyValues("spring.liquibase.user:test", "spring.liquibase.password:secret").run((context) -> {
String expectedName = context.getBean(CustomDataSourceConfiguration.class).name;
SpringLiquibase liquibase = context.getBean(SpringLiquibase.class);
SimpleDriverDataSource dataSource = (SimpleDriverDataSource) liquibase.getDataSource();
assertThat(dataSource.getUrl()).contains(expectedName);
assertThat(dataSource.getUsername()).isEqualTo("test");
});
}
use of org.springframework.jdbc.datasource.SimpleDriverDataSource in project tutorials by eugenp.
the class TransactionalTestConfiguration method getDataSource.
@Bean
public DataSource getDataSource() {
SimpleDriverDataSource simpleDriverDataSource = new SimpleDriverDataSource();
simpleDriverDataSource.setDriverClass(org.hsqldb.jdbcDriver.class);
simpleDriverDataSource.setUrl("jdbc:hsqldb:mem:app-db");
simpleDriverDataSource.setUsername("sa");
simpleDriverDataSource.setPassword("");
return simpleDriverDataSource;
}
use of org.springframework.jdbc.datasource.SimpleDriverDataSource in project cloudbreak by hortonworks.
the class DatabaseConfig method dataSource.
@Bean
public DataSource dataSource() throws SQLException {
DatabaseUtil.createSchemaIfNeeded("postgresql", databaseAddress, dbName, dbUser, dbPassword, dbSchemaName);
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setDriverClass(Driver.class);
if (ssl && Files.exists(Paths.get(certFile))) {
Properties properties = new Properties();
properties.setProperty("ssl", "true");
properties.setProperty("sslfactory", "org.postgresql.ssl.SingleCertValidatingFactory");
properties.setProperty("sslfactoryarg", "file://" + certFile);
dataSource.setConnectionProperties(properties);
}
dataSource.setUrl(String.format("jdbc:postgresql://%s/%s?currentSchema=%s", databaseAddress, dbName, dbSchemaName));
dataSource.setUsername(dbUser);
dataSource.setPassword(dbPassword);
return dataSource;
}
Aggregations