Fix source detection in case of multiple candidates
This commit improves the detection of a property source when more than one group with the same type exist. Closes gh-16549
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -129,6 +129,31 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiGroups() throws IOException {
|
||||
try (InputStream in = getInputStreamFor("multi-groups")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(in).build();
|
||||
assertThat(repo.getAllGroups()).containsOnlyKeys("test.group.one.retry",
|
||||
"test.group.two.retry", "test.group.one.retry.specific");
|
||||
ConfigurationMetadataGroup one = repo.getAllGroups()
|
||||
.get("test.group.one.retry");
|
||||
assertThat(one.getSources()).containsOnlyKeys("com.example.Retry");
|
||||
assertThat(one.getProperties())
|
||||
.containsOnlyKeys("test.group.one.retry.enabled");
|
||||
ConfigurationMetadataGroup two = repo.getAllGroups()
|
||||
.get("test.group.two.retry");
|
||||
assertThat(two.getSources()).containsOnlyKeys("com.example.Retry");
|
||||
assertThat(two.getProperties())
|
||||
.containsOnlyKeys("test.group.two.retry.enabled");
|
||||
ConfigurationMetadataGroup oneSpecific = repo.getAllGroups()
|
||||
.get("test.group.one.retry.specific");
|
||||
assertThat(oneSpecific.getSources()).containsOnlyKeys("com.example.Retry");
|
||||
assertThat(oneSpecific.getProperties())
|
||||
.containsOnlyKeys("test.group.one.retry.specific.enabled");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void builderInstancesAreIsolated() throws IOException {
|
||||
try (InputStream foo = getInputStreamFor("foo");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -199,6 +199,25 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
|
||||
.isEqualTo(Deprecation.Level.WARNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiGroupsMetadata() throws IOException {
|
||||
RawConfigurationMetadata rawMetadata = readFor("multi-groups");
|
||||
List<ConfigurationMetadataItem> items = rawMetadata.getItems();
|
||||
assertThat(items).hasSize(3);
|
||||
|
||||
ConfigurationMetadataItem item = items.get(0);
|
||||
assertThat(item.getName()).isEqualTo("enabled");
|
||||
assertThat(item.getSourceType()).isEqualTo("com.example.Retry");
|
||||
|
||||
ConfigurationMetadataItem item2 = items.get(1);
|
||||
assertThat(item2.getName()).isEqualTo("enabled");
|
||||
assertThat(item2.getSourceType()).isEqualTo("com.example.Retry");
|
||||
|
||||
ConfigurationMetadataItem item3 = items.get(2);
|
||||
assertThat(item3.getName()).isEqualTo("enabled");
|
||||
assertThat(item3.getSourceType()).isEqualTo("com.example.Retry");
|
||||
}
|
||||
|
||||
RawConfigurationMetadata readFor(String path) throws IOException {
|
||||
return this.reader.read(getInputStreamFor(path), DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"groups": [
|
||||
{
|
||||
"name": "test.group.one.retry",
|
||||
"type": "com.example.Retry",
|
||||
"sourceType": "org.acme.config.TestApp",
|
||||
"sourceMethod": "one()"
|
||||
},
|
||||
{
|
||||
"name": "test.group.two.retry",
|
||||
"type": "com.example.Retry",
|
||||
"sourceType": "org.acme.config.TestApp",
|
||||
"sourceMethod": "two()"
|
||||
},
|
||||
{
|
||||
"name": "test.group.one.retry.specific",
|
||||
"type": "com.example.Retry",
|
||||
"sourceType": "org.acme.config.TestApp",
|
||||
"sourceMethod": "two()"
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "test.group.one.retry.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Whether publishing retries are enabled.",
|
||||
"sourceType": "com.example.Retry",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "test.group.two.retry.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Whether publishing retries are enabled.",
|
||||
"sourceType": "com.example.Retry",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "test.group.one.retry.specific.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Whether publishing retries are enabled.",
|
||||
"sourceType": "com.example.Retry",
|
||||
"defaultValue": false
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user