org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties Java Examples

The following examples show how to use org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringLiquibaseUtilTest.java    From jhipster with Apache License 2.0 6 votes vote down vote up
@Test
public void createSpringLiquibaseFromLiquibaseProperties() {
    DataSource liquibaseDatasource = null;
    LiquibaseProperties liquibaseProperties = new LiquibaseProperties();
    liquibaseProperties.setUrl("jdbc:h2:mem:liquibase");
    liquibaseProperties.setUser("sa");
    DataSource normalDataSource = null;
    DataSourceProperties dataSourceProperties = new DataSourceProperties();
    dataSourceProperties.setPassword("password");

    SpringLiquibase liquibase = SpringLiquibaseUtil.createSpringLiquibase(liquibaseDatasource, liquibaseProperties, normalDataSource, dataSourceProperties);
    assertThat(liquibase)
        .asInstanceOf(type(DataSourceClosingSpringLiquibase.class))
        .extracting(SpringLiquibase::getDataSource)
        .asInstanceOf(type(HikariDataSource.class))
        .hasFieldOrPropertyWithValue("jdbcUrl", "jdbc:h2:mem:liquibase")
        .hasFieldOrPropertyWithValue("username", "sa")
        .hasFieldOrPropertyWithValue("password", "password");
}
 
Example #2
Source File: SpringLiquibaseUtilTest.java    From jhipster with Apache License 2.0 6 votes vote down vote up
@Test
public void createAsyncSpringLiquibaseFromLiquibaseProperties() {
    DataSource liquibaseDatasource = null;
    LiquibaseProperties liquibaseProperties = new LiquibaseProperties();
    liquibaseProperties.setUrl("jdbc:h2:mem:liquibase");
    liquibaseProperties.setUser("sa");
    DataSource normalDataSource = null;
    DataSourceProperties dataSourceProperties = new DataSourceProperties();
    dataSourceProperties.setPassword("password");

    AsyncSpringLiquibase liquibase = SpringLiquibaseUtil.createAsyncSpringLiquibase(null, null, liquibaseDatasource, liquibaseProperties, normalDataSource, dataSourceProperties);
    assertThat(liquibase.getDataSource())
        .asInstanceOf(type(HikariDataSource.class))
        .hasFieldOrPropertyWithValue("jdbcUrl", "jdbc:h2:mem:liquibase")
        .hasFieldOrPropertyWithValue("username", "sa")
        .hasFieldOrPropertyWithValue("password", "password");
}
 
Example #3
Source File: Utils.java    From radman with MIT License 5 votes vote down vote up
static SpringLiquibase buildLiquibase(DataSource dataSource, LiquibaseProperties properties) {
    SpringLiquibase liquibase = new SpringLiquibase();
    liquibase.setDataSource(dataSource);
    liquibase.setChangeLog(properties.getChangeLog());
    liquibase.setContexts(properties.getContexts());
    liquibase.setDefaultSchema(properties.getDefaultSchema());
    liquibase.setDropFirst(properties.isDropFirst());
    liquibase.setShouldRun(properties.isEnabled());
    liquibase.setLabels(properties.getLabels());
    liquibase.setChangeLogParameters(properties.getParameters());
    liquibase.setRollbackFile(properties.getRollbackFile());
    return liquibase;
}
 
Example #4
Source File: SpringLiquibaseUtil.java    From jhipster with Apache License 2.0 5 votes vote down vote up
public static AsyncSpringLiquibase createAsyncSpringLiquibase(Environment env, Executor executor, DataSource liquibaseDatasource, LiquibaseProperties liquibaseProperties, DataSource dataSource, DataSourceProperties dataSourceProperties) {
    AsyncSpringLiquibase liquibase = new AsyncSpringLiquibase(executor, env);
    DataSource liquibaseDataSource = getDataSource(liquibaseDatasource, liquibaseProperties, dataSource);
    if (liquibaseDataSource != null) {
        liquibase.setCloseDataSourceOnceMigrated(false);
        liquibase.setDataSource(liquibaseDataSource);
    } else {
        liquibase.setDataSource(createNewDataSource(liquibaseProperties, dataSourceProperties));
    }
    return liquibase;
}
 
Example #5
Source File: SpringLiquibaseUtil.java    From jhipster with Apache License 2.0 5 votes vote down vote up
private static DataSource getDataSource(DataSource liquibaseDataSource, LiquibaseProperties liquibaseProperties, DataSource dataSource) {
    if (liquibaseDataSource != null) {
        return liquibaseDataSource;
    }
    if (liquibaseProperties.getUrl() == null && liquibaseProperties.getUser() == null) {
        return dataSource;
    }
    return null;
}
 
Example #6
Source File: SpringLiquibaseUtilTest.java    From jhipster with Apache License 2.0 5 votes vote down vote up
@Test
public void createSpringLiquibaseFromLiquibaseDataSource() {
    DataSource liquibaseDatasource = DataSourceBuilder.create().url("jdbc:h2:mem:liquibase").username("sa").build();
    LiquibaseProperties liquibaseProperties = null;
    DataSource normalDataSource = null;
    DataSourceProperties dataSourceProperties = null;

    SpringLiquibase liquibase = SpringLiquibaseUtil.createSpringLiquibase(liquibaseDatasource, liquibaseProperties, normalDataSource, dataSourceProperties);
    assertThat(liquibase).isNotInstanceOf(DataSourceClosingSpringLiquibase.class)
        .extracting(SpringLiquibase::getDataSource).isEqualTo(liquibaseDatasource)
        .asInstanceOf(type(HikariDataSource.class))
        .hasFieldOrPropertyWithValue("jdbcUrl", "jdbc:h2:mem:liquibase")
        .hasFieldOrPropertyWithValue("username", "sa")
        .hasFieldOrPropertyWithValue("password", null);
}
 
Example #7
Source File: SpringLiquibaseUtilTest.java    From jhipster with Apache License 2.0 5 votes vote down vote up
@Test
public void createSpringLiquibaseFromNormalDataSource() {
    DataSource liquibaseDatasource = null;
    LiquibaseProperties liquibaseProperties = new LiquibaseProperties();
    DataSource normalDataSource = DataSourceBuilder.create().url("jdbc:h2:mem:normal").username("sa").build();
    DataSourceProperties dataSourceProperties = null;

    SpringLiquibase liquibase = SpringLiquibaseUtil.createSpringLiquibase(liquibaseDatasource, liquibaseProperties, normalDataSource, dataSourceProperties);
    assertThat(liquibase).isNotInstanceOf(DataSourceClosingSpringLiquibase.class)
        .extracting(SpringLiquibase::getDataSource).isEqualTo(normalDataSource)
        .asInstanceOf(type(HikariDataSource.class))
        .hasFieldOrPropertyWithValue("jdbcUrl", "jdbc:h2:mem:normal")
        .hasFieldOrPropertyWithValue("username", "sa")
        .hasFieldOrPropertyWithValue("password", null);
}
 
Example #8
Source File: SpringLiquibaseUtilTest.java    From jhipster with Apache License 2.0 5 votes vote down vote up
@Test
public void createAsyncSpringLiquibaseFromLiquibaseDataSource() {
    DataSource liquibaseDatasource = DataSourceBuilder.create().url("jdbc:h2:mem:liquibase").username("sa").build();
    LiquibaseProperties liquibaseProperties = null;
    DataSource normalDataSource = null;
    DataSourceProperties dataSourceProperties = null;

    AsyncSpringLiquibase liquibase = SpringLiquibaseUtil.createAsyncSpringLiquibase(null, null, liquibaseDatasource, liquibaseProperties, normalDataSource, dataSourceProperties);
    assertThat(liquibase.getDataSource()).isEqualTo(liquibaseDatasource)
        .asInstanceOf(type(HikariDataSource.class))
        .hasFieldOrPropertyWithValue("jdbcUrl", "jdbc:h2:mem:liquibase")
        .hasFieldOrPropertyWithValue("username", "sa")
        .hasFieldOrPropertyWithValue("password", null);
}
 
Example #9
Source File: SpringLiquibaseUtilTest.java    From jhipster with Apache License 2.0 5 votes vote down vote up
@Test
public void createAsyncSpringLiquibaseFromNormalDataSource() {
    DataSource liquibaseDatasource = null;
    LiquibaseProperties liquibaseProperties = new LiquibaseProperties();
    DataSource normalDataSource = DataSourceBuilder.create().url("jdbc:h2:mem:normal").username("sa").build();
    DataSourceProperties dataSourceProperties = null;

    AsyncSpringLiquibase liquibase = SpringLiquibaseUtil.createAsyncSpringLiquibase(null, null, liquibaseDatasource, liquibaseProperties, normalDataSource, dataSourceProperties);
    assertThat(liquibase.getDataSource()).isEqualTo(normalDataSource)
        .asInstanceOf(type(HikariDataSource.class))
        .hasFieldOrPropertyWithValue("jdbcUrl", "jdbc:h2:mem:normal")
        .hasFieldOrPropertyWithValue("username", "sa")
        .hasFieldOrPropertyWithValue("password", null);
}
 
Example #10
Source File: RadmanDbConfiguration.java    From radman with MIT License 4 votes vote down vote up
@Bean
@ConfigurationProperties(prefix = "database.radman.liquibase")
LiquibaseProperties liquibaseProperties() {
    return new LiquibaseProperties();
}
 
Example #11
Source File: SpringLiquibaseUtil.java    From jhipster with Apache License 2.0 4 votes vote down vote up
private static DataSource createNewDataSource(LiquibaseProperties liquibaseProperties, DataSourceProperties dataSourceProperties) {
    String url = getProperty(liquibaseProperties::getUrl, dataSourceProperties::determineUrl);
    String user = getProperty(liquibaseProperties::getUser, dataSourceProperties::determineUsername);
    String password = getProperty(liquibaseProperties::getPassword, dataSourceProperties::determinePassword);
    return DataSourceBuilder.create().url(url).username(user).password(password).build();
}