Search in sources :

Example 61 with MockEnvironment

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()));
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) MockEnvironment(org.springframework.mock.env.MockEnvironment) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 62 with MockEnvironment

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"));
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 63 with MockEnvironment

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());
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MockEnvironment(org.springframework.mock.env.MockEnvironment) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Test(org.junit.Test)

Aggregations

MockEnvironment (org.springframework.mock.env.MockEnvironment)63 Test (org.junit.Test)53 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)10 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)9 TestBean (org.springframework.tests.sample.beans.TestBean)7 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)6 LoggingInitializationContext (org.springframework.boot.logging.LoggingInitializationContext)5 CoffeeNetConfigurationProperties (coffee.synyx.autoconfigure.CoffeeNetConfigurationProperties)4 URL (java.net.URL)4 Before (org.junit.Before)4 ServerProperties (org.springframework.boot.autoconfigure.web.ServerProperties)4 InetUtils (org.springframework.cloud.commons.util.InetUtils)4 InetUtilsProperties (org.springframework.cloud.commons.util.InetUtilsProperties)4 Environment (org.springframework.core.env.Environment)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 MutablePropertySources (org.springframework.core.env.MutablePropertySources)3 WebClient (com.gargoylesoftware.htmlunit.WebClient)2 WebConnection (com.gargoylesoftware.htmlunit.WebConnection)2 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2