Skip to content

MapPropertySource changes are not reflected in the adapted ConfigurationPropertySource #13344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ private Cache getCache() {
}

private Object getCacheKey() {
if (getPropertySource() instanceof MapPropertySource) {
return ((MapPropertySource) getPropertySource()).getSource().keySet();
}
// gh-13344
return getPropertySource().getPropertyNames();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Ben Hale
* @author Fahim Farook
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("log4j*.jar")
Expand Down Expand Up @@ -500,12 +501,23 @@ public void systemPropertiesAreSetForLoggingConfiguration() {
@Test
Copy link
Contributor Author

@fahimfarookme fahimfarookme Jun 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below test case was passing before due to a side-effect of the issue I reported in SpringIterableConfigurationPropertySource. ${pid} was resolvable.

public void environmentPropertiesIgnoreUnresolvablePlaceholders() {
// gh-7719
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
"logging.pattern.console=console ${doesnotexist}");
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN))
.isEqualTo("console ${doesnotexist}");
}

@Test
public void environmentPropertiesResolvePlaceholders() {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
"logging.pattern.console=console ${pid}");
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN))
.isEqualTo("console ${pid}");
.isEqualTo(this.context.getEnvironment()
.getProperty("logging.pattern.console"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*
* @author Phillip Webb
* @author Madhura Bhave
* @author Fahim Farook
*/
public class SpringIterableConfigurationPropertySourceTests {

Expand Down Expand Up @@ -157,6 +158,24 @@ public void containsDescendantOfShouldCheckSourceNames() {
.isEqualTo(ConfigurationPropertyState.ABSENT);
}

@SuppressWarnings("unchecked")
@Test
public void propertySourceChangeReflects() {
// gh-13344
final Map<String, Object> source = new LinkedHashMap<>();
source.put("key1", "value1");
source.put("key2", "value2");
final EnumerablePropertySource<?> propertySource = new MapPropertySource("test",
source);
final SpringIterableConfigurationPropertySource adapter = new SpringIterableConfigurationPropertySource(
propertySource, DefaultPropertyMapper.INSTANCE);
assertThat(adapter.stream().count()).isEqualTo(2);

((Map<String, Object>) adapter.getPropertySource().getSource()).put("key3",
"value3");
assertThat(adapter.stream().count()).isEqualTo(3);
}

/**
* Test {@link PropertySource} that's also an {@link OriginLookup}.
*/
Expand Down