Skip to content

Commit

Permalink
Merge branch '2.7.x'
Browse files Browse the repository at this point in the history
Closes gh-33250
  • Loading branch information
wilkinsona committed Nov 18, 2022
2 parents be89f03 + 0a3c403 commit 931cc8a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Expand Up @@ -99,8 +99,10 @@ private Map<String, List<PropertyMigration>> getMatchingProperties(
List<ConfigurationMetadataProperty> candidates = this.allProperties.values().stream().filter(filter)
.collect(Collectors.toList());
getPropertySourcesAsMap().forEach((name, source) -> candidates.forEach((metadata) -> {
ConfigurationProperty configurationProperty = source
.getConfigurationProperty(ConfigurationPropertyName.of(metadata.getId()));
ConfigurationPropertyName metadataName = ConfigurationPropertyName.isValid(metadata.getId())
? ConfigurationPropertyName.of(metadata.getId())
: ConfigurationPropertyName.adapt(metadata.getId(), '.');
ConfigurationProperty configurationProperty = source.getConfigurationProperty(metadataName);
if (configurationProperty != null) {
result.add(name,
new PropertyMigration(configurationProperty, metadata, determineReplacementMetadata(metadata)));
Expand Down
Expand Up @@ -18,6 +18,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -144,6 +145,15 @@ void invalidReplacementHandled() throws IOException {
assertThat(report).doesNotContain("null");
}

@Test
void invalidNameHandledGracefully() {
this.environment.getPropertySources()
.addFirst(new MapPropertySource("first", Collections.singletonMap("invalid.property-name", "value")));
String report = createWarningReport(loadRepository("metadata/sample-metadata-invalid-name.json"));
assertThat(report).isNotNull();
assertThat(report).contains("Key: invalid.PropertyName").contains("Replacement: valid.property-name");
}

private List<String> mapToNames(PropertySources sources) {
List<String> names = new ArrayList<>();
for (PropertySource<?> source : sources) {
Expand Down
@@ -0,0 +1,16 @@
{
"properties": [
{
"name": "invalid.PropertyName",
"type": "java.lang.String",
"deprecation": {
"replacement": "valid.property-name",
"level": "error"
}
},
{
"name": "valid.property-name",
"type": "java.lang.String"
}
]
}

0 comments on commit 931cc8a

Please sign in to comment.