Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
9166bb5f
Commit
9166bb5f
authored
Apr 19, 2017
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
75f8e8a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
22 deletions
+19
-22
LoggersMvcEndpointTests.java
...rk/boot/actuate/endpoint/mvc/LoggersMvcEndpointTests.java
+19
-22
No files found.
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpointTests.java
View file @
9166bb5f
...
...
@@ -70,6 +70,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@TestPropertySource
(
properties
=
"management.security.enabled=false"
)
public
class
LoggersMvcEndpointTests
{
private
static
final
String
PATH
=
"/application/loggers"
;
@Autowired
private
WebApplicationContext
context
;
...
...
@@ -99,48 +101,47 @@ public class LoggersMvcEndpointTests {
.
singletonList
(
new
LoggerConfiguration
(
"ROOT"
,
null
,
LogLevel
.
DEBUG
)));
String
expected
=
"{\"levels\":[\"OFF\",\"FATAL\",\"ERROR\",\"WARN\",\"INFO\",\"DEBUG\",\"TRACE\"],"
+
"\"loggers\":{\"ROOT\":{\"configuredLevel\":null,\"effectiveLevel\":\"DEBUG\"}}}"
;
this
.
mvc
.
perform
(
get
(
"/application/loggers
"
)).
andExpect
(
status
().
isOk
())
this
.
mvc
.
perform
(
get
(
PATH
+
"
"
)).
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
json
(
expected
));
}
@Test
public
void
getLoggersWhenDisabledShouldReturnNotFound
()
throws
Exception
{
this
.
context
.
getBean
(
LoggersEndpoint
.
class
).
setEnabled
(
false
);
this
.
mvc
.
perform
(
get
(
"/application/loggers
"
)).
andExpect
(
status
().
isNotFound
());
this
.
mvc
.
perform
(
get
(
PATH
+
"
"
)).
andExpect
(
status
().
isNotFound
());
}
@Test
public
void
getLoggerShouldReturnLogLevels
()
throws
Exception
{
given
(
this
.
loggingSystem
.
getLoggerConfiguration
(
"ROOT"
))
.
willReturn
(
new
LoggerConfiguration
(
"ROOT"
,
null
,
LogLevel
.
DEBUG
));
this
.
mvc
.
perform
(
get
(
"/application/loggers
/ROOT"
)).
andExpect
(
status
().
isOk
())
this
.
mvc
.
perform
(
get
(
PATH
+
"
/ROOT"
)).
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
string
(
equalTo
(
"{\"configuredLevel\":null,
"
+
"
\"effectiveLevel\":\"DEBUG\"}"
)));
"{\"configuredLevel\":null,\"effectiveLevel\":\"DEBUG\"}"
)));
}
@Test
public
void
getLoggersRootWhenDisabledShouldReturnNotFound
()
throws
Exception
{
this
.
context
.
getBean
(
LoggersEndpoint
.
class
).
setEnabled
(
false
);
this
.
mvc
.
perform
(
get
(
"/application/loggers/ROOT"
))
.
andExpect
(
status
().
isNotFound
());
this
.
mvc
.
perform
(
get
(
PATH
+
"/ROOT"
)).
andExpect
(
status
().
isNotFound
());
}
@Test
public
void
getLoggersWhenLoggerNotFoundShouldReturnNotFound
()
throws
Exception
{
this
.
mvc
.
perform
(
get
(
"/application/loggers
/com.does.not.exist"
))
this
.
mvc
.
perform
(
get
(
PATH
+
"
/com.does.not.exist"
))
.
andExpect
(
status
().
isNotFound
());
}
@Test
public
void
contentTypeForGetDefaultsToActuatorV2Json
()
throws
Exception
{
this
.
mvc
.
perform
(
get
(
"/application/loggers
"
)).
andExpect
(
status
().
isOk
())
this
.
mvc
.
perform
(
get
(
PATH
+
"
"
)).
andExpect
(
status
().
isOk
())
.
andExpect
(
header
().
string
(
"Content-Type"
,
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"
));
}
@Test
public
void
contentTypeForGetCanBeApplicationJson
()
throws
Exception
{
this
.
mvc
.
perform
(
get
(
"/application/loggers
"
).
header
(
HttpHeaders
.
ACCEPT
,
this
.
mvc
.
perform
(
get
(
PATH
+
"
"
).
header
(
HttpHeaders
.
ACCEPT
,
MediaType
.
APPLICATION_JSON_VALUE
)).
andExpect
(
status
().
isOk
())
.
andExpect
(
header
().
string
(
"Content-Type"
,
MediaType
.
APPLICATION_JSON_UTF8_VALUE
));
...
...
@@ -148,16 +149,14 @@ public class LoggersMvcEndpointTests {
@Test
public
void
setLoggerUsingApplicationJsonShouldSetLogLevel
()
throws
Exception
{
this
.
mvc
.
perform
(
post
(
"/application/loggers/ROOT"
).
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
"{\"configuredLevel\":\"debug\"}"
))
.
andExpect
(
status
().
isOk
());
this
.
mvc
.
perform
(
post
(
PATH
+
"/ROOT"
).
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
"{\"configuredLevel\":\"debug\"}"
)).
andExpect
(
status
().
isOk
());
verify
(
this
.
loggingSystem
).
setLogLevel
(
"ROOT"
,
LogLevel
.
DEBUG
);
}
@Test
public
void
setLoggerUsingActuatorV2JsonShouldSetLogLevel
()
throws
Exception
{
this
.
mvc
.
perform
(
post
(
"/application/loggers
/ROOT"
)
this
.
mvc
.
perform
(
post
(
PATH
+
"
/ROOT"
)
.
contentType
(
ActuatorMediaTypes
.
APPLICATION_ACTUATOR_V2_JSON
)
.
content
(
"{\"configuredLevel\":\"debug\"}"
)).
andExpect
(
status
().
isOk
());
verify
(
this
.
loggingSystem
).
setLogLevel
(
"ROOT"
,
LogLevel
.
DEBUG
);
...
...
@@ -166,18 +165,16 @@ public class LoggersMvcEndpointTests {
@Test
public
void
setLoggerWhenDisabledShouldReturnNotFound
()
throws
Exception
{
this
.
context
.
getBean
(
LoggersEndpoint
.
class
).
setEnabled
(
false
);
this
.
mvc
.
perform
(
post
(
"/application/loggers/ROOT"
).
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
"{\"configuredLevel\":\"DEBUG\"}"
))
this
.
mvc
.
perform
(
post
(
PATH
+
"/ROOT"
).
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
"{\"configuredLevel\":\"DEBUG\"}"
))
.
andExpect
(
status
().
isNotFound
());
verifyZeroInteractions
(
this
.
loggingSystem
);
}
@Test
public
void
setLoggerWithWrongLogLevel
()
throws
Exception
{
this
.
mvc
.
perform
(
post
(
"/application/loggers/ROOT"
).
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
"{\"configuredLevel\":\"other\"}"
))
this
.
mvc
.
perform
(
post
(
PATH
+
"/ROOT"
).
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
"{\"configuredLevel\":\"other\"}"
))
.
andExpect
(
status
().
is4xxClientError
());
verifyZeroInteractions
(
this
.
loggingSystem
);
}
...
...
@@ -187,9 +184,9 @@ public class LoggersMvcEndpointTests {
throws
Exception
{
given
(
this
.
loggingSystem
.
getLoggerConfiguration
(
"com.png"
))
.
willReturn
(
new
LoggerConfiguration
(
"com.png"
,
null
,
LogLevel
.
DEBUG
));
this
.
mvc
.
perform
(
get
(
"/application/loggers
/com.png"
)).
andExpect
(
status
().
isOk
())
this
.
mvc
.
perform
(
get
(
PATH
+
"
/com.png"
)).
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
string
(
equalTo
(
"{\"configuredLevel\":null,
"
+
"
\"effectiveLevel\":\"DEBUG\"}"
)));
"{\"configuredLevel\":null,\"effectiveLevel\":\"DEBUG\"}"
)));
}
@Configuration
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment