pull/13568/merge
Andy Wilkinson 6 years ago
parent 454de0bfd7
commit 2f952fde6c

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2016 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.
@ -66,14 +66,9 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
public void setup() {
this.context = new AnnotationConfigApplicationContext();
this.context.register(JacksonAutoConfiguration.class, this.configClass);
configureEnvironment(this.context);
this.context.refresh();
}
protected void configureEnvironment(AnnotationConfigApplicationContext context) {
}
@After
public void close() {
if (this.context != null) {

@ -25,6 +25,7 @@ import liquibase.integration.spring.SpringLiquibase;
import org.junit.Test;
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;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@ -46,14 +47,14 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests<LiquibaseEndpo
"endpoints.liquibase");
}
@Override
protected void configureEnvironment(AnnotationConfigApplicationContext context) {
EnvironmentTestUtils.addEnvironment(context,
"spring.datasource.generate-unique-name=true");
}
@Test
public void invoke() throws Exception {
this.context.close();
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.generate-unique-name=true");
this.context.register(PooledConfig.class);
this.context.refresh();
DataSource dataSource = this.context.getBean(DataSource.class);
assertThat(getAutoCommit(dataSource)).isTrue();
assertThat(getEndpointBean().invoke()).hasSize(1);
@ -76,14 +77,15 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests<LiquibaseEndpo
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"liquibase.default-schema=CUSTOMSCHEMA",
"spring.datasource.generate-unique-name=true",
"spring.datasource.schema=classpath:/db/create-custom-schema.sql");
this.context.register(Config.class);
this.context.register(PooledConfig.class);
this.context.refresh();
assertThat(getEndpointBean().invoke()).hasSize(1);
}
@Configuration
@Import({ DataSourceAutoConfiguration.class, LiquibaseAutoConfiguration.class })
@Import({ EmbeddedDataSourceConfiguration.class, LiquibaseAutoConfiguration.class })
public static class Config {
private final SpringLiquibase liquibase;
@ -99,4 +101,21 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests<LiquibaseEndpo
}
@Configuration
@Import({ DataSourceAutoConfiguration.class, LiquibaseAutoConfiguration.class })
public static class PooledConfig {
private final SpringLiquibase liquibase;
public PooledConfig(SpringLiquibase liquibase) {
this.liquibase = liquibase;
}
@Bean
public LiquibaseEndpoint endpoint() {
return new LiquibaseEndpoint(this.liquibase);
}
}
}

Loading…
Cancel
Save