Skip to content

Commit

Permalink
Restore compatibility with Liquibase 4.23
Browse files Browse the repository at this point in the history
Closes gh-38522
  • Loading branch information
wilkinsona committed Nov 28, 2023
1 parent 903f85c commit 3e4e59a
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import javax.sql.DataSource;

import liquibase.UpdateSummaryEnum;
import liquibase.UpdateSummaryOutputEnum;
import liquibase.change.DatabaseChange;
import liquibase.integration.spring.SpringLiquibase;

Expand Down Expand Up @@ -113,8 +115,13 @@ public SpringLiquibase liquibase(ObjectProvider<DataSource> dataSource,
liquibase.setRollbackFile(properties.getRollbackFile());
liquibase.setTestRollbackOnUpdate(properties.isTestRollbackOnUpdate());
liquibase.setTag(properties.getTag());
liquibase.setShowSummary(properties.getShowSummary());
liquibase.setShowSummaryOutput(properties.getShowSummaryOutput());
if (properties.getShowSummary() != null) {
liquibase.setShowSummary(UpdateSummaryEnum.valueOf(properties.getShowSummary().name()));
}
if (properties.getShowSummaryOutput() != null) {
liquibase
.setShowSummaryOutput(UpdateSummaryOutputEnum.valueOf(properties.getShowSummaryOutput().name()));
}
return liquibase;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,14 @@ public class LiquibaseProperties {
private String tag;

/**
* Whether to print a summary of the update operation. Values can be 'off', 'summary'
* (default), 'verbose'
* Whether to print a summary of the update operation.
*/
private UpdateSummaryEnum showSummary;
private ShowSummary showSummary;

/**
* Where to print a summary of the update operation. Values can be 'log' (default),
* 'console', or 'all'.
* Where to print a summary of the update operation.
*/
private UpdateSummaryOutputEnum showSummaryOutput;
private ShowSummaryOutput showSummaryOutput;

public String getChangeLog() {
return this.changeLog;
Expand Down Expand Up @@ -302,20 +300,72 @@ public void setTag(String tag) {
this.tag = tag;
}

public UpdateSummaryEnum getShowSummary() {
public ShowSummary getShowSummary() {
return this.showSummary;
}

public void setShowSummary(UpdateSummaryEnum showSummary) {
public void setShowSummary(ShowSummary showSummary) {
this.showSummary = showSummary;
}

public UpdateSummaryOutputEnum getShowSummaryOutput() {
public ShowSummaryOutput getShowSummaryOutput() {
return this.showSummaryOutput;
}

public void setShowSummaryOutput(UpdateSummaryOutputEnum showSummaryOutput) {
public void setShowSummaryOutput(ShowSummaryOutput showSummaryOutput) {
this.showSummaryOutput = showSummaryOutput;
}

/**
* Enumeration of types of summary to show. Values are the same as those on
* {@link UpdateSummaryEnum}. To maximize backwards compatibility, the Liquibase enum
* is not used directly.
*
* @since 3.2.1
*/
public enum ShowSummary {

/**
* Do not show a summary.
*/
OFF,

/**
* Show a summary.
*/
SUMMARY,

/**
* Show a verbose summary.
*/
VERBOSE

}

/**
* Enumeration of destinations to which the summary should be output. Values are the
* same as those on {@link UpdateSummaryOutputEnum}. To maximize backwards
* compatibility, the Liquibase enum is not used directly.
*
* @since 3.2.1
*/
public enum ShowSummaryOutput {

/**
* Log the summary.
*/
LOG,

/**
* Output the summary to the console.
*/
CONSOLE,

/**
* Log the summary and output it to the console.
*/
ALL

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,14 @@
"level": "error"
}
},
{
"name": "spring.liquibase.show-summary",
"defaultValue": "summary"
},
{
"name": "spring.liquibase.show-summary-output",
"defaultValue": "log"
},
{
"name": "spring.mail.test-connection",
"description": "Whether to test that the mail server is available on startup.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.autoconfigure.liquibase;

import java.util.function.Consumer;

import liquibase.integration.spring.SpringLiquibase;
import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ContextConsumer;
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link LiquibaseAutoConfiguration} with Liquibase 4.23.
*
* @author Andy Wilkinson
*/
@ClassPathOverrides("org.liquibase:liquibase-core:4.23.1")
class Liquibase423AutoConfigurationTests {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(LiquibaseAutoConfiguration.class))
.withPropertyValues("spring.datasource.generate-unique-name=true");

@Test
void defaultSpringLiquibase() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.run(assertLiquibase((liquibase) -> {
assertThat(liquibase.getChangeLog()).isEqualTo("classpath:/db/changelog/db.changelog-master.yaml");
assertThat(liquibase.getContexts()).isNull();
assertThat(liquibase.getDefaultSchema()).isNull();
assertThat(liquibase.isDropFirst()).isFalse();
assertThat(liquibase.isClearCheckSums()).isFalse();
}));
}

private ContextConsumer<AssertableApplicationContext> assertLiquibase(Consumer<SpringLiquibase> consumer) {
return (context) -> {
assertThat(context).hasSingleBean(SpringLiquibase.class);
SpringLiquibase liquibase = context.getBean(SpringLiquibase.class);
consumer.accept(liquibase);
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.zaxxer.hikari.HikariDataSource;
import liquibase.UpdateSummaryEnum;
import liquibase.UpdateSummaryOutputEnum;
import liquibase.command.core.helpers.ShowSummaryArgument;
import liquibase.integration.spring.SpringLiquibase;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -119,9 +120,6 @@ void defaultSpringLiquibase() {
assertThat(liquibase.getDefaultSchema()).isNull();
assertThat(liquibase.isDropFirst()).isFalse();
assertThat(liquibase.isClearCheckSums()).isFalse();
UpdateSummaryOutputEnum showSummaryOutput = (UpdateSummaryOutputEnum) ReflectionTestUtils
.getField(liquibase, "showSummaryOutput");
assertThat(showSummaryOutput).isEqualTo(UpdateSummaryOutputEnum.LOG);
}));
}

Expand Down Expand Up @@ -225,6 +223,9 @@ void defaultValues() {
assertThat(liquibase.isDropFirst()).isEqualTo(properties.isDropFirst());
assertThat(liquibase.isClearCheckSums()).isEqualTo(properties.isClearChecksums());
assertThat(liquibase.isTestRollbackOnUpdate()).isEqualTo(properties.isTestRollbackOnUpdate());
assertThat(liquibase).extracting("showSummary").isNull();
assertThat(ShowSummaryArgument.SHOW_SUMMARY.getDefaultValue()).isEqualTo(UpdateSummaryEnum.SUMMARY);
assertThat(liquibase).extracting("showSummaryOutput").isEqualTo(UpdateSummaryOutputEnum.LOG);
}));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.autoconfigure.liquibase;

import java.util.List;
import java.util.stream.Stream;

import liquibase.UpdateSummaryEnum;
import liquibase.UpdateSummaryOutputEnum;
import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties.ShowSummary;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties.ShowSummaryOutput;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link LiquibaseProperties}.
*
* @author Andy Wilkinson
*/
public class LiquibasePropertiesTests {

@Test
void valuesOfShowSummaryMatchValuesOfUpdateSummaryEnum() {
assertThat(namesOf(ShowSummary.values())).isEqualTo(namesOf(UpdateSummaryEnum.values()));
}

@Test
void valuesOfShowSummaryOutputMatchValuesOfUpdateSummaryOutputEnum() {
assertThat(namesOf(ShowSummaryOutput.values())).isEqualTo(namesOf(UpdateSummaryOutputEnum.values()));
}

private List<String> namesOf(Enum<?>[] input) {
return Stream.of(input).map(Enum::name).toList();
}

}

0 comments on commit 3e4e59a

Please sign in to comment.