@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"); }
@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"); }
@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"); }
@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("random")); setupFactory(); this.factory.setPropertySources(propertySources); this.factory.afterPropertiesSet(); Foo foo = this.factory.getObject(); assertEquals("blah", foo.name); }