use of org.springframework.mock.env.MockEnvironment in project spring-boot by spring-projects.
the class LogbackLoggingSystemTests method testLevelPatternProperty.
@Test
public void testLevelPatternProperty() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("logging.pattern.level", "X%clr(%p)X");
LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(environment);
this.loggingSystem.initialize(loggingInitializationContext, null, null);
this.logger.info("Hello world");
String output = this.output.toString().trim();
assertThat(getLineWithText(output, "Hello world")).contains("XINFOX");
}
use of org.springframework.mock.env.MockEnvironment in project spring-framework by spring-projects.
the class PropertySourcesPlaceholderConfigurerTests method optionalPropertyWithValue.
@Test
public void optionalPropertyWithValue() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setConversionService(new DefaultConversionService());
bf.registerBeanDefinition("testBean", genericBeanDefinition(OptionalTestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
MockEnvironment env = new MockEnvironment();
env.setProperty("my.name", "myValue");
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setEnvironment(env);
ppc.setIgnoreUnresolvablePlaceholders(true);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(OptionalTestBean.class).getName(), equalTo(Optional.of("myValue")));
}
use of org.springframework.mock.env.MockEnvironment in project spring-framework by spring-projects.
the class PropertySourcesPlaceholderConfigurerTests method withNonEnumerablePropertySource.
@Test
public void withNonEnumerablePropertySource() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${foo}").getBeanDefinition());
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
PropertySource<?> ps = new PropertySource<Object>("simplePropertySource", new Object()) {
@Override
public Object getProperty(String key) {
return "bar";
}
};
MockEnvironment env = new MockEnvironment();
env.getPropertySources().addFirst(ps);
ppc.setEnvironment(env);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("bar"));
}
use of org.springframework.mock.env.MockEnvironment in project spring-framework by spring-projects.
the class PropertySourcesPlaceholderConfigurerTests method trimValuesIsOffByDefault.
@Test
public void trimValuesIsOffByDefault() {
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean", rootBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
ppc.setEnvironment(new MockEnvironment().withProperty("my.name", " myValue "));
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo(" myValue "));
}
use of org.springframework.mock.env.MockEnvironment in project spring-framework by spring-projects.
the class PropertySourcesPlaceholderConfigurerTests method explicitPropertySourcesExcludesEnvironment.
@Test
public void explicitPropertySourcesExcludesEnvironment() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addLast(new MockPropertySource());
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setPropertySources(propertySources);
ppc.setEnvironment(new MockEnvironment().withProperty("my.name", "env"));
ppc.setIgnoreUnresolvablePlaceholders(true);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("${my.name}"));
assertEquals(ppc.getAppliedPropertySources().iterator().next(), propertySources.iterator().next());
}
Aggregations