use of cn.taketoday.core.env.MockPropertySource in project today-framework by TAKETODAY.
the class PropertySourcesPlaceholderConfigurerTests method explicitPropertySourcesExcludesLocalProperties.
@Test
@SuppressWarnings("serial")
public void explicitPropertySourcesExcludesLocalProperties() {
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.setProperties(new Properties() {
{
put("my.name", "local");
}
});
ppc.setIgnoreUnresolvablePlaceholders(true);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("${my.name}");
}
use of cn.taketoday.core.env.MockPropertySource in project today-framework by TAKETODAY.
the class PropertySourcesPlaceholderConfigurerTests method ignoreUnresolvablePlaceholdersInAtValueAnnotation__falseIsDefault.
@Test
public // https://github.com/spring-projects/spring-framework/issues/27947
void ignoreUnresolvablePlaceholdersInAtValueAnnotation__falseIsDefault() {
MockPropertySource mockPropertySource = new MockPropertySource("test");
mockPropertySource.setProperty("my.key", "${enigma}");
@SuppressWarnings("resource") AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.getEnvironment().getPropertySources().addLast(mockPropertySource);
context.register(IgnoreUnresolvablePlaceholdersFalseConfig.class);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(context::refresh).havingCause().isExactlyInstanceOf(IllegalArgumentException.class).withMessage("Could not resolve placeholder 'enigma' in value \"${enigma}\"");
}
use of cn.taketoday.core.env.MockPropertySource in project today-framework 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");
}
use of cn.taketoday.core.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class PropertySourcesPlaceholderConfigurerTests method ignoreUnresolvablePlaceholdersInAtValueAnnotation_true.
@Test
public // https://github.com/spring-projects/spring-framework/issues/27947
void ignoreUnresolvablePlaceholdersInAtValueAnnotation_true() {
MockPropertySource mockPropertySource = new MockPropertySource("test");
mockPropertySource.setProperty("my.key", "${enigma}");
@SuppressWarnings("resource") AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.getEnvironment().getPropertySources().addLast(mockPropertySource);
context.register(IgnoreUnresolvablePlaceholdersTrueConfig.class);
context.refresh();
IgnoreUnresolvablePlaceholdersTrueConfig config = context.getBean(IgnoreUnresolvablePlaceholdersTrueConfig.class);
assertThat(config.value).isEqualTo("${enigma}");
}
use of cn.taketoday.core.env.MockPropertySource in project today-infrastructure by TAKETODAY.
the class PropertySourcesPlaceholderConfigurerTests method ignoreUnresolvablePlaceholdersInAtValueAnnotation__falseIsDefault.
@Test
public // https://github.com/spring-projects/spring-framework/issues/27947
void ignoreUnresolvablePlaceholdersInAtValueAnnotation__falseIsDefault() {
MockPropertySource mockPropertySource = new MockPropertySource("test");
mockPropertySource.setProperty("my.key", "${enigma}");
@SuppressWarnings("resource") AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.getEnvironment().getPropertySources().addLast(mockPropertySource);
context.register(IgnoreUnresolvablePlaceholdersFalseConfig.class);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(context::refresh).havingCause().isExactlyInstanceOf(IllegalArgumentException.class).withMessage("Could not resolve placeholder 'enigma' in value \"${enigma}\"");
}
Aggregations