@ -17,21 +17,19 @@
package org.springframework.boot.actuate.logging ;
package org.springframework.boot.actuate.logging ;
import java.io.File ;
import java.io.File ;
import java.io.IOException ;
import org.junit.Before ;
import org.junit.ClassRule ;
import org.junit.Rule ;
import org.junit.Test ;
import org.junit.Test ;
import org.junit.rules.TemporaryFolder ;
import org.junit.rules.TemporaryFolder ;
import org.junit.runner.RunWith ;
import org.junit.runner.RunWith ;
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointRunners ;
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointRunners ;
import org.springframework.boot. test.util.TestPropertyValues ;
import org.springframework.boot. logging.LogFile ;
import org.springframework.context.ConfigurableApplicationContext ;
import org.springframework.context.ConfigurableApplicationContext ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.core.env.Environment ;
import org.springframework.http.MediaType ;
import org.springframework.http.MediaType ;
import org.springframework.mock.env.MockEnvironment ;
import org.springframework.test.web.reactive.server.WebTestClient ;
import org.springframework.test.web.reactive.server.WebTestClient ;
import org.springframework.util.FileCopyUtils ;
import org.springframework.util.FileCopyUtils ;
@ -48,32 +46,19 @@ public class LogFileWebEndpointWebIntegrationTests {
private static WebTestClient client ;
private static WebTestClient client ;
@ Rule
@ Class Rule
public final TemporaryFolder temp = new TemporaryFolder ( ) ;
public static final TemporaryFolder temp = new TemporaryFolder ( ) ;
private File logFile ;
private static File logFile ;
@Before
public void setUp ( ) throws IOException {
this . logFile = this . temp . newFile ( ) ;
FileCopyUtils . copy ( "--TEST--" . getBytes ( ) , this . logFile ) ;
}
@Test
public void getRequestProduces404ResponseWhenLogFileNotFound ( ) {
client . get ( ) . uri ( "/actuator/logfile" ) . exchange ( ) . expectStatus ( ) . isNotFound ( ) ;
}
@Test
@Test
public void getRequestProducesResponseWithLogFile ( ) {
public void getRequestProducesResponseWithLogFile ( ) {
TestPropertyValues . of ( "logging.file:" + this . logFile . getAbsolutePath ( ) ) . applyTo ( context ) ;
client . get ( ) . uri ( "/actuator/logfile" ) . exchange ( ) . expectStatus ( ) . isOk ( ) . expectHeader ( )
client . get ( ) . uri ( "/actuator/logfile" ) . exchange ( ) . expectStatus ( ) . isOk ( ) . expectHeader ( )
. contentType ( "text/plain; charset=UTF-8" ) . expectBody ( String . class ) . isEqualTo ( "--TEST--" ) ;
. contentType ( "text/plain; charset=UTF-8" ) . expectBody ( String . class ) . isEqualTo ( "--TEST--" ) ;
}
}
@Test
@Test
public void getRequestThatAcceptsTextPlainProducesResponseWithLogFile ( ) {
public void getRequestThatAcceptsTextPlainProducesResponseWithLogFile ( ) {
TestPropertyValues . of ( "logging.file:" + this . logFile . getAbsolutePath ( ) ) . applyTo ( context ) ;
client . get ( ) . uri ( "/actuator/logfile" ) . accept ( MediaType . TEXT_PLAIN ) . exchange ( ) . expectStatus ( ) . isOk ( )
client . get ( ) . uri ( "/actuator/logfile" ) . accept ( MediaType . TEXT_PLAIN ) . exchange ( ) . expectStatus ( ) . isOk ( )
. expectHeader ( ) . contentType ( "text/plain; charset=UTF-8" ) . expectBody ( String . class ) . isEqualTo ( "--TEST--" ) ;
. expectHeader ( ) . contentType ( "text/plain; charset=UTF-8" ) . expectBody ( String . class ) . isEqualTo ( "--TEST--" ) ;
}
}
@ -82,8 +67,12 @@ public class LogFileWebEndpointWebIntegrationTests {
static class TestConfiguration {
static class TestConfiguration {
@Bean
@Bean
public LogFileWebEndpoint logFileEndpoint ( Environment environment ) {
public LogFileWebEndpoint logFileEndpoint ( ) throws Exception {
return new LogFileWebEndpoint ( environment ) ;
logFile = temp . newFile ( ) ;
FileCopyUtils . copy ( "--TEST--" . getBytes ( ) , logFile ) ;
MockEnvironment environment = new MockEnvironment ( ) ;
environment . setProperty ( "logging.file" , logFile . getAbsolutePath ( ) ) ;
return new LogFileWebEndpoint ( LogFile . get ( environment ) , null ) ;
}
}
}
}