forked from spring-projects/spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,060 additions
and
821 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...java/org/springframework/boot/configurationprocessor/AbstractMetadataGenerationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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 | ||
* | ||
* 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.boot.configurationprocessor; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; | ||
import org.springframework.boot.testsupport.compiler.TestCompiler; | ||
|
||
/** | ||
* Base test infrastructure for metadata generation tests. | ||
* | ||
* @author Stephane Nicoll | ||
*/ | ||
public abstract class AbstractMetadataGenerationTests { | ||
|
||
@Rule | ||
public TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
||
private TestCompiler compiler; | ||
|
||
@Before | ||
public void createCompiler() throws IOException { | ||
this.compiler = new TestCompiler(this.temporaryFolder); | ||
} | ||
|
||
protected TestCompiler getCompiler() { | ||
return this.compiler; | ||
} | ||
|
||
protected ConfigurationMetadata compile(Class<?>... types) { | ||
TestConfigurationMetadataAnnotationProcessor processor = new TestConfigurationMetadataAnnotationProcessor( | ||
this.compiler.getOutputLocation()); | ||
this.compiler.getTask(types).call(processor); | ||
return processor.getMetadata(); | ||
} | ||
|
||
} |
819 changes: 2 additions & 817 deletions
819
...gframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java
Large diffs are not rendered by default.
Oops, something went wrong.
181 changes: 181 additions & 0 deletions
181
...java/org/springframework/boot/configurationprocessor/EndpointMetadataGenerationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
/* | ||
* 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 | ||
* | ||
* 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.boot.configurationprocessor; | ||
|
||
import java.time.Duration; | ||
|
||
import org.junit.Test; | ||
|
||
import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; | ||
import org.springframework.boot.configurationprocessor.metadata.Metadata; | ||
import org.springframework.boot.configurationsample.endpoint.CamelCaseEndpoint; | ||
import org.springframework.boot.configurationsample.endpoint.CustomPropertiesEndpoint; | ||
import org.springframework.boot.configurationsample.endpoint.DisabledEndpoint; | ||
import org.springframework.boot.configurationsample.endpoint.EnabledEndpoint; | ||
import org.springframework.boot.configurationsample.endpoint.SimpleEndpoint; | ||
import org.springframework.boot.configurationsample.endpoint.SpecificEndpoint; | ||
import org.springframework.boot.configurationsample.endpoint.incremental.IncrementalEndpoint; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Metadata generation tests for Actuator endpoints. | ||
* | ||
* @author Stephane Nicoll | ||
*/ | ||
public class EndpointMetadataGenerationTests extends AbstractMetadataGenerationTests { | ||
|
||
@Test | ||
public void simpleEndpoint() { | ||
ConfigurationMetadata metadata = compile(SimpleEndpoint.class); | ||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.simple") | ||
.fromSource(SimpleEndpoint.class)); | ||
assertThat(metadata).has(enabledFlag("simple", true)); | ||
assertThat(metadata).has(cacheTtl("simple")); | ||
assertThat(metadata.getItems()).hasSize(3); | ||
} | ||
|
||
@Test | ||
public void disableEndpoint() { | ||
ConfigurationMetadata metadata = compile(DisabledEndpoint.class); | ||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.disabled") | ||
.fromSource(DisabledEndpoint.class)); | ||
assertThat(metadata).has(enabledFlag("disabled", false)); | ||
assertThat(metadata.getItems()).hasSize(2); | ||
} | ||
|
||
@Test | ||
public void enabledEndpoint() { | ||
ConfigurationMetadata metadata = compile(EnabledEndpoint.class); | ||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.enabled") | ||
.fromSource(EnabledEndpoint.class)); | ||
assertThat(metadata).has(enabledFlag("enabled", true)); | ||
assertThat(metadata.getItems()).hasSize(2); | ||
} | ||
|
||
@Test | ||
public void customPropertiesEndpoint() { | ||
ConfigurationMetadata metadata = compile(CustomPropertiesEndpoint.class); | ||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.customprops") | ||
.fromSource(CustomPropertiesEndpoint.class)); | ||
assertThat(metadata) | ||
.has(Metadata.withProperty("management.endpoint.customprops.name") | ||
.ofType(String.class).withDefaultValue("test")); | ||
assertThat(metadata).has(enabledFlag("customprops", true)); | ||
assertThat(metadata).has(cacheTtl("customprops")); | ||
assertThat(metadata.getItems()).hasSize(4); | ||
} | ||
|
||
@Test | ||
public void specificEndpoint() { | ||
ConfigurationMetadata metadata = compile(SpecificEndpoint.class); | ||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.specific") | ||
.fromSource(SpecificEndpoint.class)); | ||
assertThat(metadata).has(enabledFlag("specific", true)); | ||
assertThat(metadata).has(cacheTtl("specific")); | ||
assertThat(metadata.getItems()).hasSize(3); | ||
} | ||
|
||
@Test | ||
public void camelCaseEndpoint() { | ||
ConfigurationMetadata metadata = compile(CamelCaseEndpoint.class); | ||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.pascal-case") | ||
.fromSource(CamelCaseEndpoint.class)); | ||
assertThat(metadata).has(enabledFlag("PascalCase", "pascal-case", true)); | ||
assertThat(metadata.getItems()).hasSize(2); | ||
} | ||
|
||
@Test | ||
public void incrementalEndpointBuildChangeGeneralEnabledFlag() throws Exception { | ||
TestProject project = new TestProject(this.temporaryFolder, | ||
IncrementalEndpoint.class); | ||
ConfigurationMetadata metadata = project.fullBuild(); | ||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.incremental") | ||
.fromSource(IncrementalEndpoint.class)); | ||
assertThat(metadata).has(enabledFlag("incremental", true)); | ||
assertThat(metadata).has(cacheTtl("incremental")); | ||
assertThat(metadata.getItems()).hasSize(3); | ||
project.replaceText(IncrementalEndpoint.class, "id = \"incremental\"", | ||
"id = \"incremental\", enableByDefault = false"); | ||
metadata = project.incrementalBuild(IncrementalEndpoint.class); | ||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.incremental") | ||
.fromSource(IncrementalEndpoint.class)); | ||
assertThat(metadata).has(enabledFlag("incremental", false)); | ||
assertThat(metadata).has(cacheTtl("incremental")); | ||
assertThat(metadata.getItems()).hasSize(3); | ||
} | ||
|
||
@Test | ||
public void incrementalEndpointBuildChangeCacheFlag() throws Exception { | ||
TestProject project = new TestProject(this.temporaryFolder, | ||
IncrementalEndpoint.class); | ||
ConfigurationMetadata metadata = project.fullBuild(); | ||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.incremental") | ||
.fromSource(IncrementalEndpoint.class)); | ||
assertThat(metadata).has(enabledFlag("incremental", true)); | ||
assertThat(metadata).has(cacheTtl("incremental")); | ||
assertThat(metadata.getItems()).hasSize(3); | ||
project.replaceText(IncrementalEndpoint.class, "@Nullable String param", | ||
"String param"); | ||
metadata = project.incrementalBuild(IncrementalEndpoint.class); | ||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.incremental") | ||
.fromSource(IncrementalEndpoint.class)); | ||
assertThat(metadata).has(enabledFlag("incremental", true)); | ||
assertThat(metadata.getItems()).hasSize(2); | ||
} | ||
|
||
@Test | ||
public void incrementalEndpointBuildEnableSpecificEndpoint() throws Exception { | ||
TestProject project = new TestProject(this.temporaryFolder, | ||
SpecificEndpoint.class); | ||
ConfigurationMetadata metadata = project.fullBuild(); | ||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.specific") | ||
.fromSource(SpecificEndpoint.class)); | ||
assertThat(metadata).has(enabledFlag("specific", true)); | ||
assertThat(metadata).has(cacheTtl("specific")); | ||
assertThat(metadata.getItems()).hasSize(3); | ||
project.replaceText(SpecificEndpoint.class, "enableByDefault = true", | ||
"enableByDefault = false"); | ||
metadata = project.incrementalBuild(SpecificEndpoint.class); | ||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.specific") | ||
.fromSource(SpecificEndpoint.class)); | ||
assertThat(metadata).has(enabledFlag("specific", false)); | ||
assertThat(metadata).has(cacheTtl("specific")); | ||
assertThat(metadata.getItems()).hasSize(3); | ||
} | ||
|
||
private Metadata.MetadataItemCondition enabledFlag(String endpointId, | ||
String endpointSuffix, Boolean defaultValue) { | ||
return Metadata | ||
.withEnabledFlag("management.endpoint." + endpointSuffix + ".enabled") | ||
.withDefaultValue(defaultValue).withDescription( | ||
String.format("Whether to enable the %s endpoint.", endpointId)); | ||
} | ||
|
||
private Metadata.MetadataItemCondition enabledFlag(String endpointId, | ||
Boolean defaultValue) { | ||
return enabledFlag(endpointId, endpointId, defaultValue); | ||
} | ||
|
||
private Metadata.MetadataItemCondition cacheTtl(String endpointId) { | ||
return Metadata | ||
.withProperty("management.endpoint." + endpointId + ".cache.time-to-live") | ||
.ofType(Duration.class).withDefaultValue("0ms") | ||
.withDescription("Maximum time that a response can be cached."); | ||
} | ||
|
||
} |
112 changes: 112 additions & 0 deletions
112
...java/org/springframework/boot/configurationprocessor/GenericsMetadataGenerationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* 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 | ||
* | ||
* 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.boot.configurationprocessor; | ||
|
||
import org.junit.Test; | ||
|
||
import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; | ||
import org.springframework.boot.configurationprocessor.metadata.Metadata; | ||
import org.springframework.boot.configurationsample.generic.AbstractGenericProperties; | ||
import org.springframework.boot.configurationsample.generic.GenericConfig; | ||
import org.springframework.boot.configurationsample.generic.SimpleGenericProperties; | ||
import org.springframework.boot.configurationsample.generic.UnresolvedGenericProperties; | ||
import org.springframework.boot.configurationsample.generic.WildcardConfig; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Metadata generation tests for generics handling. | ||
* | ||
* @author Stephane Nicoll | ||
*/ | ||
public class GenericsMetadataGenerationTests extends AbstractMetadataGenerationTests { | ||
|
||
@Test | ||
public void simpleGenericProperties() { | ||
ConfigurationMetadata metadata = compile(AbstractGenericProperties.class, | ||
SimpleGenericProperties.class); | ||
assertThat(metadata).has( | ||
Metadata.withGroup("generic").fromSource(SimpleGenericProperties.class)); | ||
assertThat(metadata).has(Metadata.withProperty("generic.name", String.class) | ||
.fromSource(SimpleGenericProperties.class) | ||
.withDescription("Generic name.").withDefaultValue(null)); | ||
assertThat(metadata).has(Metadata | ||
.withProperty("generic.mappings", | ||
"java.util.Map<java.lang.Integer,java.time.Duration>") | ||
.fromSource(SimpleGenericProperties.class) | ||
.withDescription("Generic mappings.").withDefaultValue(null)); | ||
assertThat(metadata.getItems()).hasSize(3); | ||
} | ||
|
||
@Test | ||
public void unresolvedGenericProperties() { | ||
ConfigurationMetadata metadata = compile(AbstractGenericProperties.class, | ||
UnresolvedGenericProperties.class); | ||
assertThat(metadata).has(Metadata.withGroup("generic") | ||
.fromSource(UnresolvedGenericProperties.class)); | ||
assertThat(metadata).has(Metadata.withProperty("generic.name", String.class) | ||
.fromSource(UnresolvedGenericProperties.class) | ||
.withDescription("Generic name.").withDefaultValue(null)); | ||
assertThat(metadata).has(Metadata | ||
.withProperty("generic.mappings", | ||
"java.util.Map<java.lang.Number,java.lang.Object>") | ||
.fromSource(UnresolvedGenericProperties.class) | ||
.withDescription("Generic mappings.").withDefaultValue(null)); | ||
assertThat(metadata.getItems()).hasSize(3); | ||
} | ||
|
||
@Test | ||
public void genericTypes() { | ||
ConfigurationMetadata metadata = compile(GenericConfig.class); | ||
assertThat(metadata).has(Metadata.withGroup("generic").ofType( | ||
"org.springframework.boot.configurationsample.generic.GenericConfig")); | ||
assertThat(metadata).has(Metadata.withGroup("generic.foo").ofType( | ||
"org.springframework.boot.configurationsample.generic.GenericConfig$Foo")); | ||
assertThat(metadata).has(Metadata.withGroup("generic.foo.bar").ofType( | ||
"org.springframework.boot.configurationsample.generic.GenericConfig$Bar")); | ||
assertThat(metadata).has(Metadata.withGroup("generic.foo.bar.biz").ofType( | ||
"org.springframework.boot.configurationsample.generic.GenericConfig$Bar$Biz")); | ||
assertThat(metadata).has(Metadata.withProperty("generic.foo.name") | ||
.ofType(String.class).fromSource(GenericConfig.Foo.class)); | ||
assertThat(metadata).has(Metadata.withProperty("generic.foo.string-to-bar") | ||
.ofType("java.util.Map<java.lang.String,org.springframework.boot.configurationsample.generic.GenericConfig$Bar<java.lang.Integer>>") | ||
.fromSource(GenericConfig.Foo.class)); | ||
assertThat(metadata).has(Metadata.withProperty("generic.foo.string-to-integer") | ||
.ofType("java.util.Map<java.lang.String,java.lang.Integer>") | ||
.fromSource(GenericConfig.Foo.class)); | ||
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.name") | ||
.ofType("java.lang.String").fromSource(GenericConfig.Bar.class)); | ||
assertThat(metadata).has(Metadata.withProperty("generic.foo.bar.biz.name") | ||
.ofType("java.lang.String").fromSource(GenericConfig.Bar.Biz.class)); | ||
assertThat(metadata.getItems()).hasSize(9); | ||
} | ||
|
||
@Test | ||
public void wildcardTypes() { | ||
ConfigurationMetadata metadata = compile(WildcardConfig.class); | ||
assertThat(metadata) | ||
.has(Metadata.withGroup("wildcard").ofType(WildcardConfig.class)); | ||
assertThat(metadata).has(Metadata.withProperty("wildcard.string-to-number") | ||
.ofType("java.util.Map<java.lang.String,? extends java.lang.Number>") | ||
.fromSource(WildcardConfig.class)); | ||
assertThat(metadata).has(Metadata.withProperty("wildcard.integers") | ||
.ofType("java.util.List<? super java.lang.Integer>") | ||
.fromSource(WildcardConfig.class)); | ||
assertThat(metadata.getItems()).hasSize(3); | ||
} | ||
|
||
} |
Oops, something went wrong.