Skip to content

Commit b055410

Browse files
committed
Fix outdated tests
Closes gh-16298
1 parent b604ccc commit b055410

File tree

1 file changed

+49
-22
lines changed

1 file changed

+49
-22
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,54 +49,80 @@ public class LogFileWebEndpointAutoConfigurationTests {
4949
public final TemporaryFolder temp = new TemporaryFolder();
5050

5151
@Test
52-
public void logFileWebEndpointIsAutoConfiguredWhenLoggingFileIsSet() {
53-
this.contextRunner.withPropertyValues("logging.file.name:test.log").run(
54-
(context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
52+
public void runWithOnlyExposedShouldNotHaveEndpointBean() {
53+
this.contextRunner
54+
.withPropertyValues("management.endpoints.web.exposure.include=logfile")
55+
.run((context) -> assertThat(context)
56+
.doesNotHaveBean(LogFileWebEndpoint.class));
5557
}
5658

5759
@Test
58-
@Deprecated
59-
public void logFileWebEndpointIsAutoConfiguredWhenLoggingFileIsSetWithDeprecatedProperty() {
60-
this.contextRunner.withPropertyValues("logging.file:test.log").run(
61-
(context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
60+
public void runWhenLoggingFileIsSetAndNotExposedShouldNotHaveEndpointBean() {
61+
this.contextRunner.withPropertyValues("logging.file.name:test.log")
62+
.run((context) -> assertThat(context)
63+
.doesNotHaveBean(LogFileWebEndpoint.class));
6264
}
6365

6466
@Test
65-
public void logFileWebEndpointIsAutoConfiguredWhenLoggingPathIsSet() {
66-
this.contextRunner.withPropertyValues("logging.file.path:test/logs").run(
67-
(context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
67+
public void runWhenLoggingFileIsSetAndExposedShouldHaveEndpointBean() {
68+
this.contextRunner
69+
.withPropertyValues("logging.file.name:test.log",
70+
"management.endpoints.web.exposure.include=logfile")
71+
.run((context) -> assertThat(context)
72+
.hasSingleBean(LogFileWebEndpoint.class));
6873
}
6974

7075
@Test
7176
@Deprecated
72-
public void logFileWebEndpointIsAutoConfiguredWhenLoggingPathIsSetWithDeprecatedProperty() {
73-
this.contextRunner.withPropertyValues("logging.path:test/logs").run(
74-
(context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
77+
public void runWhenLoggingFileIsSetWithDeprecatedPropertyAndExposedShouldHaveEndpointBean() {
78+
this.contextRunner
79+
.withPropertyValues("logging.file:test.log",
80+
"management.endpoints.web.exposure.include=logfile")
81+
.run((context) -> assertThat(context)
82+
.hasSingleBean(LogFileWebEndpoint.class));
7583
}
7684

7785
@Test
78-
public void logFileWebEndpointIsAutoConfiguredWhenExternalFileIsSet() {
86+
public void runWhenLoggingPathIsSetAndNotExposedShouldNotHaveEndpointBean() {
87+
this.contextRunner.withPropertyValues("logging.file.path:test/logs")
88+
.run((context) -> assertThat(context)
89+
.doesNotHaveBean(LogFileWebEndpoint.class));
90+
}
91+
92+
@Test
93+
public void runWhenLoggingPathIsSetAndExposedShouldHaveEndpointBean() {
7994
this.contextRunner
80-
.withPropertyValues(
81-
"management.endpoint.logfile.external-file:external.log")
95+
.withPropertyValues("logging.file.path:test/logs",
96+
"management.endpoints.web.exposure.include=logfile")
8297
.run((context) -> assertThat(context)
8398
.hasSingleBean(LogFileWebEndpoint.class));
8499
}
85100

86101
@Test
87-
public void logFileWebEndpointCanBeDisabled() {
102+
@Deprecated
103+
public void runWhenLoggingPathIsSetWithDeprecatedPropertyAndExposedShouldHaveEndpointBean() {
88104
this.contextRunner
89-
.withPropertyValues("logging.file.name:test.log",
90-
"management.endpoint.logfile.enabled:false")
105+
.withPropertyValues("logging.path:test/logs",
106+
"management.endpoints.web.exposure.include=logfile")
91107
.run((context) -> assertThat(context)
92-
.doesNotHaveBean(LogFileWebEndpoint.class));
108+
.hasSingleBean(LogFileWebEndpoint.class));
109+
}
110+
111+
@Test
112+
public void logFileWebEndpointIsAutoConfiguredWhenExternalFileIsSet() {
113+
this.contextRunner
114+
.withPropertyValues(
115+
"management.endpoint.logfile.external-file:external.log",
116+
"management.endpoints.web.exposure.include=logfile")
117+
.run((context) -> assertThat(context)
118+
.hasSingleBean(LogFileWebEndpoint.class));
93119
}
94120

95121
@Test
96-
public void logFileWebEndpointCanBeExcluded() {
122+
public void logFileWebEndpointCanBeDisabled() {
97123
this.contextRunner
98124
.withPropertyValues("logging.file.name:test.log",
99-
"management.endpoints.web.exposure.exclude=logfile")
125+
"management.endpoint.logfile.enabled:false")
100126
.run((context) -> assertThat(context)
101127
.doesNotHaveBean(LogFileWebEndpoint.class));
102128
}
@@ -106,6 +132,7 @@ public void logFileWebEndpointUsesConfiguredExternalFile() throws IOException {
106132
File file = this.temp.newFile();
107133
FileCopyUtils.copy("--TEST--".getBytes(), file);
108134
this.contextRunner.withPropertyValues(
135+
"management.endpoints.web.exposure.include=logfile",
109136
"management.endpoint.logfile.external-file:" + file.getAbsolutePath())
110137
.run((context) -> {
111138
assertThat(context).hasSingleBean(LogFileWebEndpoint.class);

0 commit comments

Comments
 (0)