use of cn.taketoday.core.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class PropertySourcesPlaceholderConfigurerTests method explicitPropertySources.
@Test
public void explicitPropertySources() {
StandardBeanFactory bf = new StandardBeanFactory();
bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
PropertySources propertySources = new PropertySources();
propertySources.addLast(new MockPropertySource().withProperty("my.name", "foo"));
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setPropertySources(propertySources);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("foo");
assertThat(propertySources.iterator().next()).isEqualTo(ppc.getAppliedPropertySources().iterator().next());
}
use of cn.taketoday.core.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class PropertySourcesPlaceholderConfigurerTests method explicitPropertySourcesExcludesEnvironment.
@Test
public void explicitPropertySourcesExcludesEnvironment() {
StandardBeanFactory bf = new StandardBeanFactory();
bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
PropertySources propertySources = new PropertySources();
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()).isEqualTo("${my.name}");
assertThat(propertySources.iterator().next()).isEqualTo(ppc.getAppliedPropertySources().iterator().next());
}
use of cn.taketoday.core.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class EnvironmentAccessorTests method braceAccess.
@Test
public void braceAccess() {
StandardBeanFactory bf = new StandardBeanFactory();
bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "#{environment['my.name']}").getBeanDefinition());
GenericApplicationContext ctx = new GenericApplicationContext(bf);
ctx.getEnvironment().getPropertySources().addFirst(new MockPropertySource().withProperty("my.name", "myBean"));
ctx.refresh();
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("myBean");
ctx.close();
}
use of cn.taketoday.core.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class AbstractApplicationEnvironmentTests method getActiveProfilesDoesNotResolveProperty.
@Test
void getActiveProfilesDoesNotResolveProperty() {
StandardEnvironment environment = createEnvironment();
new MockPropertySource().withProperty("", "");
environment.getPropertySources().addFirst(new MockPropertySource().withProperty(AbstractEnvironment.KEY_ACTIVE_PROFILES, "test"));
assertThat(environment.getActiveProfiles()).isEmpty();
}
use of cn.taketoday.core.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class AbstractApplicationEnvironmentTests method getDefaultProfilesDoesNotResolveProperty.
@Test
void getDefaultProfilesDoesNotResolveProperty() {
StandardEnvironment environment = createEnvironment();
new MockPropertySource().withProperty("", "");
environment.getPropertySources().addFirst(new MockPropertySource().withProperty(AbstractEnvironment.KEY_DEFAULT_PROFILES, "test"));
assertThat(environment.getDefaultProfiles()).containsExactly("default");
}
Aggregations