Search in sources :

Example 1 with RandomValuePropertySource

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

the class PropertiesConfigurationFactoryTests method testBindWithDashPrefix.

@Test
public void testBindWithDashPrefix() throws Exception {
    // gh-4045
    this.targetName = "foo-bar";
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new SystemEnvironmentPropertySource("systemEnvironment", Collections.<String, Object>singletonMap("FOO_BAR_NAME", "blah")));
    propertySources.addLast(new RandomValuePropertySource());
    setupFactory();
    this.factory.setPropertySources(propertySources);
    this.factory.afterPropertiesSet();
    Foo foo = this.factory.getObject();
    assertThat(foo.name).isEqualTo("blah");
}
Also used : SystemEnvironmentPropertySource(org.springframework.core.env.SystemEnvironmentPropertySource) RandomValuePropertySource(org.springframework.boot.env.RandomValuePropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Test(org.junit.Test)

Example 2 with RandomValuePropertySource

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

the class PropertiesConfigurationFactoryTests method testBindWithDelimitedPrefixUsingDifferentDelimiter.

@Test
public void testBindWithDelimitedPrefixUsingDifferentDelimiter() throws Exception {
    this.targetName = "env.foo";
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new SystemEnvironmentPropertySource("systemEnvironment", Collections.<String, Object>singletonMap("ENV_FOO_NAME", "blah")));
    propertySources.addLast(new RandomValuePropertySource("random"));
    this.ignoreUnknownFields = false;
    setupFactory();
    this.factory.setPropertySources(propertySources);
    this.factory.afterPropertiesSet();
    Foo foo = this.factory.getObject();
    assertThat(foo.name).isEqualTo("blah");
}
Also used : SystemEnvironmentPropertySource(org.springframework.core.env.SystemEnvironmentPropertySource) RandomValuePropertySource(org.springframework.boot.env.RandomValuePropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Test(org.junit.Test)

Example 3 with RandomValuePropertySource

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

the class PropertiesConfigurationFactoryTests method testBindWithDelimitedPrefixUsingMatchingDelimiter.

@Test
public void testBindWithDelimitedPrefixUsingMatchingDelimiter() throws Exception {
    this.targetName = "env_foo";
    this.ignoreUnknownFields = false;
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new SystemEnvironmentPropertySource("systemEnvironment", Collections.<String, Object>singletonMap("ENV_FOO_NAME", "blah")));
    propertySources.addLast(new RandomValuePropertySource("random"));
    setupFactory();
    this.factory.setPropertySources(propertySources);
    this.factory.afterPropertiesSet();
    Foo foo = this.factory.getObject();
    assertThat(foo.name).isEqualTo("blah");
}
Also used : SystemEnvironmentPropertySource(org.springframework.core.env.SystemEnvironmentPropertySource) RandomValuePropertySource(org.springframework.boot.env.RandomValuePropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 RandomValuePropertySource (org.springframework.boot.env.RandomValuePropertySource)3 MutablePropertySources (org.springframework.core.env.MutablePropertySources)3 SystemEnvironmentPropertySource (org.springframework.core.env.SystemEnvironmentPropertySource)3