Polish "Create EndpointWebExtension only if necessary"

See gh-28475
This commit is contained in:
Stephane Nicoll
2021-11-16 08:22:35 +01:00
parent b658013a97
commit 52ecc1e0dd
5 changed files with 17 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -68,7 +68,8 @@ class CachesEndpointAutoConfigurationTests {
@Test
void runWhenOnlyExposedOverJmxShouldHaveEndpointBeanWithoutWebExtension() {
this.contextRunner.withBean(CacheManager.class, () -> mock(CacheManager.class))
.withPropertyValues("spring.jmx.enabled=true", "management.endpoints.jmx.exposure.include=caches")
.withPropertyValues("management.endpoints.web.exposure.include=info", "spring.jmx.enabled=true",
"management.endpoints.jmx.exposure.include=caches")
.run((context) -> assertThat(context).hasSingleBean(CachesEndpoint.class)
.doesNotHaveBean(CachesEndpointWebExtension.class));
}

View File

@@ -106,7 +106,8 @@ class ConfigurationPropertiesReportEndpointAutoConfigurationTests {
@Test
void runWhenOnlyExposedOverJmxShouldHaveEndpointBeanWithoutWebExtension() {
this.contextRunner
.withPropertyValues("spring.jmx.enabled=true", "management.endpoints.jmx.exposure.include=configprops")
.withPropertyValues("management.endpoints.web.exposure.include=info", "spring.jmx.enabled=true",
"management.endpoints.jmx.exposure.include=configprops")
.run((context) -> assertThat(context).hasSingleBean(ConfigurationPropertiesReportEndpoint.class)
.doesNotHaveBean(ConfigurationPropertiesReportEndpointWebExtension.class));
}

View File

@@ -94,6 +94,15 @@ class EnvironmentEndpointAutoConfigurationTests {
.run(validateSystemProperties("******", "******"));
}
@Test
void runWhenOnlyExposedOverJmxShouldHaveEndpointBeanWithoutWebExtension() {
this.contextRunner
.withPropertyValues("management.endpoints.web.exposure.include=info", "spring.jmx.enabled=true",
"management.endpoints.jmx.exposure.include=env")
.run((context) -> assertThat(context).hasSingleBean(EnvironmentEndpoint.class)
.doesNotHaveBean(EnvironmentEndpointWebExtension.class));
}
private ContextConsumer<AssertableApplicationContext> validateSystemProperties(String dbPassword, String apiKey) {
return (context) -> {
assertThat(context).hasSingleBean(EnvironmentEndpoint.class);
@@ -110,14 +119,6 @@ class EnvironmentEndpointAutoConfigurationTests {
.get();
}
@Test
void runWhenOnlyExposedOverJmxShouldHaveEndpointBeanWithoutWebExtension() {
this.contextRunner
.withPropertyValues("spring.jmx.enabled=true", "management.endpoints.jmx.exposure.include=env")
.run((context) -> assertThat(context).hasSingleBean(EnvironmentEndpoint.class)
.doesNotHaveBean(EnvironmentEndpointWebExtension.class));
}
@Configuration(proxyBeanMethods = false)
static class SanitizingFunctionConfiguration {

View File

@@ -75,7 +75,8 @@ class QuartzEndpointAutoConfigurationTests {
@Test
void runWhenOnlyExposedOverJmxShouldHaveEndpointBeanWithoutWebExtension() {
this.contextRunner.withBean(Scheduler.class, () -> mock(Scheduler.class))
.withPropertyValues("spring.jmx.enabled=true", "management.endpoints.jmx.exposure.include=quartz")
.withPropertyValues("management.endpoints.web.exposure.include=info", "spring.jmx.enabled=true",
"management.endpoints.jmx.exposure.include=quartz")
.run((context) -> assertThat(context).hasSingleBean(QuartzEndpoint.class)
.doesNotHaveBean(QuartzEndpointWebExtension.class));
}