Revert spring-boot-configuration-metadata for now
See gh-1970
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.configurationmetadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class AbstractConfigurationMetadataTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
protected void assertSource(ConfigurationMetadataSource actual, String groupId, String type, String sourceType) {
|
||||
assertNotNull(actual);
|
||||
assertEquals(groupId, actual.getGroupId());
|
||||
assertEquals(type, actual.getType());
|
||||
assertEquals(sourceType, actual.getSourceType());
|
||||
}
|
||||
|
||||
protected void assertProperty(ConfigurationMetadataProperty actual, String id, String name,
|
||||
Class<?> type, Object defaultValue) {
|
||||
assertNotNull(actual);
|
||||
assertEquals(id, actual.getId());
|
||||
assertEquals(name, actual.getName());
|
||||
String typeName = type != null ? type.getName() : null;
|
||||
assertEquals(typeName, actual.getType());
|
||||
assertEquals(defaultValue, actual.getDefaultValue());
|
||||
}
|
||||
|
||||
protected void assertItem(ConfigurationMetadataItem actual, String sourceType) {
|
||||
assertNotNull(actual);
|
||||
assertEquals(sourceType, actual.getSourceType());
|
||||
}
|
||||
|
||||
protected InputStream getInputStreamFor(String name) throws IOException {
|
||||
Resource r = new ClassPathResource("metadata/configuration-metadata-" + name + ".json");
|
||||
return r.getInputStream();
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.configurationmetadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link ConfigurationMetadataRepository}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ConfigurationMetadataRepositoryJsonLoaderTests extends AbstractConfigurationMetadataTests {
|
||||
|
||||
private final ConfigurationMetadataRepositoryJsonLoader loader = new ConfigurationMetadataRepositoryJsonLoader();
|
||||
|
||||
@Test
|
||||
public void nullResource() throws IOException {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
loader.loadAll(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleRepository() throws IOException {
|
||||
ConfigurationMetadataRepository repo = loader.loadAll(Collections.singleton(getInputStreamFor("foo")));
|
||||
validateFoo(repo);
|
||||
assertEquals(1, repo.getAllGroups().size());
|
||||
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter");
|
||||
assertEquals(3, repo.getAllProperties().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void severalRepositoriesNoConflict() throws IOException {
|
||||
ConfigurationMetadataRepository repo = loader.loadAll(
|
||||
Arrays.asList(getInputStreamFor("foo"), getInputStreamFor("bar")));
|
||||
validateFoo(repo);
|
||||
validateBar(repo);
|
||||
assertEquals(2, repo.getAllGroups().size());
|
||||
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter",
|
||||
"spring.bar.name", "spring.bar.description", "spring.bar.counter");
|
||||
assertEquals(6, repo.getAllProperties().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repositoryWithRoot() throws IOException {
|
||||
ConfigurationMetadataRepository repo = loader.loadAll(
|
||||
Arrays.asList(getInputStreamFor("foo"), getInputStreamFor("root")));
|
||||
validateFoo(repo);
|
||||
assertEquals(2, repo.getAllGroups().size());
|
||||
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter",
|
||||
"spring.root.name", "spring.root2.name");
|
||||
assertEquals(5, repo.getAllProperties().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void severalRepositoriesIdenticalGroups() throws IOException {
|
||||
ConfigurationMetadataRepository repo = loader.loadAll(
|
||||
Arrays.asList(getInputStreamFor("foo"), getInputStreamFor("foo2")));
|
||||
assertEquals(1, repo.getAllGroups().size());
|
||||
ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo");
|
||||
contains(group.getSources(), "org.acme.Foo", "org.acme.Foo2", "org.springframework.boot.FooProperties");
|
||||
assertEquals(3, group.getSources().size());
|
||||
contains(group.getProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter",
|
||||
"spring.foo.enabled", "spring.foo.type");
|
||||
assertEquals(5, group.getProperties().size());
|
||||
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", "spring.foo.counter",
|
||||
"spring.foo.enabled", "spring.foo.type");
|
||||
assertEquals(5, repo.getAllProperties().size());
|
||||
}
|
||||
|
||||
private void validateFoo(ConfigurationMetadataRepository repo) {
|
||||
ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo");
|
||||
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");
|
||||
assertEquals(2, source.getProperties().size());
|
||||
ConfigurationMetadataSource source2 = group.getSources().get("org.springframework.boot.FooProperties");
|
||||
contains(source2.getProperties(), "spring.foo.name", "spring.foo.counter");
|
||||
assertEquals(2, source2.getProperties().size());
|
||||
}
|
||||
|
||||
private void validateBar(ConfigurationMetadataRepository repo) {
|
||||
ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.bar");
|
||||
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");
|
||||
assertEquals(2, source.getProperties().size());
|
||||
ConfigurationMetadataSource source2 = group.getSources().get("org.springframework.boot.BarProperties");
|
||||
contains(source2.getProperties(), "spring.bar.name", "spring.bar.counter");
|
||||
assertEquals(2, source2.getProperties().size());
|
||||
}
|
||||
|
||||
private void contains(Map<String, ?> source, String... keys) {
|
||||
for (String key : keys) {
|
||||
assertTrue("Item '" + key + "' not found. Got " + source.keySet(), source.containsKey(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.configurationmetadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Tests for {@link JsonReader}
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JsonReaderTests extends AbstractConfigurationMetadataTests {
|
||||
|
||||
private final JsonReader reader = new JsonReader();
|
||||
|
||||
@Test
|
||||
public void emptyMetadata() throws IOException {
|
||||
RawConfigurationMetadata rawMetadata = reader.read(getInputStreamFor("empty"));
|
||||
assertEquals(0, rawMetadata.getSources().size());
|
||||
assertEquals(0, rawMetadata.getItems().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidMetadata() throws IOException {
|
||||
thrown.expect(JSONException.class);
|
||||
reader.read(getInputStreamFor("invalid"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleMetadata() throws IOException {
|
||||
RawConfigurationMetadata rawMetadata = reader.read(getInputStreamFor("foo"));
|
||||
List<ConfigurationMetadataSource> sources = rawMetadata.getSources();
|
||||
assertEquals(2, sources.size());
|
||||
List<ConfigurationMetadataItem> items = rawMetadata.getItems();
|
||||
assertEquals(4, items.size());
|
||||
|
||||
|
||||
ConfigurationMetadataSource source = sources.get(0);
|
||||
assertSource(source, "spring.foo", "org.acme.Foo", "org.acme.config.FooApp");
|
||||
assertEquals("foo()", source.getSourceMethod());
|
||||
assertEquals("This is Foo.", source.getDescription());
|
||||
ConfigurationMetadataItem item = items.get(0);
|
||||
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");
|
||||
assertEquals("Foo description.", item2.getDescription());
|
||||
assertNull(item2.getSourceMethod());
|
||||
assertItem(item2, "org.acme.Foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootMetadata() throws IOException {
|
||||
RawConfigurationMetadata rawMetadata = reader.read(getInputStreamFor("root"));
|
||||
List<ConfigurationMetadataSource> sources = rawMetadata.getSources();
|
||||
assertEquals(0, sources.size());
|
||||
List<ConfigurationMetadataItem> items = rawMetadata.getItems();
|
||||
assertEquals(2, items.size());
|
||||
|
||||
ConfigurationMetadataItem item = items.get(0);
|
||||
assertProperty(item, "spring.root.name", "spring.root.name", String.class, null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
{
|
||||
"groups": [
|
||||
{
|
||||
"name": "spring.bar",
|
||||
"type": "org.acme.Bar",
|
||||
"sourceType": "org.acme.config.BarApp",
|
||||
"sourceMethod": "bar()",
|
||||
"description": "This is Bar."
|
||||
},
|
||||
{
|
||||
"name": "spring.bar",
|
||||
"type": "org.springframework.boot.BarProperties"
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "spring.bar.name",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Bar"
|
||||
},
|
||||
{
|
||||
"name": "spring.bar.description",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Bar",
|
||||
"description": "Bar description.",
|
||||
"defaultValue": "BarFoo"
|
||||
},
|
||||
{
|
||||
"name": "spring.bar.name",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.springframework.boot.BarProperties"
|
||||
},
|
||||
{
|
||||
"name": "spring.bar.counter",
|
||||
"type": "java.lang.Integer",
|
||||
"sourceType": "org.springframework.boot.BarProperties",
|
||||
"defaultValue": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"foo": "bar"
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
{
|
||||
"groups": [
|
||||
{
|
||||
"name": "spring.foo",
|
||||
"type": "org.acme.Foo",
|
||||
"sourceType": "org.acme.config.FooApp",
|
||||
"sourceMethod": "foo()",
|
||||
"description": "This is Foo."
|
||||
},
|
||||
{
|
||||
"name": "spring.foo",
|
||||
"type": "org.springframework.boot.FooProperties"
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "spring.foo.name",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Foo"
|
||||
},
|
||||
{
|
||||
"name": "spring.foo.description",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Foo",
|
||||
"description": "Foo description.",
|
||||
"defaultValue": "FooBar"
|
||||
},
|
||||
{
|
||||
"name": "spring.foo.name",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.springframework.boot.FooProperties"
|
||||
},
|
||||
{
|
||||
"name": "spring.foo.counter",
|
||||
"type": "java.lang.Integer",
|
||||
"sourceType": "org.springframework.boot.FooProperties",
|
||||
"defaultValue": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"groups": [
|
||||
{
|
||||
"name": "spring.foo",
|
||||
"type": "org.acme.Foo2",
|
||||
"sourceType": "org.acme.config.FooApp",
|
||||
"sourceMethod": "foo2()",
|
||||
"description": "This is Foo2."
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
{
|
||||
"name": "spring.foo.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"sourceType": "org.acme.Foo2"
|
||||
},
|
||||
{
|
||||
"name": "spring.foo.type",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Foo2"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "org.acme.Invalid"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"name": "spring.root.name",
|
||||
"type": "java.lang.String"
|
||||
},
|
||||
{
|
||||
"name": "spring.root2.name"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user