Add support for property deprecation
Previously, an item could only have a 'deprecated' boolean flag to indicate that the property is deprecated. It is desirable to provide an additional description for the deprecation as well as the name of the property to use instead. The `deprecated` boolean flag is now supported. Instead, a `deprecated` object can be specified with two optional attributes: `reason` to provide an explanation for the deprecation and `replacement` to refer to the property that should be used instead. If none of them is present, an empty deprecation object should be set. For backward compatibility, the `deprecated` field is still set. Deprecation information can only set via manual meta-data. Closes gh-3449
This commit is contained in:
@@ -24,7 +24,9 @@ import org.json.JSONException;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link JsonReader}
|
||||
@@ -130,6 +132,30 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
|
||||
assertProperty(item, "spring.root.name", "spring.root.name", String.class, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deprecatedMetadata() throws IOException {
|
||||
RawConfigurationMetadata rawMetadata = readFor("deprecated");
|
||||
List<ConfigurationMetadataItem> items = rawMetadata.getItems();
|
||||
assertEquals(3, items.size());
|
||||
|
||||
ConfigurationMetadataItem item = items.get(0);
|
||||
assertProperty(item, "server.port", "server.port", Integer.class, null);
|
||||
assertTrue(item.isDeprecated());
|
||||
assertEquals("Server namespace has moved to spring.server", item.getDeprecation().getReason());
|
||||
assertEquals("server.spring.port", item.getDeprecation().getReplacement());
|
||||
|
||||
ConfigurationMetadataItem item2 = items.get(1);
|
||||
assertProperty(item2, "server.cluster-name", "server.cluster-name", String.class, null);
|
||||
assertTrue(item2.isDeprecated());
|
||||
assertEquals(null, item2.getDeprecation().getReason());
|
||||
assertEquals(null, item2.getDeprecation().getReplacement());
|
||||
|
||||
ConfigurationMetadataItem item3 = items.get(2);
|
||||
assertProperty(item3, "spring.server.name", "spring.server.name", String.class, null);
|
||||
assertFalse(item3.isDeprecated());
|
||||
assertEquals(null, item3.getDeprecation());
|
||||
}
|
||||
|
||||
RawConfigurationMetadata readFor(String path) throws IOException {
|
||||
return this.reader.read(getInputStreamFor(path), DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"name": "server.port",
|
||||
"type": "java.lang.Integer",
|
||||
"deprecation": {
|
||||
"reason": "Server namespace has moved to spring.server",
|
||||
"replacement": "server.spring.port"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "server.cluster-name",
|
||||
"type": "java.lang.String",
|
||||
"deprecated": true
|
||||
},
|
||||
{
|
||||
"name": "spring.server.name",
|
||||
"type": "java.lang.String",
|
||||
"deprecated": false
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user