Browse Source

Revisit metrics and tracing test properties

This commit renames 'spring.test.metrics.auto-configure' and
'spring.test.tracing.auto-configure' for consistency with the non-test
properties. It also adds a configuration metadata entry for
'spring.test.observability.auto-configure' that's superseded by these
two properties.

Closes gh-47776
pull/47784/head
Stéphane Nicoll 3 months ago
parent
commit
ffc822d852
  1. 7
      core/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json
  2. 3
      module/spring-boot-micrometer-metrics-test/src/main/java/org/springframework/boot/micrometer/metrics/test/autoconfigure/MetricsContextCustomizerFactory.java
  3. 4
      module/spring-boot-micrometer-metrics-test/src/main/resources/META-INF/spring-configuration-metadata.json
  4. 10
      module/spring-boot-micrometer-metrics-test/src/test/java/org/springframework/boot/micrometer/metrics/test/autoconfigure/MetricsContextCustomizerFactoryTests.java
  5. 3
      module/spring-boot-micrometer-tracing-test/src/main/java/org/springframework/boot/micrometer/tracing/test/autoconfigure/TracingContextCustomizerFactory.java
  6. 4
      module/spring-boot-micrometer-tracing-test/src/main/resources/META-INF/spring-configuration-metadata.json
  7. 8
      module/spring-boot-micrometer-tracing-test/src/test/java/org/springframework/boot/micrometer/tracing/test/autoconfigure/TracingContextCustomizerFactoryTests.java

7
core/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json

@ -6,6 +6,13 @@ @@ -6,6 +6,13 @@
"description": "Whether auto-configuration of JSON testers is enabled.",
"defaultValue": "true"
},
{
"name": "spring.test.observability.auto-configure",
"deprecation": {
"reason": "Superseded by 'spring.test.metrics.export' and 'spring.test.tracing.export'.",
"level": "error"
}
},
{
"name": "spring.test.print-condition-evaluation-report",
"type": "java.lang.Boolean",

3
module/spring-boot-micrometer-metrics-test/src/main/java/org/springframework/boot/micrometer/metrics/test/autoconfigure/MetricsContextCustomizerFactory.java

@ -41,8 +41,7 @@ import org.springframework.test.context.TestContextAnnotationUtils; @@ -41,8 +41,7 @@ import org.springframework.test.context.TestContextAnnotationUtils;
*/
class MetricsContextCustomizerFactory implements ContextCustomizerFactory {
// TODO spring.test.metrics.export?
static final String AUTO_CONFIGURE_PROPERTY = "spring.test.metrics.auto-configure";
static final String AUTO_CONFIGURE_PROPERTY = "spring.test.metrics.export";
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,

4
module/spring-boot-micrometer-metrics-test/src/main/resources/META-INF/spring-configuration-metadata.json

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
{
"properties": [
{
"name": "spring.test.metrics.auto-configure",
"name": "spring.test.metrics.export",
"type": "java.lang.Boolean",
"description": "Whether metrics should be auto-configured in tests.",
"description": "Whether metrics export should be auto-configured in tests.",
"defaultValue": false
}
]

10
module/spring-boot-micrometer-metrics-test/src/test/java/org/springframework/boot/micrometer/metrics/test/autoconfigure/MetricsContextCustomizerFactoryTests.java

@ -94,18 +94,18 @@ class MetricsContextCustomizerFactoryTests { @@ -94,18 +94,18 @@ class MetricsContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(NoAnnotation.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.metrics.auto-configure", "true");
environment.setProperty("spring.test.metrics.export", "true");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatMetricsAreEnabled(context);
}
@Test
void metricsCanBeDisabledViaProperty() {
void metricsExportCanBeDisabledViaProperty() {
ContextCustomizer customizer = createContextCustomizer(NoAnnotation.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.metrics.auto-configure", "false");
environment.setProperty("spring.test.metrics.export", "false");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatMetricsAreDisabled(context);
@ -116,7 +116,7 @@ class MetricsContextCustomizerFactoryTests { @@ -116,7 +116,7 @@ class MetricsContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(MetricsExportEnabled.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.metrics.auto-configure", "false");
environment.setProperty("spring.test.metrics.export", "false");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatMetricsAreEnabled(context);
@ -127,7 +127,7 @@ class MetricsContextCustomizerFactoryTests { @@ -127,7 +127,7 @@ class MetricsContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(MetricsExportDisabled.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.metrics.auto-configure", "true");
environment.setProperty("spring.test.metrics.export", "true");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatMetricsAreDisabled(context);

3
module/spring-boot-micrometer-tracing-test/src/main/java/org/springframework/boot/micrometer/tracing/test/autoconfigure/TracingContextCustomizerFactory.java

@ -41,8 +41,7 @@ import org.springframework.test.context.TestContextAnnotationUtils; @@ -41,8 +41,7 @@ import org.springframework.test.context.TestContextAnnotationUtils;
*/
class TracingContextCustomizerFactory implements ContextCustomizerFactory {
// TODO spring.test.tracing.export?
static final String AUTO_CONFIGURE_PROPERTY = "spring.test.tracing.auto-configure";
static final String AUTO_CONFIGURE_PROPERTY = "spring.test.tracing.export";
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,

4
module/spring-boot-micrometer-tracing-test/src/main/resources/META-INF/spring-configuration-metadata.json

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
{
"properties": [
{
"name": "spring.test.tracing.auto-configure",
"name": "spring.test.tracing.export",
"type": "java.lang.Boolean",
"description": "Whether tracing should be auto-configured in tests.",
"description": "Whether tracing export should be auto-configured in tests.",
"defaultValue": false
}
]

8
module/spring-boot-micrometer-tracing-test/src/test/java/org/springframework/boot/micrometer/tracing/test/autoconfigure/TracingContextCustomizerFactoryTests.java

@ -93,7 +93,7 @@ class TracingContextCustomizerFactoryTests { @@ -93,7 +93,7 @@ class TracingContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(NoAnnotation.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.tracing.auto-configure", "true");
environment.setProperty("spring.test.tracing.export", "true");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatTracingExportIsEnabled(context);
@ -104,7 +104,7 @@ class TracingContextCustomizerFactoryTests { @@ -104,7 +104,7 @@ class TracingContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(NoAnnotation.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.tracing.auto-configure", "false");
environment.setProperty("spring.test.tracing.export", "false");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatTracingExportIsDisabled(context);
@ -115,7 +115,7 @@ class TracingContextCustomizerFactoryTests { @@ -115,7 +115,7 @@ class TracingContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(TracingExportEnabled.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.tracing.auto-configure", "false");
environment.setProperty("spring.test.tracing.export", "false");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatTracingExportIsEnabled(context);
@ -126,7 +126,7 @@ class TracingContextCustomizerFactoryTests { @@ -126,7 +126,7 @@ class TracingContextCustomizerFactoryTests {
ContextCustomizer customizer = createContextCustomizer(TracingExportDisabled.class);
ConfigurableApplicationContext context = new GenericApplicationContext();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.test.tracing.auto-configure", "true");
environment.setProperty("spring.test.tracing.export", "true");
context.setEnvironment(environment);
applyCustomizerToContext(customizer, context);
assertThatTracingExportIsDisabled(context);

Loading…
Cancel
Save