Search in sources :

Example 1 with MockPropertySource

use of org.springframework.mock.env.MockPropertySource in project spring-boot by spring-projects.

the class PropertiesConfigurationFactoryTests method systemPropertyBindingFailuresAreIgnored.

@Test
public void systemPropertyBindingFailuresAreIgnored() throws Exception {
    setupFactory();
    MutablePropertySources propertySources = new MutablePropertySources();
    MockPropertySource propertySource = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
    propertySource.setProperty("doesNotExist", "foo");
    propertySource.setProperty("name", "bar");
    propertySources.addFirst(propertySource);
    this.factory.setPropertySources(propertySources);
    this.factory.setIgnoreUnknownFields(false);
    this.factory.afterPropertiesSet();
}
Also used : MutablePropertySources(org.springframework.core.env.MutablePropertySources) MockPropertySource(org.springframework.mock.env.MockPropertySource) Test(org.junit.Test)

Example 2 with MockPropertySource

use of org.springframework.mock.env.MockPropertySource in project spring-boot by spring-projects.

the class PropertiesConfigurationFactoryTests method systemEnvironmentBindingFailuresAreIgnored.

@Test
public void systemEnvironmentBindingFailuresAreIgnored() throws Exception {
    setupFactory();
    MutablePropertySources propertySources = new MutablePropertySources();
    MockPropertySource propertySource = new MockPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
    propertySource.setProperty("doesNotExist", "foo");
    propertySource.setProperty("name", "bar");
    propertySources.addFirst(propertySource);
    this.factory.setPropertySources(propertySources);
    this.factory.setIgnoreUnknownFields(false);
    this.factory.afterPropertiesSet();
    Foo foo = this.factory.getObject();
    assertThat(foo.name).isEqualTo("bar");
}
Also used : MutablePropertySources(org.springframework.core.env.MutablePropertySources) MockPropertySource(org.springframework.mock.env.MockPropertySource) Test(org.junit.Test)

Example 3 with MockPropertySource

use of org.springframework.mock.env.MockPropertySource in project spring-boot by spring-projects.

the class PropertiesConfigurationFactoryTests method systemEnvironmentNoResolvePlaceholders.

@Test
public void systemEnvironmentNoResolvePlaceholders() throws Exception {
    setupFactory();
    MutablePropertySources propertySources = new MutablePropertySources();
    MockPropertySource propertySource = new MockPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
    propertySource.setProperty("name", "${foo.name:bar}");
    propertySources.addFirst(propertySource);
    this.factory.setPropertySources(propertySources);
    this.factory.setResolvePlaceholders(false);
    this.factory.afterPropertiesSet();
    Foo foo = this.factory.getObject();
    assertThat(foo.name).isEqualTo("${foo.name:bar}");
}
Also used : MutablePropertySources(org.springframework.core.env.MutablePropertySources) MockPropertySource(org.springframework.mock.env.MockPropertySource) Test(org.junit.Test)

Example 4 with MockPropertySource

use of org.springframework.mock.env.MockPropertySource in project spring-framework by spring-projects.

the class PropertySourcesPlaceholderConfigurerTests method explicitPropertySources.

@Test
public void explicitPropertySources() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new MockPropertySource().withProperty("my.name", "foo"));
    PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
    ppc.setPropertySources(propertySources);
    ppc.postProcessBeanFactory(bf);
    assertThat(bf.getBean(TestBean.class).getName(), equalTo("foo"));
    assertEquals(ppc.getAppliedPropertySources().iterator().next(), propertySources.iterator().next());
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) MutablePropertySources(org.springframework.core.env.MutablePropertySources) MockPropertySource(org.springframework.mock.env.MockPropertySource) Test(org.junit.Test)

Example 5 with MockPropertySource

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

Aggregations

MockPropertySource (org.springframework.mock.env.MockPropertySource)19 Test (org.junit.Test)16 MutablePropertySources (org.springframework.core.env.MutablePropertySources)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)4 TestBean (org.springframework.tests.sample.beans.TestBean)4 MockServletContext (org.springframework.mock.web.MockServletContext)3 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)2 MockServletConfig (org.springframework.mock.web.MockServletConfig)2 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)2 StandardServletEnvironment (org.springframework.web.context.support.StandardServletEnvironment)2 BitsquareEnvironment (io.bitsquare.app.BitsquareEnvironment)1 Properties (java.util.Properties)1 Connector (org.eclipse.jetty.server.Connector)1 Server (org.eclipse.jetty.server.Server)1 SelectChannelConnector (org.eclipse.jetty.server.nio.SelectChannelConnector)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1