Merge branch '2.1.x'
Closes gh-17486
This commit is contained in:
@@ -25,6 +25,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.logging.LogFile;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
@@ -43,8 +44,6 @@ class LogFileWebEndpointTests {
|
||||
|
||||
private final MockEnvironment environment = new MockEnvironment();
|
||||
|
||||
private final LogFileWebEndpoint endpoint = new LogFileWebEndpoint(this.environment);
|
||||
|
||||
private File logFile;
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,19 +54,22 @@ class LogFileWebEndpointTests {
|
||||
|
||||
@Test
|
||||
void nullResponseWithoutLogFile() {
|
||||
assertThat(this.endpoint.logFile()).isNull();
|
||||
LogFileWebEndpoint endpoint = new LogFileWebEndpoint(null, null);
|
||||
assertThat(endpoint.logFile()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullResponseWithMissingLogFile() {
|
||||
this.environment.setProperty("logging.file.name", "no_test.log");
|
||||
assertThat(this.endpoint.logFile()).isNull();
|
||||
LogFileWebEndpoint endpoint = new LogFileWebEndpoint(LogFile.get(this.environment), null);
|
||||
assertThat(endpoint.logFile()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceResponseWithLogFile() throws Exception {
|
||||
this.environment.setProperty("logging.file.name", this.logFile.getAbsolutePath());
|
||||
Resource resource = this.endpoint.logFile();
|
||||
LogFileWebEndpoint endpoint = new LogFileWebEndpoint(LogFile.get(this.environment), null);
|
||||
Resource resource = endpoint.logFile();
|
||||
assertThat(resource).isNotNull();
|
||||
assertThat(contentOf(resource.getFile())).isEqualTo("--TEST--");
|
||||
}
|
||||
@@ -76,14 +78,15 @@ class LogFileWebEndpointTests {
|
||||
@Deprecated
|
||||
void resourceResponseWithLogFileAndDeprecatedProperty() throws Exception {
|
||||
this.environment.setProperty("logging.file", this.logFile.getAbsolutePath());
|
||||
Resource resource = this.endpoint.logFile();
|
||||
LogFileWebEndpoint endpoint = new LogFileWebEndpoint(LogFile.get(this.environment), null);
|
||||
Resource resource = endpoint.logFile();
|
||||
assertThat(resource).isNotNull();
|
||||
assertThat(contentOf(resource.getFile())).isEqualTo("--TEST--");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceResponseWithExternalLogFile() throws Exception {
|
||||
LogFileWebEndpoint endpoint = new LogFileWebEndpoint(this.environment, this.logFile);
|
||||
LogFileWebEndpoint endpoint = new LogFileWebEndpoint(null, this.logFile);
|
||||
Resource resource = endpoint.logFile();
|
||||
assertThat(resource).isNotNull();
|
||||
assertThat(contentOf(resource.getFile())).isEqualTo("--TEST--");
|
||||
|
||||
@@ -19,16 +19,17 @@ package org.springframework.boot.actuate.logging;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.logging.LogFile;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
@@ -44,31 +45,28 @@ class LogFileWebEndpointWebIntegrationTests {
|
||||
|
||||
private WebTestClient client;
|
||||
|
||||
private File logFile;
|
||||
private static File tempFile;
|
||||
|
||||
@BeforeEach
|
||||
void setUp(@TempDir File temp, WebTestClient client, ConfigurableApplicationContext context) throws IOException {
|
||||
this.logFile = new File(temp, "test.log");
|
||||
void setUp(WebTestClient client, ConfigurableApplicationContext context) {
|
||||
this.client = client;
|
||||
this.context = context;
|
||||
FileCopyUtils.copy("--TEST--".getBytes(), this.logFile);
|
||||
|
||||
}
|
||||
|
||||
@WebEndpointTest
|
||||
void getRequestProduces404ResponseWhenLogFileNotFound() {
|
||||
this.client.get().uri("/actuator/logfile").exchange().expectStatus().isNotFound();
|
||||
@BeforeAll
|
||||
static void setup(@TempDir File temp) throws IOException {
|
||||
tempFile = temp;
|
||||
}
|
||||
|
||||
@WebEndpointTest
|
||||
void getRequestProducesResponseWithLogFile() {
|
||||
TestPropertyValues.of("logging.file.name:" + this.logFile.getAbsolutePath()).applyTo(this.context);
|
||||
this.client.get().uri("/actuator/logfile").exchange().expectStatus().isOk().expectHeader()
|
||||
.contentType("text/plain; charset=UTF-8").expectBody(String.class).isEqualTo("--TEST--");
|
||||
}
|
||||
|
||||
@WebEndpointTest
|
||||
void getRequestThatAcceptsTextPlainProducesResponseWithLogFile() {
|
||||
TestPropertyValues.of("logging.file:" + this.logFile.getAbsolutePath()).applyTo(this.context);
|
||||
this.client.get().uri("/actuator/logfile").accept(MediaType.TEXT_PLAIN).exchange().expectStatus().isOk()
|
||||
.expectHeader().contentType("text/plain; charset=UTF-8").expectBody(String.class).isEqualTo("--TEST--");
|
||||
}
|
||||
@@ -77,8 +75,12 @@ class LogFileWebEndpointWebIntegrationTests {
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
LogFileWebEndpoint logFileEndpoint(Environment environment) {
|
||||
return new LogFileWebEndpoint(environment);
|
||||
LogFileWebEndpoint logFileEndpoint() throws IOException {
|
||||
File logFile = new File(tempFile, "test.log");
|
||||
FileCopyUtils.copy("--TEST--".getBytes(), logFile);
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("logging.file", logFile.getAbsolutePath());
|
||||
return new LogFileWebEndpoint(LogFile.get(environment), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user