@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2012 - 20 19 the original author or authors .
* Copyright 2012 - 20 2 1 the original author or authors .
*
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -30,7 +30,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.mockito.Mockito ;
import org.mockito.Mockito ;
import org.springframework.beans.factory.ObjectProvider ;
import org.springframework.beans.factory.ObjectProvider ;
import org.springframework.boot.actuate.endpoint. http.ActuatorMediaType ;
import org.springframework.boot.actuate.endpoint. ApiVersion ;
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest ;
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest ;
import org.springframework.boot.logging.LogLevel ;
import org.springframework.boot.logging.LogLevel ;
import org.springframework.boot.logging.LoggerConfiguration ;
import org.springframework.boot.logging.LoggerConfiguration ;
@ -61,6 +61,10 @@ import static org.mockito.Mockito.verifyNoInteractions;
* /
* /
class LoggersEndpointWebIntegrationTests {
class LoggersEndpointWebIntegrationTests {
private static final String V2_JSON = ApiVersion . V2 . getProducedMimeType ( ) . toString ( ) ;
private static final String V3_JSON = ApiVersion . V3 . getProducedMimeType ( ) . toString ( ) ;
private WebTestClient client ;
private WebTestClient client ;
private LoggingSystem loggingSystem ;
private LoggingSystem loggingSystem ;
@ -125,8 +129,7 @@ class LoggersEndpointWebIntegrationTests {
@WebEndpointTest
@WebEndpointTest
void setLoggerUsingActuatorV2JsonShouldSetLogLevel ( ) {
void setLoggerUsingActuatorV2JsonShouldSetLogLevel ( ) {
this . client . post ( ) . uri ( "/actuator/loggers/ROOT" )
this . client . post ( ) . uri ( "/actuator/loggers/ROOT" ) . contentType ( MediaType . parseMediaType ( V2_JSON ) )
. contentType ( MediaType . parseMediaType ( ActuatorMediaType . V2_JSON ) )
. bodyValue ( Collections . singletonMap ( "configuredLevel" , "debug" ) ) . exchange ( ) . expectStatus ( )
. bodyValue ( Collections . singletonMap ( "configuredLevel" , "debug" ) ) . exchange ( ) . expectStatus ( )
. isNoContent ( ) ;
. isNoContent ( ) ;
verify ( this . loggingSystem ) . setLogLevel ( "ROOT" , LogLevel . DEBUG ) ;
verify ( this . loggingSystem ) . setLogLevel ( "ROOT" , LogLevel . DEBUG ) ;
@ -134,8 +137,7 @@ class LoggersEndpointWebIntegrationTests {
@WebEndpointTest
@WebEndpointTest
void setLoggerUsingActuatorV3JsonShouldSetLogLevel ( ) {
void setLoggerUsingActuatorV3JsonShouldSetLogLevel ( ) {
this . client . post ( ) . uri ( "/actuator/loggers/ROOT" )
this . client . post ( ) . uri ( "/actuator/loggers/ROOT" ) . contentType ( MediaType . parseMediaType ( V3_JSON ) )
. contentType ( MediaType . parseMediaType ( ActuatorMediaType . V3_JSON ) )
. bodyValue ( Collections . singletonMap ( "configuredLevel" , "debug" ) ) . exchange ( ) . expectStatus ( )
. bodyValue ( Collections . singletonMap ( "configuredLevel" , "debug" ) ) . exchange ( ) . expectStatus ( )
. isNoContent ( ) ;
. isNoContent ( ) ;
verify ( this . loggingSystem ) . setLogLevel ( "ROOT" , LogLevel . DEBUG ) ;
verify ( this . loggingSystem ) . setLogLevel ( "ROOT" , LogLevel . DEBUG ) ;
@ -143,8 +145,7 @@ class LoggersEndpointWebIntegrationTests {
@WebEndpointTest
@WebEndpointTest
void setLoggerGroupUsingActuatorV2JsonShouldSetLogLevel ( ) {
void setLoggerGroupUsingActuatorV2JsonShouldSetLogLevel ( ) {
this . client . post ( ) . uri ( "/actuator/loggers/test" )
this . client . post ( ) . uri ( "/actuator/loggers/test" ) . contentType ( MediaType . parseMediaType ( V2_JSON ) )
. contentType ( MediaType . parseMediaType ( ActuatorMediaType . V2_JSON ) )
. bodyValue ( Collections . singletonMap ( "configuredLevel" , "debug" ) ) . exchange ( ) . expectStatus ( )
. bodyValue ( Collections . singletonMap ( "configuredLevel" , "debug" ) ) . exchange ( ) . expectStatus ( )
. isNoContent ( ) ;
. isNoContent ( ) ;
verify ( this . loggingSystem ) . setLogLevel ( "test.member1" , LogLevel . DEBUG ) ;
verify ( this . loggingSystem ) . setLogLevel ( "test.member1" , LogLevel . DEBUG ) ;
@ -170,24 +171,21 @@ class LoggersEndpointWebIntegrationTests {
@WebEndpointTest
@WebEndpointTest
void setLoggerWithNullLogLevel ( ) {
void setLoggerWithNullLogLevel ( ) {
this . client . post ( ) . uri ( "/actuator/loggers/ROOT" )
this . client . post ( ) . uri ( "/actuator/loggers/ROOT" ) . contentType ( MediaType . parseMediaType ( V3_JSON ) )
. contentType ( MediaType . parseMediaType ( ActuatorMediaType . V3_JSON ) )
. bodyValue ( Collections . singletonMap ( "configuredLevel" , null ) ) . exchange ( ) . expectStatus ( ) . isNoContent ( ) ;
. bodyValue ( Collections . singletonMap ( "configuredLevel" , null ) ) . exchange ( ) . expectStatus ( ) . isNoContent ( ) ;
verify ( this . loggingSystem ) . setLogLevel ( "ROOT" , null ) ;
verify ( this . loggingSystem ) . setLogLevel ( "ROOT" , null ) ;
}
}
@WebEndpointTest
@WebEndpointTest
void setLoggerWithNoLogLevel ( ) {
void setLoggerWithNoLogLevel ( ) {
this . client . post ( ) . uri ( "/actuator/loggers/ROOT" )
this . client . post ( ) . uri ( "/actuator/loggers/ROOT" ) . contentType ( MediaType . parseMediaType ( V3_JSON ) )
. contentType ( MediaType . parseMediaType ( ActuatorMediaType . V3_JSON ) ) . bodyValue ( Collections . emptyMap ( ) )
. bodyValue ( Collections . emptyMap ( ) ) . exchange ( ) . expectStatus ( ) . isNoContent ( ) ;
. exchange ( ) . expectStatus ( ) . isNoContent ( ) ;
verify ( this . loggingSystem ) . setLogLevel ( "ROOT" , null ) ;
verify ( this . loggingSystem ) . setLogLevel ( "ROOT" , null ) ;
}
}
@WebEndpointTest
@WebEndpointTest
void setLoggerGroupWithNullLogLevel ( ) {
void setLoggerGroupWithNullLogLevel ( ) {
this . client . post ( ) . uri ( "/actuator/loggers/test" )
this . client . post ( ) . uri ( "/actuator/loggers/test" ) . contentType ( MediaType . parseMediaType ( V3_JSON ) )
. contentType ( MediaType . parseMediaType ( ActuatorMediaType . V3_JSON ) )
. bodyValue ( Collections . singletonMap ( "configuredLevel" , null ) ) . exchange ( ) . expectStatus ( ) . isNoContent ( ) ;
. bodyValue ( Collections . singletonMap ( "configuredLevel" , null ) ) . exchange ( ) . expectStatus ( ) . isNoContent ( ) ;
verify ( this . loggingSystem ) . setLogLevel ( "test.member1" , null ) ;
verify ( this . loggingSystem ) . setLogLevel ( "test.member1" , null ) ;
verify ( this . loggingSystem ) . setLogLevel ( "test.member2" , null ) ;
verify ( this . loggingSystem ) . setLogLevel ( "test.member2" , null ) ;
@ -195,9 +193,8 @@ class LoggersEndpointWebIntegrationTests {
@WebEndpointTest
@WebEndpointTest
void setLoggerGroupWithNoLogLevel ( ) {
void setLoggerGroupWithNoLogLevel ( ) {
this . client . post ( ) . uri ( "/actuator/loggers/test" )
this . client . post ( ) . uri ( "/actuator/loggers/test" ) . contentType ( MediaType . parseMediaType ( V3_JSON ) )
. contentType ( MediaType . parseMediaType ( ActuatorMediaType . V3_JSON ) ) . bodyValue ( Collections . emptyMap ( ) )
. bodyValue ( Collections . emptyMap ( ) ) . exchange ( ) . expectStatus ( ) . isNoContent ( ) ;
. exchange ( ) . expectStatus ( ) . isNoContent ( ) ;
verify ( this . loggingSystem ) . setLogLevel ( "test.member1" , null ) ;
verify ( this . loggingSystem ) . setLogLevel ( "test.member1" , null ) ;
verify ( this . loggingSystem ) . setLogLevel ( "test.member2" , null ) ;
verify ( this . loggingSystem ) . setLogLevel ( "test.member2" , null ) ;
}
}