Search in sources :

Example 6 with SpringLiquibase

use of liquibase.integration.spring.SpringLiquibase in project spring-boot by spring-projects.

the class LiquibaseAutoConfigurationTests method testOverrideDropFirst.

@Test
public void testOverrideDropFirst() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context, "liquibase.drop-first:true");
    this.context.register(EmbeddedDataSourceConfiguration.class, LiquibaseAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class);
    assertThat(liquibase.isDropFirst()).isTrue();
}
Also used : SpringLiquibase(liquibase.integration.spring.SpringLiquibase) Test(org.junit.Test)

Example 7 with SpringLiquibase

use of liquibase.integration.spring.SpringLiquibase in project spring-boot by spring-projects.

the class LiquibaseEndpoint method invoke.

@Override
public List<LiquibaseReport> invoke() {
    List<LiquibaseReport> reports = new ArrayList<>();
    DatabaseFactory factory = DatabaseFactory.getInstance();
    StandardChangeLogHistoryService service = new StandardChangeLogHistoryService();
    for (Map.Entry<String, SpringLiquibase> entry : this.liquibases.entrySet()) {
        try {
            DataSource dataSource = entry.getValue().getDataSource();
            JdbcConnection connection = new JdbcConnection(dataSource.getConnection());
            try {
                Database database = factory.findCorrectDatabaseImplementation(connection);
                reports.add(new LiquibaseReport(entry.getKey(), service.queryDatabaseChangeLogTable(database)));
            } finally {
                connection.close();
            }
        } catch (Exception ex) {
            throw new IllegalStateException("Unable to get Liquibase changelog", ex);
        }
    }
    return reports;
}
Also used : LiquibaseReport(org.springframework.boot.actuate.endpoint.LiquibaseEndpoint.LiquibaseReport) ArrayList(java.util.ArrayList) JdbcConnection(liquibase.database.jvm.JdbcConnection) StandardChangeLogHistoryService(liquibase.changelog.StandardChangeLogHistoryService) DataSource(javax.sql.DataSource) DatabaseFactory(liquibase.database.DatabaseFactory) SpringLiquibase(liquibase.integration.spring.SpringLiquibase) Database(liquibase.database.Database) Map(java.util.Map)

Example 8 with SpringLiquibase

use of liquibase.integration.spring.SpringLiquibase in project spring-boot by spring-projects.

the class LiquibaseAutoConfigurationTests method testOverrideDataSource.

@Test
public void testOverrideDataSource() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context, "liquibase.url:jdbc:hsqldb:mem:liquibase", "liquibase.user:sa");
    this.context.register(EmbeddedDataSourceConfiguration.class, LiquibaseAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class);
    assertThat(liquibase.getDataSource().getConnection().getMetaData().getURL()).isEqualTo("jdbc:hsqldb:mem:liquibase");
}
Also used : SpringLiquibase(liquibase.integration.spring.SpringLiquibase) Test(org.junit.Test)

Example 9 with SpringLiquibase

use of liquibase.integration.spring.SpringLiquibase in project spring-boot by spring-projects.

the class LiquibaseAutoConfigurationTests method testXmlChangeLog.

@Test
public void testXmlChangeLog() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context, "liquibase.change-log:classpath:/db/changelog/db.changelog-override.xml");
    this.context.register(EmbeddedDataSourceConfiguration.class, LiquibaseAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class);
    assertThat(liquibase.getChangeLog()).isEqualTo("classpath:/db/changelog/db.changelog-override.xml");
}
Also used : SpringLiquibase(liquibase.integration.spring.SpringLiquibase) Test(org.junit.Test)

Example 10 with SpringLiquibase

use of liquibase.integration.spring.SpringLiquibase in project spring-boot by spring-projects.

the class LiquibaseAutoConfigurationTests method testRollbackFile.

@Test
public void testRollbackFile() throws Exception {
    File file = this.temp.newFile("rollback-file.sql");
    EnvironmentTestUtils.addEnvironment(this.context, "liquibase.rollbackFile:" + file.getAbsolutePath());
    this.context.register(EmbeddedDataSourceConfiguration.class, LiquibaseAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class);
    File actualFile = (File) ReflectionTestUtils.getField(liquibase, "rollbackFile");
    assertThat(actualFile).isEqualTo(file).exists();
    String content = new String(FileCopyUtils.copyToByteArray(file));
    assertThat(content).contains("DROP TABLE PUBLIC.customer;");
}
Also used : SpringLiquibase(liquibase.integration.spring.SpringLiquibase) File(java.io.File) Test(org.junit.Test)

Aggregations

SpringLiquibase (liquibase.integration.spring.SpringLiquibase)14 Test (org.junit.Test)13 Map (java.util.Map)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 DataSource (javax.sql.DataSource)1 StandardChangeLogHistoryService (liquibase.changelog.StandardChangeLogHistoryService)1 Database (liquibase.database.Database)1 DatabaseFactory (liquibase.database.DatabaseFactory)1 JdbcConnection (liquibase.database.jvm.JdbcConnection)1 LiquibaseReport (org.springframework.boot.actuate.endpoint.LiquibaseEndpoint.LiquibaseReport)1