use of org.springframework.mock.env.MockEnvironment in project spring-framework by spring-projects.
the class PropertySourcesPlaceholderConfigurerTests method replacementFromEnvironmentProperties.
@Test
public void replacementFromEnvironmentProperties() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
MockEnvironment env = new MockEnvironment();
env.setProperty("my.name", "myValue");
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setEnvironment(env);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("myValue"));
assertThat(ppc.getAppliedPropertySources(), not(nullValue()));
}
use of org.springframework.mock.env.MockEnvironment in project spring-framework by spring-projects.
the class TestPropertySourceUtilsTests method addInlinedPropertiesToEnvironmentWithMalformedUnicodeInValue.
@Test
public void addInlinedPropertiesToEnvironmentWithMalformedUnicodeInValue() {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Failed to load test environment property");
addInlinedPropertiesToEnvironment(new MockEnvironment(), asArray("key = \\uZZZZ"));
}
use of org.springframework.mock.env.MockEnvironment in project spring-framework by spring-projects.
the class TestPropertySourceUtilsTests method addInlinedPropertiesToEnvironmentWithEmptyProperty.
@Test
@SuppressWarnings("rawtypes")
public void addInlinedPropertiesToEnvironmentWithEmptyProperty() {
ConfigurableEnvironment environment = new MockEnvironment();
MutablePropertySources propertySources = environment.getPropertySources();
propertySources.remove(MockPropertySource.MOCK_PROPERTIES_PROPERTY_SOURCE_NAME);
assertEquals(0, propertySources.size());
addInlinedPropertiesToEnvironment(environment, asArray(" "));
assertEquals(1, propertySources.size());
assertEquals(0, ((Map) propertySources.iterator().next().getSource()).size());
}
Aggregations