From b055410ab4bdd4293d9a9aee1f3401ebdc7f53db Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 25 Mar 2019 11:58:09 +0100 Subject: [PATCH] Fix outdated tests Closes gh-16298 --- ...FileWebEndpointAutoConfigurationTests.java | 71 +++++++++++++------ 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java index bcd048c0cd9..aa2dd6922e6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java @@ -49,36 +49,71 @@ public class LogFileWebEndpointAutoConfigurationTests { public final TemporaryFolder temp = new TemporaryFolder(); @Test - public void logFileWebEndpointIsAutoConfiguredWhenLoggingFileIsSet() { - this.contextRunner.withPropertyValues("logging.file.name:test.log").run( - (context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class)); + public void runWithOnlyExposedShouldNotHaveEndpointBean() { + this.contextRunner + .withPropertyValues("management.endpoints.web.exposure.include=logfile") + .run((context) -> assertThat(context) + .doesNotHaveBean(LogFileWebEndpoint.class)); + } + + @Test + public void runWhenLoggingFileIsSetAndNotExposedShouldNotHaveEndpointBean() { + this.contextRunner.withPropertyValues("logging.file.name:test.log") + .run((context) -> assertThat(context) + .doesNotHaveBean(LogFileWebEndpoint.class)); + } + + @Test + public void runWhenLoggingFileIsSetAndExposedShouldHaveEndpointBean() { + this.contextRunner + .withPropertyValues("logging.file.name:test.log", + "management.endpoints.web.exposure.include=logfile") + .run((context) -> assertThat(context) + .hasSingleBean(LogFileWebEndpoint.class)); } @Test @Deprecated - public void logFileWebEndpointIsAutoConfiguredWhenLoggingFileIsSetWithDeprecatedProperty() { - this.contextRunner.withPropertyValues("logging.file:test.log").run( - (context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class)); + public void runWhenLoggingFileIsSetWithDeprecatedPropertyAndExposedShouldHaveEndpointBean() { + this.contextRunner + .withPropertyValues("logging.file:test.log", + "management.endpoints.web.exposure.include=logfile") + .run((context) -> assertThat(context) + .hasSingleBean(LogFileWebEndpoint.class)); } @Test - public void logFileWebEndpointIsAutoConfiguredWhenLoggingPathIsSet() { - this.contextRunner.withPropertyValues("logging.file.path:test/logs").run( - (context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class)); + public void runWhenLoggingPathIsSetAndNotExposedShouldNotHaveEndpointBean() { + this.contextRunner.withPropertyValues("logging.file.path:test/logs") + .run((context) -> assertThat(context) + .doesNotHaveBean(LogFileWebEndpoint.class)); + } + + @Test + public void runWhenLoggingPathIsSetAndExposedShouldHaveEndpointBean() { + this.contextRunner + .withPropertyValues("logging.file.path:test/logs", + "management.endpoints.web.exposure.include=logfile") + .run((context) -> assertThat(context) + .hasSingleBean(LogFileWebEndpoint.class)); } @Test @Deprecated - public void logFileWebEndpointIsAutoConfiguredWhenLoggingPathIsSetWithDeprecatedProperty() { - this.contextRunner.withPropertyValues("logging.path:test/logs").run( - (context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class)); + public void runWhenLoggingPathIsSetWithDeprecatedPropertyAndExposedShouldHaveEndpointBean() { + this.contextRunner + .withPropertyValues("logging.path:test/logs", + "management.endpoints.web.exposure.include=logfile") + .run((context) -> assertThat(context) + .hasSingleBean(LogFileWebEndpoint.class)); } @Test public void logFileWebEndpointIsAutoConfiguredWhenExternalFileIsSet() { this.contextRunner .withPropertyValues( - "management.endpoint.logfile.external-file:external.log") + "management.endpoint.logfile.external-file:external.log", + "management.endpoints.web.exposure.include=logfile") .run((context) -> assertThat(context) .hasSingleBean(LogFileWebEndpoint.class)); } @@ -92,20 +127,12 @@ public class LogFileWebEndpointAutoConfigurationTests { .doesNotHaveBean(LogFileWebEndpoint.class)); } - @Test - public void logFileWebEndpointCanBeExcluded() { - this.contextRunner - .withPropertyValues("logging.file.name:test.log", - "management.endpoints.web.exposure.exclude=logfile") - .run((context) -> assertThat(context) - .doesNotHaveBean(LogFileWebEndpoint.class)); - } - @Test public void logFileWebEndpointUsesConfiguredExternalFile() throws IOException { File file = this.temp.newFile(); FileCopyUtils.copy("--TEST--".getBytes(), file); this.contextRunner.withPropertyValues( + "management.endpoints.web.exposure.include=logfile", "management.endpoint.logfile.external-file:" + file.getAbsolutePath()) .run((context) -> { assertThat(context).hasSingleBean(LogFileWebEndpoint.class);