|
|
|
|
@@ -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) {
|
|
|
|
|
|