Polish
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://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.boot.configurationdocs;
|
||||
|
||||
/**
|
||||
* Simple builder to help construct Asciidoc markup.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class AsciidocBuilder {
|
||||
|
||||
private static final String NEWLINE = System.lineSeparator();
|
||||
|
||||
private final StringBuilder content;
|
||||
|
||||
AsciidocBuilder() {
|
||||
this.content = new StringBuilder();
|
||||
}
|
||||
|
||||
public AsciidocBuilder appendln(Object... items) {
|
||||
append(items);
|
||||
append(NEWLINE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AsciidocBuilder append(Object... items) {
|
||||
for (Object item : items) {
|
||||
this.content.append(item);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.content.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,29 +27,30 @@ import org.springframework.boot.configurationmetadata.ConfigurationMetadataPrope
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
class CompoundKeyEntry extends AbstractConfigurationEntry {
|
||||
class CompoundConfigurationTableEntry extends ConfigurationTableEntry {
|
||||
|
||||
private Set<String> configurationKeys;
|
||||
|
||||
private String description;
|
||||
|
||||
CompoundKeyEntry(String key, String description) {
|
||||
CompoundConfigurationTableEntry(String key, String description) {
|
||||
this.key = key;
|
||||
this.description = description;
|
||||
this.configurationKeys = new TreeSet<>();
|
||||
}
|
||||
|
||||
void addConfigurationKeys(ConfigurationMetadataProperty... properties) {
|
||||
Stream.of(properties)
|
||||
.forEach((property) -> this.configurationKeys.add(property.getId()));
|
||||
Stream.of(properties).map(ConfigurationMetadataProperty::getId)
|
||||
.forEach(this.configurationKeys::add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAsciidoc(StringBuilder builder) {
|
||||
public void write(AsciidocBuilder builder) {
|
||||
builder.append("|`+++");
|
||||
this.configurationKeys.forEach((key) -> builder.append(key).append(NEWLINE));
|
||||
builder.append("+++`").append(NEWLINE).append("|").append(NEWLINE).append("|+++")
|
||||
.append(this.description).append("+++").append(NEWLINE);
|
||||
this.configurationKeys.forEach(builder::appendln);
|
||||
builder.appendln("+++`");
|
||||
builder.appendln("|");
|
||||
builder.appendln("|+++", this.description, "+++");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,6 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
|
||||
import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepository;
|
||||
import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepositoryJsonBuilder;
|
||||
|
||||
/**
|
||||
@@ -39,8 +38,21 @@ import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepos
|
||||
*/
|
||||
public class ConfigurationMetadataDocumentWriter {
|
||||
|
||||
public void writeDocument(Path outputDirPath, DocumentOptions options,
|
||||
InputStream... metadataInput) throws IOException {
|
||||
public void writeDocument(Path outputDirectory, DocumentOptions options,
|
||||
InputStream... metadata) throws IOException {
|
||||
assertValidOutputDirectory(outputDirectory);
|
||||
if (!Files.exists(outputDirectory)) {
|
||||
Files.createDirectory(outputDirectory);
|
||||
}
|
||||
assertMetadata(metadata);
|
||||
List<ConfigurationTable> tables = createConfigTables(
|
||||
getMetadataProperties(metadata), options);
|
||||
for (ConfigurationTable table : tables) {
|
||||
writeConfigurationTable(table, outputDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertValidOutputDirectory(Path outputDirPath) {
|
||||
if (outputDirPath == null) {
|
||||
throw new IllegalArgumentException("output path should not be null");
|
||||
}
|
||||
@@ -48,64 +60,33 @@ public class ConfigurationMetadataDocumentWriter {
|
||||
throw new IllegalArgumentException(
|
||||
"output path already exists and is not a directory");
|
||||
}
|
||||
else if (!Files.exists(outputDirPath)) {
|
||||
Files.createDirectory(outputDirPath);
|
||||
}
|
||||
if (metadataInput == null || metadataInput.length < 1) {
|
||||
}
|
||||
|
||||
private void assertMetadata(InputStream... metadata) {
|
||||
if (metadata == null || metadata.length < 1) {
|
||||
throw new IllegalArgumentException("missing input metadata");
|
||||
}
|
||||
|
||||
ConfigurationMetadataRepository configRepository = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(metadataInput).build();
|
||||
Map<String, ConfigurationMetadataProperty> allProperties = configRepository
|
||||
.getAllProperties();
|
||||
|
||||
List<ConfigurationTable> tables = createConfigTables(allProperties, options);
|
||||
|
||||
for (ConfigurationTable table : tables) {
|
||||
Path outputFilePath = outputDirPath.resolve(table.getId() + ".adoc");
|
||||
Files.deleteIfExists(outputFilePath);
|
||||
Files.createFile(outputFilePath);
|
||||
try (OutputStream outputStream = Files.newOutputStream(outputFilePath)) {
|
||||
outputStream
|
||||
.write(table.toAsciidocTable().getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, ConfigurationMetadataProperty> getMetadataProperties(
|
||||
InputStream... metadata) throws IOException {
|
||||
ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder
|
||||
.create(metadata);
|
||||
return builder.build().getAllProperties();
|
||||
}
|
||||
|
||||
private List<ConfigurationTable> createConfigTables(
|
||||
Map<String, ConfigurationMetadataProperty> allProperties,
|
||||
Map<String, ConfigurationMetadataProperty> metadataProperties,
|
||||
DocumentOptions options) {
|
||||
|
||||
final List<ConfigurationTable> tables = new ArrayList<>();
|
||||
final List<String> unmappedKeys = allProperties.values().stream()
|
||||
.filter((prop) -> !prop.isDeprecated()).map((prop) -> prop.getId())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final Map<String, CompoundKeyEntry> overrides = getOverrides(allProperties,
|
||||
unmappedKeys, options);
|
||||
|
||||
options.getMetadataSections().forEach((id, keyPrefixes) -> {
|
||||
ConfigurationTable table = new ConfigurationTable(id);
|
||||
tables.add(table);
|
||||
for (String keyPrefix : keyPrefixes) {
|
||||
List<String> matchingOverrides = overrides.keySet().stream()
|
||||
.filter((overrideKey) -> overrideKey.startsWith(keyPrefix))
|
||||
.collect(Collectors.toList());
|
||||
matchingOverrides
|
||||
.forEach((match) -> table.addEntry(overrides.remove(match)));
|
||||
}
|
||||
List<String> matchingKeys = unmappedKeys.stream()
|
||||
.filter((key) -> keyPrefixes.stream().anyMatch(key::startsWith))
|
||||
.collect(Collectors.toList());
|
||||
for (String matchingKey : matchingKeys) {
|
||||
ConfigurationMetadataProperty property = allProperties.get(matchingKey);
|
||||
table.addEntry(new SingleKeyEntry(property));
|
||||
|
||||
}
|
||||
unmappedKeys.removeAll(matchingKeys);
|
||||
});
|
||||
|
||||
List<ConfigurationTable> tables = new ArrayList<>();
|
||||
List<String> unmappedKeys = metadataProperties.values().stream()
|
||||
.filter((property) -> !property.isDeprecated())
|
||||
.map(ConfigurationMetadataProperty::getId).collect(Collectors.toList());
|
||||
Map<String, CompoundConfigurationTableEntry> overrides = getOverrides(
|
||||
metadataProperties, unmappedKeys, options);
|
||||
options.getMetadataSections().forEach(
|
||||
(id, keyPrefixes) -> tables.add(createConfigTable(metadataProperties,
|
||||
unmappedKeys, overrides, id, keyPrefixes)));
|
||||
if (!unmappedKeys.isEmpty()) {
|
||||
throw new IllegalStateException(
|
||||
"The following keys were not written to the documentation: "
|
||||
@@ -116,22 +97,21 @@ public class ConfigurationMetadataDocumentWriter {
|
||||
"The following keys were not written to the documentation: "
|
||||
+ String.join(", ", overrides.keySet()));
|
||||
}
|
||||
|
||||
return tables;
|
||||
}
|
||||
|
||||
private Map<String, CompoundKeyEntry> getOverrides(
|
||||
Map<String, ConfigurationMetadataProperty> allProperties,
|
||||
private Map<String, CompoundConfigurationTableEntry> getOverrides(
|
||||
Map<String, ConfigurationMetadataProperty> metadataProperties,
|
||||
List<String> unmappedKeys, DocumentOptions options) {
|
||||
final Map<String, CompoundKeyEntry> overrides = new HashMap<>();
|
||||
|
||||
Map<String, CompoundConfigurationTableEntry> overrides = new HashMap<>();
|
||||
options.getOverrides().forEach((keyPrefix, description) -> {
|
||||
final CompoundKeyEntry entry = new CompoundKeyEntry(keyPrefix, description);
|
||||
CompoundConfigurationTableEntry entry = new CompoundConfigurationTableEntry(
|
||||
keyPrefix, description);
|
||||
List<String> matchingKeys = unmappedKeys.stream()
|
||||
.filter((key) -> key.startsWith(keyPrefix))
|
||||
.collect(Collectors.toList());
|
||||
for (String matchingKey : matchingKeys) {
|
||||
entry.addConfigurationKeys(allProperties.get(matchingKey));
|
||||
entry.addConfigurationKeys(metadataProperties.get(matchingKey));
|
||||
}
|
||||
overrides.put(keyPrefix, entry);
|
||||
unmappedKeys.removeAll(matchingKeys);
|
||||
@@ -139,4 +119,37 @@ public class ConfigurationMetadataDocumentWriter {
|
||||
return overrides;
|
||||
}
|
||||
|
||||
private ConfigurationTable createConfigTable(
|
||||
Map<String, ConfigurationMetadataProperty> metadataProperties,
|
||||
List<String> unmappedKeys,
|
||||
Map<String, CompoundConfigurationTableEntry> overrides, String id,
|
||||
List<String> keyPrefixes) {
|
||||
ConfigurationTable table = new ConfigurationTable(id);
|
||||
for (String keyPrefix : keyPrefixes) {
|
||||
List<String> matchingOverrides = overrides.keySet().stream()
|
||||
.filter((overrideKey) -> overrideKey.startsWith(keyPrefix))
|
||||
.collect(Collectors.toList());
|
||||
matchingOverrides.forEach((match) -> table.addEntry(overrides.remove(match)));
|
||||
}
|
||||
List<String> matchingKeys = unmappedKeys.stream()
|
||||
.filter((key) -> keyPrefixes.stream().anyMatch(key::startsWith))
|
||||
.collect(Collectors.toList());
|
||||
for (String matchingKey : matchingKeys) {
|
||||
ConfigurationMetadataProperty property = metadataProperties.get(matchingKey);
|
||||
table.addEntry(new SingleConfigurationTableEntry(property));
|
||||
}
|
||||
unmappedKeys.removeAll(matchingKeys);
|
||||
return table;
|
||||
}
|
||||
|
||||
private void writeConfigurationTable(ConfigurationTable table, Path outputDirectory)
|
||||
throws IOException {
|
||||
Path outputFilePath = outputDirectory.resolve(table.getId() + ".adoc");
|
||||
Files.deleteIfExists(outputFilePath);
|
||||
Files.createFile(outputFilePath);
|
||||
try (OutputStream outputStream = Files.newOutputStream(outputFilePath)) {
|
||||
outputStream.write(table.toAsciidocTable().getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,11 +27,9 @@ import java.util.TreeSet;
|
||||
*/
|
||||
class ConfigurationTable {
|
||||
|
||||
private static final String NEWLINE = System.lineSeparator();
|
||||
|
||||
private final String id;
|
||||
|
||||
private final Set<AbstractConfigurationEntry> entries;
|
||||
private final Set<ConfigurationTableEntry> entries;
|
||||
|
||||
ConfigurationTable(String id) {
|
||||
this.id = id;
|
||||
@@ -42,20 +40,21 @@ class ConfigurationTable {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
void addEntry(AbstractConfigurationEntry... entries) {
|
||||
void addEntry(ConfigurationTableEntry... entries) {
|
||||
this.entries.addAll(Arrays.asList(entries));
|
||||
}
|
||||
|
||||
String toAsciidocTable() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append("[cols=\"1,1,2\", options=\"header\"]").append(NEWLINE);
|
||||
builder.append("|===").append(NEWLINE).append("|Key|Default Value|Description")
|
||||
.append(NEWLINE).append(NEWLINE);
|
||||
AsciidocBuilder builder = new AsciidocBuilder();
|
||||
builder.appendln("[cols=\"1,1,2\", options=\"header\"]");
|
||||
builder.appendln("|===");
|
||||
builder.appendln("|Key|Default Value|Description");
|
||||
builder.appendln();
|
||||
this.entries.forEach((entry) -> {
|
||||
entry.writeAsciidoc(builder);
|
||||
builder.append(NEWLINE);
|
||||
entry.write(builder);
|
||||
builder.appendln();
|
||||
});
|
||||
return builder.append("|===").append(NEWLINE).toString();
|
||||
return builder.appendln("|===").toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,17 +16,12 @@
|
||||
|
||||
package org.springframework.boot.configurationdocs;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Abstract class for entries in {@link ConfigurationTable}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
abstract class AbstractConfigurationEntry
|
||||
implements Comparable<AbstractConfigurationEntry> {
|
||||
|
||||
protected static final String NEWLINE = System.lineSeparator();
|
||||
abstract class ConfigurationTableEntry implements Comparable<ConfigurationTableEntry> {
|
||||
|
||||
protected String key;
|
||||
|
||||
@@ -34,27 +29,27 @@ abstract class AbstractConfigurationEntry
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public abstract void writeAsciidoc(StringBuilder builder);
|
||||
public abstract void write(AsciidocBuilder builder);
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
AbstractConfigurationEntry that = (AbstractConfigurationEntry) o;
|
||||
return this.key.equals(that.key);
|
||||
ConfigurationTableEntry other = (ConfigurationTableEntry) obj;
|
||||
return this.key.equals(other.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.key);
|
||||
return this.key.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(AbstractConfigurationEntry other) {
|
||||
public int compareTo(ConfigurationTableEntry other) {
|
||||
return this.key.compareTo(other.getKey());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://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.boot.configurationdocs;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
|
||||
|
||||
/**
|
||||
* Table entry containing a single configuration property.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
class SingleConfigurationTableEntry extends ConfigurationTableEntry {
|
||||
|
||||
private final String description;
|
||||
|
||||
private final String defaultValue;
|
||||
|
||||
SingleConfigurationTableEntry(ConfigurationMetadataProperty property) {
|
||||
this.key = property.getId();
|
||||
if (property.getType() != null
|
||||
&& property.getType().startsWith("java.util.Map")) {
|
||||
this.key += ".*";
|
||||
}
|
||||
this.description = property.getDescription();
|
||||
this.defaultValue = getDefaultValue(property.getDefaultValue());
|
||||
}
|
||||
|
||||
private String getDefaultValue(Object defaultValue) {
|
||||
if (defaultValue == null) {
|
||||
return null;
|
||||
}
|
||||
if (defaultValue.getClass().isArray()) {
|
||||
return Arrays.stream((Object[]) defaultValue).map(Object::toString)
|
||||
.collect(Collectors.joining("," + System.lineSeparator()));
|
||||
}
|
||||
return defaultValue.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(AsciidocBuilder builder) {
|
||||
builder.appendln("|`+", this.key, "+`");
|
||||
writeDefaultValue(builder);
|
||||
writeDescription(builder);
|
||||
builder.appendln();
|
||||
}
|
||||
|
||||
private void writeDefaultValue(AsciidocBuilder builder) {
|
||||
String defaultValue = (this.defaultValue != null) ? this.defaultValue : "";
|
||||
defaultValue = defaultValue.replace("\\", "\\\\").replace("|",
|
||||
"{vbar}" + System.lineSeparator());
|
||||
if (defaultValue.isEmpty()) {
|
||||
builder.appendln("|");
|
||||
}
|
||||
else {
|
||||
builder.appendln("|`+", defaultValue, "+`");
|
||||
}
|
||||
}
|
||||
|
||||
private void writeDescription(AsciidocBuilder builder) {
|
||||
if (this.description == null || this.description.isEmpty()) {
|
||||
builder.append("|");
|
||||
}
|
||||
else {
|
||||
builder.append("|+++", this.description, "+++");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://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.boot.configurationdocs;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
|
||||
|
||||
/**
|
||||
* Table entry containing a single configuration property.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
class SingleKeyEntry extends AbstractConfigurationEntry {
|
||||
|
||||
private String defaultValue;
|
||||
|
||||
private String description;
|
||||
|
||||
SingleKeyEntry(ConfigurationMetadataProperty property) {
|
||||
|
||||
this.key = property.getId();
|
||||
if (property.getType() != null
|
||||
&& property.getType().startsWith("java.util.Map")) {
|
||||
this.key += ".*";
|
||||
}
|
||||
|
||||
this.description = property.getDescription();
|
||||
|
||||
if (property.getDefaultValue() != null) {
|
||||
if (property.getDefaultValue().getClass().isArray()) {
|
||||
this.defaultValue = Arrays.stream((Object[]) property.getDefaultValue())
|
||||
.map(Object::toString).collect(Collectors.joining("," + NEWLINE));
|
||||
}
|
||||
else {
|
||||
this.defaultValue = property.getDefaultValue().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAsciidoc(StringBuilder builder) {
|
||||
builder.append("|`+").append(this.key).append("+`").append(NEWLINE);
|
||||
String defaultValue = processDefaultValue();
|
||||
if (!defaultValue.isEmpty()) {
|
||||
builder.append("|`+").append(defaultValue).append("+`").append(NEWLINE);
|
||||
}
|
||||
else {
|
||||
builder.append("|").append(NEWLINE);
|
||||
}
|
||||
if (this.description != null) {
|
||||
builder.append("|+++").append(this.description).append("+++");
|
||||
}
|
||||
else {
|
||||
builder.append("|");
|
||||
}
|
||||
builder.append(NEWLINE);
|
||||
}
|
||||
|
||||
private String processDefaultValue() {
|
||||
if (this.defaultValue != null && !this.defaultValue.isEmpty()) {
|
||||
return this.defaultValue.replace("\\", "\\\\").replace("|",
|
||||
"{vbar}" + NEWLINE);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,9 +23,11 @@ import org.springframework.boot.configurationmetadata.ConfigurationMetadataPrope
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link CompoundConfigurationTableEntry}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
public class CompoundKeyEntryTests {
|
||||
public class CompoundConfigurationTableEntryTests {
|
||||
|
||||
private static String NEWLINE = System.lineSeparator();
|
||||
|
||||
@@ -34,21 +36,17 @@ public class CompoundKeyEntryTests {
|
||||
ConfigurationMetadataProperty firstProp = new ConfigurationMetadataProperty();
|
||||
firstProp.setId("spring.test.first");
|
||||
firstProp.setType("java.lang.String");
|
||||
|
||||
ConfigurationMetadataProperty secondProp = new ConfigurationMetadataProperty();
|
||||
secondProp.setId("spring.test.second");
|
||||
secondProp.setType("java.lang.String");
|
||||
|
||||
ConfigurationMetadataProperty thirdProp = new ConfigurationMetadataProperty();
|
||||
thirdProp.setId("spring.test.third");
|
||||
thirdProp.setType("java.lang.String");
|
||||
|
||||
CompoundKeyEntry entry = new CompoundKeyEntry("spring.test",
|
||||
"This is a description.");
|
||||
CompoundConfigurationTableEntry entry = new CompoundConfigurationTableEntry(
|
||||
"spring.test", "This is a description.");
|
||||
entry.addConfigurationKeys(firstProp, secondProp, thirdProp);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
entry.writeAsciidoc(builder);
|
||||
|
||||
AsciidocBuilder builder = new AsciidocBuilder();
|
||||
entry.write(builder);
|
||||
assertThat(builder.toString()).isEqualTo("|`+++spring.test.first" + NEWLINE
|
||||
+ "spring.test.second" + NEWLINE + "spring.test.third" + NEWLINE + "+++`"
|
||||
+ NEWLINE + "|" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
|
||||
@@ -23,6 +23,8 @@ import org.springframework.boot.configurationmetadata.ConfigurationMetadataPrope
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ConfigurationTable}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
public class ConfigurationTableTests {
|
||||
@@ -32,22 +34,18 @@ public class ConfigurationTableTests {
|
||||
@Test
|
||||
public void simpleTable() {
|
||||
ConfigurationTable table = new ConfigurationTable("test");
|
||||
|
||||
ConfigurationMetadataProperty first = new ConfigurationMetadataProperty();
|
||||
first.setId("spring.test.prop");
|
||||
first.setDefaultValue("something");
|
||||
first.setDescription("This is a description.");
|
||||
first.setType("java.lang.String");
|
||||
|
||||
ConfigurationMetadataProperty second = new ConfigurationMetadataProperty();
|
||||
second.setId("spring.test.other");
|
||||
second.setDefaultValue("other value");
|
||||
second.setDescription("This is another description.");
|
||||
second.setType("java.lang.String");
|
||||
|
||||
table.addEntry(new SingleKeyEntry(first));
|
||||
table.addEntry(new SingleKeyEntry(second));
|
||||
|
||||
table.addEntry(new SingleConfigurationTableEntry(first));
|
||||
table.addEntry(new SingleConfigurationTableEntry(second));
|
||||
assertThat(table.toAsciidocTable())
|
||||
.isEqualTo("[cols=\"1,1,2\", options=\"header\"]" + NEWLINE + "|==="
|
||||
+ NEWLINE + "|Key|Default Value|Description" + NEWLINE + NEWLINE
|
||||
|
||||
@@ -23,9 +23,11 @@ import org.springframework.boot.configurationmetadata.ConfigurationMetadataPrope
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SingleConfigurationTableEntry}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
public class SingleKeyEntryTests {
|
||||
public class SingleConfigurationTableEntryTests {
|
||||
|
||||
private static String NEWLINE = System.lineSeparator();
|
||||
|
||||
@@ -36,11 +38,9 @@ public class SingleKeyEntryTests {
|
||||
property.setDefaultValue("something");
|
||||
property.setDescription("This is a description.");
|
||||
property.setType("java.lang.String");
|
||||
|
||||
SingleKeyEntry entry = new SingleKeyEntry(property);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
entry.writeAsciidoc(builder);
|
||||
|
||||
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
|
||||
AsciidocBuilder builder = new AsciidocBuilder();
|
||||
entry.write(builder);
|
||||
assertThat(builder.toString()).isEqualTo("|`+spring.test.prop+`" + NEWLINE
|
||||
+ "|`+something+`" + NEWLINE + "|+++This is a description.+++" + NEWLINE);
|
||||
}
|
||||
@@ -51,11 +51,9 @@ public class SingleKeyEntryTests {
|
||||
property.setId("spring.test.prop");
|
||||
property.setDescription("This is a description.");
|
||||
property.setType("java.lang.String");
|
||||
|
||||
SingleKeyEntry entry = new SingleKeyEntry(property);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
entry.writeAsciidoc(builder);
|
||||
|
||||
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
|
||||
AsciidocBuilder builder = new AsciidocBuilder();
|
||||
entry.write(builder);
|
||||
assertThat(builder.toString()).isEqualTo("|`+spring.test.prop+`" + NEWLINE + "|"
|
||||
+ NEWLINE + "|+++This is a description.+++" + NEWLINE);
|
||||
}
|
||||
@@ -67,11 +65,9 @@ public class SingleKeyEntryTests {
|
||||
property.setDefaultValue("first|second");
|
||||
property.setDescription("This is a description.");
|
||||
property.setType("java.lang.String");
|
||||
|
||||
SingleKeyEntry entry = new SingleKeyEntry(property);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
entry.writeAsciidoc(builder);
|
||||
|
||||
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
|
||||
AsciidocBuilder builder = new AsciidocBuilder();
|
||||
entry.write(builder);
|
||||
assertThat(builder.toString()).isEqualTo("|`+spring.test.prop+`" + NEWLINE
|
||||
+ "|`+first{vbar}" + NEWLINE + "second+`" + NEWLINE
|
||||
+ "|+++This is a description.+++" + NEWLINE);
|
||||
@@ -84,11 +80,9 @@ public class SingleKeyEntryTests {
|
||||
property.setDefaultValue("first\\second");
|
||||
property.setDescription("This is a description.");
|
||||
property.setType("java.lang.String");
|
||||
|
||||
SingleKeyEntry entry = new SingleKeyEntry(property);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
entry.writeAsciidoc(builder);
|
||||
|
||||
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
|
||||
AsciidocBuilder builder = new AsciidocBuilder();
|
||||
entry.write(builder);
|
||||
assertThat(builder.toString())
|
||||
.isEqualTo("|`+spring.test.prop+`" + NEWLINE + "|`+first\\\\second+`"
|
||||
+ NEWLINE + "|+++This is a description.+++" + NEWLINE);
|
||||
@@ -100,11 +94,9 @@ public class SingleKeyEntryTests {
|
||||
property.setId("spring.test.prop");
|
||||
property.setDescription("This is a description.");
|
||||
property.setType("java.util.Map<java.lang.String,java.lang.String>");
|
||||
|
||||
SingleKeyEntry entry = new SingleKeyEntry(property);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
entry.writeAsciidoc(builder);
|
||||
|
||||
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
|
||||
AsciidocBuilder builder = new AsciidocBuilder();
|
||||
entry.write(builder);
|
||||
assertThat(builder.toString()).isEqualTo("|`+spring.test.prop.*+`" + NEWLINE + "|"
|
||||
+ NEWLINE + "|+++This is a description.+++" + NEWLINE);
|
||||
}
|
||||
@@ -117,11 +109,9 @@ public class SingleKeyEntryTests {
|
||||
property.setDescription("This is a description.");
|
||||
property.setType("java.util.List<java.lang.String>");
|
||||
property.setDefaultValue(defaultValue);
|
||||
|
||||
SingleKeyEntry entry = new SingleKeyEntry(property);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
entry.writeAsciidoc(builder);
|
||||
|
||||
SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property);
|
||||
AsciidocBuilder builder = new AsciidocBuilder();
|
||||
entry.write(builder);
|
||||
assertThat(builder.toString()).isEqualTo("|`+spring.test.prop+`" + NEWLINE
|
||||
+ "|`+first," + NEWLINE + "second," + NEWLINE + "third+`" + NEWLINE
|
||||
+ "|+++This is a description.+++" + NEWLINE);
|
||||
Reference in New Issue
Block a user