Merge branch '2.0.x' into 2.1.x
Closes gh-17078
This commit is contained in:
@@ -53,8 +53,7 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
|
||||
* @return this builder
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
public ConfigurationMetadataRepositoryJsonBuilder withJsonResource(
|
||||
InputStream inputStream) throws IOException {
|
||||
public ConfigurationMetadataRepositoryJsonBuilder withJsonResource(InputStream inputStream) throws IOException {
|
||||
return withJsonResource(inputStream, this.defaultCharset);
|
||||
}
|
||||
|
||||
@@ -70,8 +69,8 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
|
||||
* @return this builder
|
||||
* @throws IOException in case of I/O errors
|
||||
*/
|
||||
public ConfigurationMetadataRepositoryJsonBuilder withJsonResource(
|
||||
InputStream inputStream, Charset charset) throws IOException {
|
||||
public ConfigurationMetadataRepositoryJsonBuilder withJsonResource(InputStream inputStream, Charset charset)
|
||||
throws IOException {
|
||||
if (inputStream == null) {
|
||||
throw new IllegalArgumentException("InputStream must not be null.");
|
||||
}
|
||||
@@ -92,8 +91,7 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
|
||||
return result;
|
||||
}
|
||||
|
||||
private SimpleConfigurationMetadataRepository add(InputStream in, Charset charset)
|
||||
throws IOException {
|
||||
private SimpleConfigurationMetadataRepository add(InputStream in, Charset charset) throws IOException {
|
||||
try {
|
||||
RawConfigurationMetadata metadata = this.reader.read(in, charset);
|
||||
return create(metadata);
|
||||
@@ -103,16 +101,14 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private SimpleConfigurationMetadataRepository create(
|
||||
RawConfigurationMetadata metadata) {
|
||||
private SimpleConfigurationMetadataRepository create(RawConfigurationMetadata metadata) {
|
||||
SimpleConfigurationMetadataRepository repository = new SimpleConfigurationMetadataRepository();
|
||||
repository.add(metadata.getSources());
|
||||
for (ConfigurationMetadataItem item : metadata.getItems()) {
|
||||
ConfigurationMetadataSource source = metadata.getSource(item);
|
||||
repository.add(item, source);
|
||||
}
|
||||
Map<String, ConfigurationMetadataProperty> allProperties = repository
|
||||
.getAllProperties();
|
||||
Map<String, ConfigurationMetadataProperty> allProperties = repository.getAllProperties();
|
||||
for (ConfigurationMetadataHint hint : metadata.getHints()) {
|
||||
ConfigurationMetadataProperty property = allProperties.get(hint.getId());
|
||||
if (property != null) {
|
||||
@@ -134,14 +130,12 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
|
||||
return repository;
|
||||
}
|
||||
|
||||
private void addValueHints(ConfigurationMetadataProperty property,
|
||||
ConfigurationMetadataHint hint) {
|
||||
private void addValueHints(ConfigurationMetadataProperty property, ConfigurationMetadataHint hint) {
|
||||
property.getHints().getValueHints().addAll(hint.getValueHints());
|
||||
property.getHints().getValueProviders().addAll(hint.getValueProviders());
|
||||
}
|
||||
|
||||
private void addMapHints(ConfigurationMetadataProperty property,
|
||||
ConfigurationMetadataHint hint) {
|
||||
private void addMapHints(ConfigurationMetadataProperty property, ConfigurationMetadataHint hint) {
|
||||
property.getHints().getKeyHints().addAll(hint.getValueHints());
|
||||
property.getHints().getKeyProviders().addAll(hint.getValueProviders());
|
||||
}
|
||||
@@ -153,8 +147,7 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
|
||||
* @return a new {@link ConfigurationMetadataRepositoryJsonBuilder} instance.
|
||||
* @throws IOException on error
|
||||
*/
|
||||
public static ConfigurationMetadataRepositoryJsonBuilder create(
|
||||
InputStream... inputStreams) throws IOException {
|
||||
public static ConfigurationMetadataRepositoryJsonBuilder create(InputStream... inputStreams) throws IOException {
|
||||
ConfigurationMetadataRepositoryJsonBuilder builder = create();
|
||||
for (InputStream inputStream : inputStreams) {
|
||||
builder = builder.withJsonResource(inputStream);
|
||||
@@ -176,8 +169,7 @@ public final class ConfigurationMetadataRepositoryJsonBuilder {
|
||||
* @param defaultCharset the default charset to use
|
||||
* @return a new {@link ConfigurationMetadataRepositoryJsonBuilder} instance.
|
||||
*/
|
||||
public static ConfigurationMetadataRepositoryJsonBuilder create(
|
||||
Charset defaultCharset) {
|
||||
public static ConfigurationMetadataRepositoryJsonBuilder create(Charset defaultCharset) {
|
||||
return new ConfigurationMetadataRepositoryJsonBuilder(defaultCharset);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -90,8 +90,8 @@ public class Deprecation implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Deprecation{" + "level='" + this.level + '\'' + ", reason='" + this.reason
|
||||
+ '\'' + ", replacement='" + this.replacement + '\'' + '}';
|
||||
return "Deprecation{" + "level='" + this.level + '\'' + ", reason='" + this.reason + '\'' + ", replacement='"
|
||||
+ this.replacement + '\'' + '}';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
@@ -40,8 +40,7 @@ class JsonReader {
|
||||
|
||||
private final SentenceExtractor sentenceExtractor = new SentenceExtractor();
|
||||
|
||||
public RawConfigurationMetadata read(InputStream in, Charset charset)
|
||||
throws IOException {
|
||||
public RawConfigurationMetadata read(InputStream in, Charset charset) throws IOException {
|
||||
try {
|
||||
JSONObject json = readJson(in, charset);
|
||||
List<ConfigurationMetadataSource> groups = parseAllSources(json);
|
||||
@@ -60,8 +59,7 @@ class JsonReader {
|
||||
}
|
||||
}
|
||||
|
||||
private List<ConfigurationMetadataSource> parseAllSources(JSONObject root)
|
||||
throws Exception {
|
||||
private List<ConfigurationMetadataSource> parseAllSources(JSONObject root) throws Exception {
|
||||
List<ConfigurationMetadataSource> result = new ArrayList<>();
|
||||
if (!root.has("groups")) {
|
||||
return result;
|
||||
@@ -74,8 +72,7 @@ class JsonReader {
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<ConfigurationMetadataItem> parseAllItems(JSONObject root)
|
||||
throws Exception {
|
||||
private List<ConfigurationMetadataItem> parseAllItems(JSONObject root) throws Exception {
|
||||
List<ConfigurationMetadataItem> result = new ArrayList<>();
|
||||
if (!root.has("properties")) {
|
||||
return result;
|
||||
@@ -88,8 +85,7 @@ class JsonReader {
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<ConfigurationMetadataHint> parseAllHints(JSONObject root)
|
||||
throws Exception {
|
||||
private List<ConfigurationMetadataHint> parseAllHints(JSONObject root) throws Exception {
|
||||
List<ConfigurationMetadataHint> result = new ArrayList<>();
|
||||
if (!root.has("hints")) {
|
||||
return result;
|
||||
@@ -139,8 +135,7 @@ class JsonReader {
|
||||
valueHint.setValue(readItemValue(value.get("value")));
|
||||
String description = value.optString("description", null);
|
||||
valueHint.setDescription(description);
|
||||
valueHint.setShortDescription(
|
||||
this.sentenceExtractor.getFirstSentence(description));
|
||||
valueHint.setShortDescription(this.sentenceExtractor.getFirstSentence(description));
|
||||
hint.getValueHints().add(valueHint);
|
||||
}
|
||||
}
|
||||
@@ -155,8 +150,7 @@ class JsonReader {
|
||||
Iterator<?> keys = parameters.keys();
|
||||
while (keys.hasNext()) {
|
||||
String key = (String) keys.next();
|
||||
valueProvider.getParameters().put(key,
|
||||
readItemValue(parameters.get(key)));
|
||||
valueProvider.getParameters().put(key, readItemValue(parameters.get(key)));
|
||||
}
|
||||
}
|
||||
hint.getValueProviders().add(valueProvider);
|
||||
@@ -169,13 +163,11 @@ class JsonReader {
|
||||
if (object.has("deprecation")) {
|
||||
JSONObject deprecationJsonObject = object.getJSONObject("deprecation");
|
||||
Deprecation deprecation = new Deprecation();
|
||||
deprecation.setLevel(parseDeprecationLevel(
|
||||
deprecationJsonObject.optString("level", null)));
|
||||
deprecation.setLevel(parseDeprecationLevel(deprecationJsonObject.optString("level", null)));
|
||||
String reason = deprecationJsonObject.optString("reason", null);
|
||||
deprecation.setReason(reason);
|
||||
deprecation.setShortReason(this.sentenceExtractor.getFirstSentence(reason));
|
||||
deprecation
|
||||
.setReplacement(deprecationJsonObject.optString("replacement", null));
|
||||
deprecation.setReplacement(deprecationJsonObject.optString("replacement", null));
|
||||
return deprecation;
|
||||
}
|
||||
return object.optBoolean("deprecated") ? new Deprecation() : null;
|
||||
|
||||
@@ -34,8 +34,7 @@ class RawConfigurationMetadata {
|
||||
|
||||
private final List<ConfigurationMetadataHint> hints;
|
||||
|
||||
RawConfigurationMetadata(List<ConfigurationMetadataSource> sources,
|
||||
List<ConfigurationMetadataItem> items,
|
||||
RawConfigurationMetadata(List<ConfigurationMetadataSource> sources, List<ConfigurationMetadataItem> items,
|
||||
List<ConfigurationMetadataHint> hints) {
|
||||
this.sources = new ArrayList<>(sources);
|
||||
this.items = new ArrayList<>(items);
|
||||
@@ -56,9 +55,7 @@ class RawConfigurationMetadata {
|
||||
return this.sources.stream()
|
||||
.filter((candidate) -> item.getSourceType().equals(candidate.getType())
|
||||
&& item.getId().startsWith(candidate.getGroupId()))
|
||||
.max(Comparator
|
||||
.comparingInt((candidate) -> candidate.getGroupId().length()))
|
||||
.orElse(null);
|
||||
.max(Comparator.comparingInt((candidate) -> candidate.getGroupId().length())).orElse(null);
|
||||
}
|
||||
|
||||
public List<ConfigurationMetadataItem> getItems() {
|
||||
|
||||
@@ -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.
|
||||
@@ -29,8 +29,7 @@ import java.util.Map;
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class SimpleConfigurationMetadataRepository
|
||||
implements ConfigurationMetadataRepository, Serializable {
|
||||
public class SimpleConfigurationMetadataRepository implements ConfigurationMetadataRepository, Serializable {
|
||||
|
||||
private final Map<String, ConfigurationMetadataGroup> allGroups = new HashMap<>();
|
||||
|
||||
@@ -73,8 +72,7 @@ public class SimpleConfigurationMetadataRepository
|
||||
* @param property the property to add
|
||||
* @param source the source
|
||||
*/
|
||||
public void add(ConfigurationMetadataProperty property,
|
||||
ConfigurationMetadataSource source) {
|
||||
public void add(ConfigurationMetadataProperty property, ConfigurationMetadataSource source) {
|
||||
if (source != null) {
|
||||
putIfAbsent(source.getProperties(), property.getId(), property);
|
||||
}
|
||||
@@ -93,11 +91,9 @@ public class SimpleConfigurationMetadataRepository
|
||||
}
|
||||
else {
|
||||
// Merge properties
|
||||
group.getProperties().forEach((name, value) -> putIfAbsent(
|
||||
existingGroup.getProperties(), name, value));
|
||||
group.getProperties().forEach((name, value) -> putIfAbsent(existingGroup.getProperties(), name, value));
|
||||
// Merge sources
|
||||
group.getSources().forEach((name,
|
||||
value) -> putIfAbsent(existingGroup.getSources(), name, value));
|
||||
group.getSources().forEach((name, value) -> putIfAbsent(existingGroup.getSources(), name, value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -74,8 +74,7 @@ public class ValueHint implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ValueHint{" + "value=" + this.value + ", description='" + this.description
|
||||
+ '\'' + '}';
|
||||
return "ValueHint{" + "value=" + this.value + ", description='" + this.description + '\'' + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -59,8 +59,7 @@ public class ValueProvider implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ValueProvider{" + "name='" + this.name + ", parameters=" + this.parameters
|
||||
+ '}';
|
||||
return "ValueProvider{" + "name='" + this.name + ", parameters=" + this.parameters + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -31,16 +31,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public abstract class AbstractConfigurationMetadataTests {
|
||||
|
||||
protected void assertSource(ConfigurationMetadataSource actual, String groupId,
|
||||
String type, String sourceType) {
|
||||
protected void assertSource(ConfigurationMetadataSource actual, String groupId, String type, String sourceType) {
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual.getGroupId()).isEqualTo(groupId);
|
||||
assertThat(actual.getType()).isEqualTo(type);
|
||||
assertThat(actual.getSourceType()).isEqualTo(sourceType);
|
||||
}
|
||||
|
||||
protected void assertProperty(ConfigurationMetadataProperty actual, String id,
|
||||
String name, Class<?> type, Object defaultValue) {
|
||||
protected void assertProperty(ConfigurationMetadataProperty actual, String id, String name, Class<?> type,
|
||||
Object defaultValue) {
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual.getId()).isEqualTo(id);
|
||||
assertThat(actual.getName()).isEqualTo(name);
|
||||
@@ -55,8 +54,7 @@ public abstract class AbstractConfigurationMetadataTests {
|
||||
}
|
||||
|
||||
protected InputStream getInputStreamFor(String name) throws IOException {
|
||||
Resource r = new ClassPathResource(
|
||||
"metadata/configuration-metadata-" + name + ".json");
|
||||
Resource r = new ClassPathResource("metadata/configuration-metadata-" + name + ".json");
|
||||
return r.getInputStream();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,25 +30,21 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ConfigurationMetadataRepositoryJsonBuilderTests
|
||||
extends AbstractConfigurationMetadataTests {
|
||||
public class ConfigurationMetadataRepositoryJsonBuilderTests extends AbstractConfigurationMetadataTests {
|
||||
|
||||
@Test
|
||||
public void nullResource() throws IOException {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ConfigurationMetadataRepositoryJsonBuilder.create()
|
||||
.withJsonResource(null));
|
||||
.isThrownBy(() -> ConfigurationMetadataRepositoryJsonBuilder.create().withJsonResource(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleRepository() throws IOException {
|
||||
try (InputStream foo = getInputStreamFor("foo")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(foo).build();
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo).build();
|
||||
validateFoo(repo);
|
||||
assertThat(repo.getAllGroups()).hasSize(1);
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description",
|
||||
"spring.foo.counter");
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter");
|
||||
assertThat(repo.getAllProperties()).hasSize(3);
|
||||
}
|
||||
}
|
||||
@@ -56,63 +52,54 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
|
||||
@Test
|
||||
public void hintsOnMaps() throws IOException {
|
||||
try (InputStream map = getInputStreamFor("map")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(map).build();
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(map).build();
|
||||
validateMap(repo);
|
||||
assertThat(repo.getAllGroups()).hasSize(1);
|
||||
contains(repo.getAllProperties(), "spring.map.first", "spring.map.second",
|
||||
"spring.map.keys", "spring.map.values");
|
||||
contains(repo.getAllProperties(), "spring.map.first", "spring.map.second", "spring.map.keys",
|
||||
"spring.map.values");
|
||||
assertThat(repo.getAllProperties()).hasSize(4);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void severalRepositoriesNoConflict() throws IOException {
|
||||
try (InputStream foo = getInputStreamFor("foo");
|
||||
InputStream bar = getInputStreamFor("bar")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(foo, bar).build();
|
||||
try (InputStream foo = getInputStreamFor("foo"); InputStream bar = getInputStreamFor("bar")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, bar).build();
|
||||
validateFoo(repo);
|
||||
validateBar(repo);
|
||||
assertThat(repo.getAllGroups()).hasSize(2);
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description",
|
||||
"spring.foo.counter", "spring.bar.name", "spring.bar.description",
|
||||
"spring.bar.counter");
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter",
|
||||
"spring.bar.name", "spring.bar.description", "spring.bar.counter");
|
||||
assertThat(repo.getAllProperties()).hasSize(6);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repositoryWithRoot() throws IOException {
|
||||
try (InputStream foo = getInputStreamFor("foo");
|
||||
InputStream root = getInputStreamFor("root")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(foo, root).build();
|
||||
try (InputStream foo = getInputStreamFor("foo"); InputStream root = getInputStreamFor("root")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, root).build();
|
||||
validateFoo(repo);
|
||||
assertThat(repo.getAllGroups()).hasSize(2);
|
||||
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description",
|
||||
"spring.foo.counter", "spring.root.name", "spring.root2.name");
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter",
|
||||
"spring.root.name", "spring.root2.name");
|
||||
assertThat(repo.getAllProperties()).hasSize(5);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void severalRepositoriesIdenticalGroups() throws IOException {
|
||||
try (InputStream foo = getInputStreamFor("foo");
|
||||
InputStream foo2 = getInputStreamFor("foo2")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(foo, foo2).build();
|
||||
try (InputStream foo = getInputStreamFor("foo"); InputStream foo2 = getInputStreamFor("foo2")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(foo, foo2).build();
|
||||
assertThat(repo.getAllGroups()).hasSize(1);
|
||||
ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo");
|
||||
contains(group.getSources(), "org.acme.Foo", "org.acme.Foo2",
|
||||
"org.springframework.boot.FooProperties");
|
||||
contains(group.getSources(), "org.acme.Foo", "org.acme.Foo2", "org.springframework.boot.FooProperties");
|
||||
assertThat(group.getSources()).hasSize(3);
|
||||
contains(group.getProperties(), "spring.foo.name", "spring.foo.description",
|
||||
"spring.foo.counter", "spring.foo.enabled", "spring.foo.type");
|
||||
contains(group.getProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter",
|
||||
"spring.foo.enabled", "spring.foo.type");
|
||||
assertThat(group.getProperties()).hasSize(5);
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description",
|
||||
"spring.foo.counter", "spring.foo.enabled", "spring.foo.type");
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter",
|
||||
"spring.foo.enabled", "spring.foo.type");
|
||||
assertThat(repo.getAllProperties()).hasSize(5);
|
||||
}
|
||||
}
|
||||
@@ -120,8 +107,7 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
|
||||
@Test
|
||||
public void emptyGroups() throws IOException {
|
||||
try (InputStream in = getInputStreamFor("empty-groups")) {
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(in).build();
|
||||
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder.create(in).build();
|
||||
validateEmptyGroup(repo);
|
||||
assertThat(repo.getAllGroups()).hasSize(1);
|
||||
contains(repo.getAllProperties(), "name", "title");
|
||||
@@ -132,39 +118,28 @@ 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");
|
||||
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(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(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");
|
||||
assertThat(oneSpecific.getProperties()).containsOnlyKeys("test.group.one.retry.specific.enabled");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void builderInstancesAreIsolated() throws IOException {
|
||||
try (InputStream foo = getInputStreamFor("foo");
|
||||
InputStream bar = getInputStreamFor("bar")) {
|
||||
ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create();
|
||||
ConfigurationMetadataRepository firstRepo = builder.withJsonResource(foo)
|
||||
.build();
|
||||
try (InputStream foo = getInputStreamFor("foo"); InputStream bar = getInputStreamFor("bar")) {
|
||||
ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create();
|
||||
ConfigurationMetadataRepository firstRepo = builder.withJsonResource(foo).build();
|
||||
validateFoo(firstRepo);
|
||||
ConfigurationMetadataRepository secondRepo = builder.withJsonResource(bar)
|
||||
.build();
|
||||
ConfigurationMetadataRepository secondRepo = builder.withJsonResource(bar).build();
|
||||
validateFoo(secondRepo);
|
||||
validateBar(secondRepo);
|
||||
// first repo not impacted by second build
|
||||
@@ -178,78 +153,63 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
|
||||
|
||||
private void validateFoo(ConfigurationMetadataRepository repo) {
|
||||
ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo");
|
||||
contains(group.getSources(), "org.acme.Foo",
|
||||
"org.springframework.boot.FooProperties");
|
||||
contains(group.getSources(), "org.acme.Foo", "org.springframework.boot.FooProperties");
|
||||
ConfigurationMetadataSource source = group.getSources().get("org.acme.Foo");
|
||||
contains(source.getProperties(), "spring.foo.name", "spring.foo.description");
|
||||
assertThat(source.getProperties()).hasSize(2);
|
||||
ConfigurationMetadataSource source2 = group.getSources()
|
||||
.get("org.springframework.boot.FooProperties");
|
||||
ConfigurationMetadataSource source2 = group.getSources().get("org.springframework.boot.FooProperties");
|
||||
contains(source2.getProperties(), "spring.foo.name", "spring.foo.counter");
|
||||
assertThat(source2.getProperties()).hasSize(2);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.foo.name"), 0, 0);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.foo.description"), 0,
|
||||
0);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.foo.description"), 0, 0);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.foo.counter"), 1, 1);
|
||||
}
|
||||
|
||||
private void validateBar(ConfigurationMetadataRepository repo) {
|
||||
ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.bar");
|
||||
contains(group.getSources(), "org.acme.Bar",
|
||||
"org.springframework.boot.BarProperties");
|
||||
contains(group.getSources(), "org.acme.Bar", "org.springframework.boot.BarProperties");
|
||||
ConfigurationMetadataSource source = group.getSources().get("org.acme.Bar");
|
||||
contains(source.getProperties(), "spring.bar.name", "spring.bar.description");
|
||||
assertThat(source.getProperties()).hasSize(2);
|
||||
ConfigurationMetadataSource source2 = group.getSources()
|
||||
.get("org.springframework.boot.BarProperties");
|
||||
ConfigurationMetadataSource source2 = group.getSources().get("org.springframework.boot.BarProperties");
|
||||
contains(source2.getProperties(), "spring.bar.name", "spring.bar.counter");
|
||||
assertThat(source2.getProperties()).hasSize(2);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.bar.name"), 0, 0);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.bar.description"), 2,
|
||||
2);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.bar.description"), 2, 2);
|
||||
validatePropertyHints(repo.getAllProperties().get("spring.bar.counter"), 0, 0);
|
||||
}
|
||||
|
||||
private void validateMap(ConfigurationMetadataRepository repo) {
|
||||
ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.map");
|
||||
ConfigurationMetadataSource source = group.getSources().get("org.acme.Map");
|
||||
contains(source.getProperties(), "spring.map.first", "spring.map.second",
|
||||
"spring.map.keys", "spring.map.values");
|
||||
contains(source.getProperties(), "spring.map.first", "spring.map.second", "spring.map.keys",
|
||||
"spring.map.values");
|
||||
assertThat(source.getProperties()).hasSize(4);
|
||||
ConfigurationMetadataProperty first = repo.getAllProperties()
|
||||
.get("spring.map.first");
|
||||
ConfigurationMetadataProperty first = repo.getAllProperties().get("spring.map.first");
|
||||
assertThat(first.getHints().getKeyHints()).hasSize(2);
|
||||
assertThat(first.getHints().getValueProviders()).hasSize(0);
|
||||
assertThat(first.getHints().getKeyHints().get(0).getValue()).isEqualTo("one");
|
||||
assertThat(first.getHints().getKeyHints().get(0).getDescription())
|
||||
.isEqualTo("First.");
|
||||
assertThat(first.getHints().getKeyHints().get(0).getDescription()).isEqualTo("First.");
|
||||
assertThat(first.getHints().getKeyHints().get(1).getValue()).isEqualTo("two");
|
||||
assertThat(first.getHints().getKeyHints().get(1).getDescription())
|
||||
.isEqualTo("Second.");
|
||||
ConfigurationMetadataProperty second = repo.getAllProperties()
|
||||
.get("spring.map.second");
|
||||
assertThat(first.getHints().getKeyHints().get(1).getDescription()).isEqualTo("Second.");
|
||||
ConfigurationMetadataProperty second = repo.getAllProperties().get("spring.map.second");
|
||||
assertThat(second.getHints().getValueHints()).hasSize(2);
|
||||
assertThat(second.getHints().getValueProviders()).hasSize(0);
|
||||
assertThat(second.getHints().getValueHints().get(0).getValue()).isEqualTo("42");
|
||||
assertThat(second.getHints().getValueHints().get(0).getDescription())
|
||||
.isEqualTo("Choose me.");
|
||||
assertThat(second.getHints().getValueHints().get(0).getDescription()).isEqualTo("Choose me.");
|
||||
assertThat(second.getHints().getValueHints().get(1).getValue()).isEqualTo("24");
|
||||
assertThat(second.getHints().getValueHints().get(1).getDescription()).isNull();
|
||||
ConfigurationMetadataProperty keys = repo.getAllProperties()
|
||||
.get("spring.map.keys");
|
||||
ConfigurationMetadataProperty keys = repo.getAllProperties().get("spring.map.keys");
|
||||
assertThat(keys.getHints().getValueHints()).hasSize(0);
|
||||
assertThat(keys.getHints().getValueProviders()).hasSize(1);
|
||||
assertThat(keys.getHints().getValueProviders().get(0).getName()).isEqualTo("any");
|
||||
ConfigurationMetadataProperty values = repo.getAllProperties()
|
||||
.get("spring.map.values");
|
||||
ConfigurationMetadataProperty values = repo.getAllProperties().get("spring.map.values");
|
||||
assertThat(values.getHints().getValueHints()).hasSize(0);
|
||||
assertThat(values.getHints().getValueProviders()).hasSize(1);
|
||||
assertThat(values.getHints().getValueProviders().get(0).getName())
|
||||
.isEqualTo("handle-as");
|
||||
assertThat(values.getHints().getValueProviders().get(0).getParameters())
|
||||
.hasSize(1);
|
||||
assertThat(values.getHints().getValueProviders().get(0).getParameters()
|
||||
.get("target")).isEqualTo("java.lang.Integer");
|
||||
assertThat(values.getHints().getValueProviders().get(0).getName()).isEqualTo("handle-as");
|
||||
assertThat(values.getHints().getValueProviders().get(0).getParameters()).hasSize(1);
|
||||
assertThat(values.getHints().getValueProviders().get(0).getParameters().get("target"))
|
||||
.isEqualTo("java.lang.Integer");
|
||||
}
|
||||
|
||||
private void validateEmptyGroup(ConfigurationMetadataRepository repo) {
|
||||
@@ -265,11 +225,9 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
|
||||
validatePropertyHints(repo.getAllProperties().get("title"), 0, 0);
|
||||
}
|
||||
|
||||
private void validatePropertyHints(ConfigurationMetadataProperty property,
|
||||
int valueHints, int valueProviders) {
|
||||
private void validatePropertyHints(ConfigurationMetadataProperty property, int valueHints, int valueProviders) {
|
||||
assertThat(property.getHints().getValueHints().size()).isEqualTo(valueHints);
|
||||
assertThat(property.getHints().getValueProviders().size())
|
||||
.isEqualTo(valueProviders);
|
||||
assertThat(property.getHints().getValueProviders().size()).isEqualTo(valueProviders);
|
||||
}
|
||||
|
||||
private void contains(Map<String, ?> source, String... keys) {
|
||||
|
||||
@@ -47,8 +47,7 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
|
||||
|
||||
@Test
|
||||
public void invalidMetadata() throws IOException {
|
||||
assertThatIllegalStateException().isThrownBy(() -> readFor("invalid"))
|
||||
.withCauseInstanceOf(JSONException.class);
|
||||
assertThatIllegalStateException().isThrownBy(() -> readFor("invalid")).withCauseInstanceOf(JSONException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,8 +82,7 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
|
||||
assertProperty(item, "spring.foo.name", "name", String.class, null);
|
||||
assertItem(item, "org.acme.Foo");
|
||||
ConfigurationMetadataItem item2 = items.get(1);
|
||||
assertProperty(item2, "spring.foo.description", "description", String.class,
|
||||
"FooBar");
|
||||
assertProperty(item2, "spring.foo.description", "description", String.class, "FooBar");
|
||||
assertThat(item2.getDescription()).isEqualTo("Foo description.");
|
||||
assertThat(item2.getShortDescription()).isEqualTo("Foo description.");
|
||||
assertThat(item2.getSourceMethod()).isNull();
|
||||
@@ -95,16 +93,14 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
|
||||
assertThat(hint.getValueHints()).hasSize(1);
|
||||
ValueHint valueHint = hint.getValueHints().get(0);
|
||||
assertThat(valueHint.getValue()).isEqualTo(42);
|
||||
assertThat(valueHint.getDescription()).isEqualTo(
|
||||
"Because that's the answer to any question, choose it. \nReally.");
|
||||
assertThat(valueHint.getShortDescription())
|
||||
.isEqualTo("Because that's the answer to any question, choose it.");
|
||||
assertThat(valueHint.getDescription())
|
||||
.isEqualTo("Because that's the answer to any question, choose it. \nReally.");
|
||||
assertThat(valueHint.getShortDescription()).isEqualTo("Because that's the answer to any question, choose it.");
|
||||
assertThat(hint.getValueProviders()).hasSize(1);
|
||||
ValueProvider valueProvider = hint.getValueProviders().get(0);
|
||||
assertThat(valueProvider.getName()).isEqualTo("handle-as");
|
||||
assertThat(valueProvider.getParameters()).hasSize(1);
|
||||
assertThat(valueProvider.getParameters().get("target"))
|
||||
.isEqualTo(Integer.class.getName());
|
||||
assertThat(valueProvider.getParameters().get("target")).isEqualTo(Integer.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,8 +123,7 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
|
||||
ValueProvider valueProvider = hint.getValueProviders().get(0);
|
||||
assertThat(valueProvider.getName()).isEqualTo("handle-as");
|
||||
assertThat(valueProvider.getParameters()).hasSize(1);
|
||||
assertThat(valueProvider.getParameters().get("target"))
|
||||
.isEqualTo(String.class.getName());
|
||||
assertThat(valueProvider.getParameters().get("target")).isEqualTo(String.class.getName());
|
||||
ValueProvider valueProvider2 = hint.getValueProviders().get(1);
|
||||
assertThat(valueProvider2.getName()).isEqualTo("any");
|
||||
assertThat(valueProvider2.getParameters()).isEmpty();
|
||||
@@ -154,17 +149,13 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
|
||||
ConfigurationMetadataItem item = items.get(0);
|
||||
assertProperty(item, "server.port", "server.port", Integer.class, null);
|
||||
assertThat(item.isDeprecated()).isTrue();
|
||||
assertThat(item.getDeprecation().getReason())
|
||||
.isEqualTo("Server namespace has moved to spring.server");
|
||||
assertThat(item.getDeprecation().getShortReason())
|
||||
.isEqualTo("Server namespace has moved to spring.server");
|
||||
assertThat(item.getDeprecation().getReplacement())
|
||||
.isEqualTo("server.spring.port");
|
||||
assertThat(item.getDeprecation().getReason()).isEqualTo("Server namespace has moved to spring.server");
|
||||
assertThat(item.getDeprecation().getShortReason()).isEqualTo("Server namespace has moved to spring.server");
|
||||
assertThat(item.getDeprecation().getReplacement()).isEqualTo("server.spring.port");
|
||||
assertThat(item.getDeprecation().getLevel()).isEqualTo(Deprecation.Level.WARNING);
|
||||
|
||||
ConfigurationMetadataItem item2 = items.get(1);
|
||||
assertProperty(item2, "server.cluster-name", "server.cluster-name", String.class,
|
||||
null);
|
||||
assertProperty(item2, "server.cluster-name", "server.cluster-name", String.class, null);
|
||||
assertThat(item2.isDeprecated()).isTrue();
|
||||
assertThat(item2.getDeprecation().getReason()).isNull();
|
||||
assertThat(item2.getDeprecation().getShortReason()).isNull();
|
||||
@@ -172,31 +163,25 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
|
||||
assertThat(item.getDeprecation().getLevel()).isEqualTo(Deprecation.Level.WARNING);
|
||||
|
||||
ConfigurationMetadataItem item3 = items.get(2);
|
||||
assertProperty(item3, "spring.server.name", "spring.server.name", String.class,
|
||||
null);
|
||||
assertProperty(item3, "spring.server.name", "spring.server.name", String.class, null);
|
||||
assertThat(item3.isDeprecated()).isFalse();
|
||||
assertThat(item3.getDeprecation()).isNull();
|
||||
|
||||
ConfigurationMetadataItem item4 = items.get(3);
|
||||
assertProperty(item4, "spring.server-name", "spring.server-name", String.class,
|
||||
null);
|
||||
assertProperty(item4, "spring.server-name", "spring.server-name", String.class, null);
|
||||
assertThat(item4.isDeprecated()).isTrue();
|
||||
assertThat(item4.getDeprecation().getReason()).isNull();
|
||||
assertThat(item2.getDeprecation().getShortReason()).isNull();
|
||||
assertThat(item4.getDeprecation().getReplacement())
|
||||
.isEqualTo("spring.server.name");
|
||||
assertThat(item4.getDeprecation().getReplacement()).isEqualTo("spring.server.name");
|
||||
assertThat(item4.getDeprecation().getLevel()).isEqualTo(Deprecation.Level.ERROR);
|
||||
|
||||
ConfigurationMetadataItem item5 = items.get(4);
|
||||
assertProperty(item5, "spring.server-name2", "spring.server-name2", String.class,
|
||||
null);
|
||||
assertProperty(item5, "spring.server-name2", "spring.server-name2", String.class, null);
|
||||
assertThat(item5.isDeprecated()).isTrue();
|
||||
assertThat(item5.getDeprecation().getReason()).isNull();
|
||||
assertThat(item2.getDeprecation().getShortReason()).isNull();
|
||||
assertThat(item5.getDeprecation().getReplacement())
|
||||
.isEqualTo("spring.server.name");
|
||||
assertThat(item5.getDeprecation().getLevel())
|
||||
.isEqualTo(Deprecation.Level.WARNING);
|
||||
assertThat(item5.getDeprecation().getReplacement()).isEqualTo("spring.server.name");
|
||||
assertThat(item5.getDeprecation().getLevel()).isEqualTo(Deprecation.Level.WARNING);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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.
|
||||
@@ -33,22 +33,21 @@ public class SentenceExtractorTests {
|
||||
|
||||
@Test
|
||||
public void extractFirstSentence() {
|
||||
String sentence = this.extractor
|
||||
.getFirstSentence("My short " + "description. More stuff.");
|
||||
String sentence = this.extractor.getFirstSentence("My short " + "description. More stuff.");
|
||||
assertThat(sentence).isEqualTo("My short description.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractFirstSentenceNewLineBeforeDot() {
|
||||
String sentence = this.extractor.getFirstSentence(
|
||||
"My short" + NEW_LINE + "description." + NEW_LINE + "More stuff.");
|
||||
String sentence = this.extractor
|
||||
.getFirstSentence("My short" + NEW_LINE + "description." + NEW_LINE + "More stuff.");
|
||||
assertThat(sentence).isEqualTo("My short description.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractFirstSentenceNewLineBeforeDotWithSpaces() {
|
||||
String sentence = this.extractor.getFirstSentence(
|
||||
"My short " + NEW_LINE + " description. " + NEW_LINE + "More stuff.");
|
||||
String sentence = this.extractor
|
||||
.getFirstSentence("My short " + NEW_LINE + " description. " + NEW_LINE + "More stuff.");
|
||||
assertThat(sentence).isEqualTo("My short description.");
|
||||
}
|
||||
|
||||
@@ -60,8 +59,7 @@ public class SentenceExtractorTests {
|
||||
|
||||
@Test
|
||||
public void extractFirstSentenceNoDotMultipleLines() {
|
||||
String sentence = this.extractor
|
||||
.getFirstSentence("My short description " + NEW_LINE + " More stuff");
|
||||
String sentence = this.extractor.getFirstSentence("My short description " + NEW_LINE + " More stuff");
|
||||
assertThat(sentence).isEqualTo("My short description");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user