Fix configuration property name when group is empty

See gh-5335
pull/5489/head
Eric Bottard 9 years ago committed by Stephane Nicoll
parent 497790571f
commit 79cd01eb7a

@ -77,10 +77,10 @@ class RawConfigurationMetadata {
}
ConfigurationMetadataSource source = getSource(item.getSourceType());
if (source != null) {
String groupId = source.getGroupId();
String dottedPrefix = source.getGroupId() + ".";
String id = item.getId();
if (id.startsWith(groupId)) { // match
String name = id.substring(groupId.length() + 1, id.length()); // "."
if (id.startsWith(dottedPrefix)) {
String name = id.substring(dottedPrefix.length(), id.length());
item.setName(name);
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 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.
@ -52,6 +52,17 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
readFor("invalid");
}
@Test
public void emptyGroupName() throws IOException {
RawConfigurationMetadata rawMetadata = readFor("emptygroup");
List<ConfigurationMetadataItem> items = rawMetadata.getItems();
assertEquals(1, items.size());
ConfigurationMetadataItem item = items.get(0);
assertProperty(item, "name", "name", String.class, null);
}
@Test
public void simpleMetadata() throws IOException {
RawConfigurationMetadata rawMetadata = readFor("foo");

@ -0,0 +1,18 @@
{
"groups": [
{
"name": "",
"type": "org.acme.Foo",
"sourceType": "org.acme.config.FooApp",
"sourceMethod": "foo()",
"description": "This is Foo."
}
],
"properties": [
{
"name": "name",
"type": "java.lang.String",
"sourceType": "org.acme.Foo"
}
]
}
Loading…
Cancel
Save