Separate custom schema configuration for Liquibase test
Unfortunately, creating the schema in code did not offer the right condition to reproduce the error scenario. This commit restore the initial intent, but separating the configuration and cleaning the created context properly. See gh-9862
This commit is contained in:
parent
7736cb1dc5
commit
5c13b8bf50
|
|
@ -16,12 +16,10 @@
|
|||
|
||||
package org.springframework.boot.actuate.endpoint;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import liquibase.integration.spring.SpringLiquibase;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
|
|
@ -29,7 +27,6 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
|||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
|
@ -52,9 +49,12 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests<LiquibaseEndpo
|
|||
|
||||
@Test
|
||||
public void invokeWithCustomSchema() throws Exception {
|
||||
this.context.close();
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"liquibase.default-schema=CUSTOMSCHEMA");
|
||||
"liquibase.default-schema=CUSTOMSCHEMA",
|
||||
"spring.datasource.generate-unique-name=true",
|
||||
"spring.datasource.schema=classpath:/db/create-custom-schema.sql");
|
||||
this.context.register(CustomSchemaConfig.class);
|
||||
this.context.refresh();
|
||||
assertThat(getEndpointBean().invoke()).hasSize(1);
|
||||
|
|
@ -78,13 +78,18 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests<LiquibaseEndpo
|
|||
}
|
||||
|
||||
@Configuration
|
||||
@Import(Config.class)
|
||||
@Import({ DataSourceAutoConfiguration.class, LiquibaseAutoConfiguration.class })
|
||||
public static class CustomSchemaConfig {
|
||||
|
||||
@Autowired
|
||||
public void initializeSchema(DataSource dataSource) {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
jdbcTemplate.execute("CREATE SCHEMA CUSTOMSCHEMA");
|
||||
private final SpringLiquibase liquibase;
|
||||
|
||||
public CustomSchemaConfig(SpringLiquibase liquibase) {
|
||||
this.liquibase = liquibase;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LiquibaseEndpoint endpoint() {
|
||||
return new LiquibaseEndpoint(this.liquibase);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
CREATE SCHEMA CUSTOMSCHEMA;
|
||||
Loading…
Reference in New Issue