Restore compatibility with Liquibase 4.23

Closes gh-38522
This commit is contained in:
Andy Wilkinson 2023-11-28 12:15:42 +00:00
parent 903f85cd50
commit 3e4e59a8f0
6 changed files with 198 additions and 15 deletions

View File

@ -18,6 +18,8 @@ package org.springframework.boot.autoconfigure.liquibase;
import javax.sql.DataSource;
import liquibase.UpdateSummaryEnum;
import liquibase.UpdateSummaryOutputEnum;
import liquibase.change.DatabaseChange;
import liquibase.integration.spring.SpringLiquibase;
@ -113,8 +115,13 @@ public class LiquibaseAutoConfiguration {
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;
}

View File

@ -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;
@ -302,20 +300,72 @@ public class LiquibaseProperties {
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
}
}

View File

@ -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.",

View File

@ -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);
};
}
}

View File

@ -31,6 +31,7 @@ import javax.sql.DataSource;
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;
@ -119,9 +120,6 @@ class LiquibaseAutoConfigurationTests {
assertThat(liquibase.getDefaultSchema()).isNull();
assertThat(liquibase.isDropFirst()).isFalse();
assertThat(liquibase.isClearCheckSums()).isFalse();
UpdateSummaryOutputEnum showSummaryOutput = (UpdateSummaryOutputEnum) ReflectionTestUtils
.getField(liquibase, "showSummaryOutput");
assertThat(showSummaryOutput).isEqualTo(UpdateSummaryOutputEnum.LOG);
}));
}
@ -225,6 +223,9 @@ class LiquibaseAutoConfigurationTests {
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);
}));
}

View File

@ -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();
}
}