|
|
@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.context;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
import org.springframework.boot.test.EnvironmentTestUtils;
|
|
|
|
import org.springframework.boot.test.EnvironmentTestUtils;
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
@ -45,29 +44,27 @@ public class ConfigurationPropertiesAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void processAnnotatedBean() {
|
|
|
|
public void processAnnotatedBean() {
|
|
|
|
load(new Class[] {SampleBean.class, ConfigurationPropertiesAutoConfiguration.class},
|
|
|
|
load(new Class[] { SampleBean.class,
|
|
|
|
"foo.name:test");
|
|
|
|
ConfigurationPropertiesAutoConfiguration.class }, "foo.name:test");
|
|
|
|
assertThat(this.context.getBean(SampleBean.class).getName(), is("test"));
|
|
|
|
assertThat(this.context.getBean(SampleBean.class).getName(), is("test"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void processAnnotatedBeanNoAutoConfig() {
|
|
|
|
public void processAnnotatedBeanNoAutoConfig() {
|
|
|
|
load(new Class[] {SampleBean.class}, "foo.name:test");
|
|
|
|
load(new Class[] { SampleBean.class }, "foo.name:test");
|
|
|
|
assertThat(this.context.getBean(SampleBean.class).getName(), is("default"));
|
|
|
|
assertThat(this.context.getBean(SampleBean.class).getName(), is("default"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void load(Class<?>[] configs,
|
|
|
|
private void load(Class<?>[] configs, String... environment) {
|
|
|
|
String... environment) {
|
|
|
|
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context.register(configs);
|
|
|
|
this.context.register(configs);
|
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, environment);
|
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, environment);
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
@Component
|
|
|
|
@ConfigurationProperties("foo")
|
|
|
|
@ConfigurationProperties("foo")
|
|
|
|
private static class SampleBean {
|
|
|
|
static class SampleBean {
|
|
|
|
|
|
|
|
|
|
|
|
private String name = "default";
|
|
|
|
private String name = "default";
|
|
|
|
|
|
|
|
|
|
|
|