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
f1ec810c
Commit
f1ec810c
authored
Sep 25, 2019
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
323a78c4
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
109 additions
and
160 deletions
+109
-160
EndpointsPropertiesSampleActuatorApplicationTests.java
...or/EndpointsPropertiesSampleActuatorApplicationTests.java
+6
-7
ManagementAddressActuatorApplicationTests.java
...t/actuator/ManagementAddressActuatorApplicationTests.java
+6
-5
ManagementDifferentPortSampleActuatorApplicationTests.java
...anagementDifferentPortSampleActuatorApplicationTests.java
+1
-5
ManagementPathSampleActuatorApplicationTests.java
...ctuator/ManagementPathSampleActuatorApplicationTests.java
+6
-8
ManagementPortAndPathSampleActuatorApplicationTests.java
.../ManagementPortAndPathSampleActuatorApplicationTests.java
+17
-26
ManagementPortSampleActuatorApplicationTests.java
...ctuator/ManagementPortSampleActuatorApplicationTests.java
+12
-18
NoManagementSampleActuatorApplicationTests.java
.../actuator/NoManagementSampleActuatorApplicationTests.java
+8
-11
SampleActuatorApplicationTests.java
...va/smoketest/actuator/SampleActuatorApplicationTests.java
+36
-55
ServletPathSampleActuatorApplicationTests.java
...t/actuator/ServletPathSampleActuatorApplicationTests.java
+9
-13
ShutdownSampleActuatorApplicationTests.java
...test/actuator/ShutdownSampleActuatorApplicationTests.java
+8
-12
No files found.
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java
View file @
f1ec810c
...
@@ -44,11 +44,9 @@ class EndpointsPropertiesSampleActuatorApplicationTests {
...
@@ -44,11 +44,9 @@ class EndpointsPropertiesSampleActuatorApplicationTests {
@Test
@Test
void
testCustomErrorPath
()
{
void
testCustomErrorPath
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
()).
getForEntity
(
"/oops"
,
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"/oops"
,
Map
.
class
));
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
.
get
(
"error"
)).
isEqualTo
(
"None"
);
assertThat
(
body
.
get
(
"error"
)).
isEqualTo
(
"None"
);
assertThat
(
body
.
get
(
"status"
)).
isEqualTo
(
999
);
assertThat
(
body
.
get
(
"status"
)).
isEqualTo
(
999
);
...
@@ -56,15 +54,16 @@ class EndpointsPropertiesSampleActuatorApplicationTests {
...
@@ -56,15 +54,16 @@ class EndpointsPropertiesSampleActuatorApplicationTests {
@Test
@Test
void
testCustomContextPath
()
{
void
testCustomContextPath
()
{
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
()
)
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
)
.
getForEntity
(
"/admin/health"
,
String
.
class
);
.
getForEntity
(
"/admin/health"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"hello\":\"world\""
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"hello\":\"world\""
);
}
}
private
String
getPassword
()
{
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
return
"password"
;
static
<
K
,
V
>
ResponseEntity
<
Map
<
K
,
V
>>
asMapEntity
(
ResponseEntity
<
Map
>
entity
)
{
return
(
ResponseEntity
)
entity
;
}
}
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementAddressActuatorApplicationTests.java
View file @
f1ec810c
...
@@ -47,21 +47,22 @@ class ManagementAddressActuatorApplicationTests {
...
@@ -47,21 +47,22 @@ class ManagementAddressActuatorApplicationTests {
@Test
@Test
void
testHome
()
{
void
testHome
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
)
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
}
@Test
@Test
void
testHealth
()
{
void
testHealth
()
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
withBasicAuth
(
"user"
,
getPassword
()
)
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
withBasicAuth
(
"user"
,
"password"
)
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/actuator/health"
,
String
.
class
);
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/actuator/health"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
}
}
private
String
getPassword
()
{
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
return
"password"
;
static
<
K
,
V
>
ResponseEntity
<
Map
<
K
,
V
>>
asMapEntity
(
ResponseEntity
<
Map
>
entity
)
{
return
(
ResponseEntity
)
entity
;
}
}
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementDifferentPortSampleActuatorApplicationTests.java
View file @
f1ec810c
...
@@ -41,14 +41,10 @@ class ManagementDifferentPortSampleActuatorApplicationTests {
...
@@ -41,14 +41,10 @@ class ManagementDifferentPortSampleActuatorApplicationTests {
@Test
@Test
void
linksEndpointShouldBeAvailable
()
{
void
linksEndpointShouldBeAvailable
()
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
()
)
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
"password"
)
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/"
,
String
.
class
);
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"_links\""
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"_links\""
);
}
}
private
String
getPassword
()
{
return
"password"
;
}
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java
View file @
f1ec810c
...
@@ -43,7 +43,7 @@ class ManagementPathSampleActuatorApplicationTests {
...
@@ -43,7 +43,7 @@ class ManagementPathSampleActuatorApplicationTests {
@Test
@Test
void
testHealth
()
{
void
testHealth
()
{
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
()
)
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
)
.
getForEntity
(
"/admin/health"
,
String
.
class
);
.
getForEntity
(
"/admin/health"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
...
@@ -51,17 +51,15 @@ class ManagementPathSampleActuatorApplicationTests {
...
@@ -51,17 +51,15 @@ class ManagementPathSampleActuatorApplicationTests {
@Test
@Test
void
testHomeIsSecure
()
{
void
testHomeIsSecure
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
this
.
restTemplate
.
getForEntity
(
"/"
,
Map
.
class
));
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
getForEntity
(
"/"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getBody
().
get
(
"error"
)).
isEqualTo
(
"Unauthorized"
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
.
get
(
"error"
)).
isEqualTo
(
"Unauthorized"
);
assertThat
(
entity
.
getHeaders
()).
doesNotContainKey
(
"Set-Cookie"
);
assertThat
(
entity
.
getHeaders
()).
doesNotContainKey
(
"Set-Cookie"
);
}
}
private
String
getPassword
()
{
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
return
"password"
;
static
<
K
,
V
>
ResponseEntity
<
Map
<
K
,
V
>>
asMapEntity
(
ResponseEntity
<
Map
>
entity
)
{
return
(
ResponseEntity
)
entity
;
}
}
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java
View file @
f1ec810c
...
@@ -52,27 +52,23 @@ class ManagementPortAndPathSampleActuatorApplicationTests {
...
@@ -52,27 +52,23 @@ class ManagementPortAndPathSampleActuatorApplicationTests {
@Test
@Test
void
testHome
()
{
void
testHome
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
new
TestRestTemplate
(
"user"
,
"password"
).
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
));
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getBody
().
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
}
}
@Test
@Test
void
testMetrics
()
{
void
testMetrics
()
{
testHome
();
// makes sure some requests have been made
testHome
();
// makes sure some requests have been made
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
new
TestRestTemplate
()
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/metrics"
,
Map
.
class
));
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/metrics"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
}
@Test
@Test
void
testHealth
()
{
void
testHealth
()
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
withBasicAuth
(
"user"
,
getPassword
()
)
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
withBasicAuth
(
"user"
,
"password"
)
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/health"
,
String
.
class
);
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/health"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
isEqualTo
(
"{\"status\":\"UP\",\"groups\":[\"live\",\"ready\"]}"
);
assertThat
(
entity
.
getBody
()).
isEqualTo
(
"{\"status\":\"UP\",\"groups\":[\"live\",\"ready\"]}"
);
...
@@ -82,14 +78,14 @@ class ManagementPortAndPathSampleActuatorApplicationTests {
...
@@ -82,14 +78,14 @@ class ManagementPortAndPathSampleActuatorApplicationTests {
void
testEnvNotFound
()
{
void
testEnvNotFound
()
{
String
unknownProperty
=
"test-does-not-exist"
;
String
unknownProperty
=
"test-does-not-exist"
;
assertThat
(
this
.
environment
.
containsProperty
(
unknownProperty
)).
isFalse
();
assertThat
(
this
.
environment
.
containsProperty
(
unknownProperty
)).
isFalse
();
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
withBasicAuth
(
"user"
,
getPassword
()
).
getForEntity
(
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/env/"
+
unknownProperty
,
String
.
class
);
"http://localhost:"
+
this
.
managementPort
+
"/admin/env/"
+
unknownProperty
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
}
}
@Test
@Test
void
testMissing
()
{
void
testMissing
()
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
()
)
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
(
"user"
,
"password"
)
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/missing"
,
String
.
class
);
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/admin/missing"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":404"
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":404"
);
...
@@ -97,28 +93,23 @@ class ManagementPortAndPathSampleActuatorApplicationTests {
...
@@ -97,28 +93,23 @@ class ManagementPortAndPathSampleActuatorApplicationTests {
@Test
@Test
void
testErrorPage
()
{
void
testErrorPage
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
new
TestRestTemplate
(
"user"
,
"password"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/error"
,
Map
.
class
));
.
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/error"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getBody
().
get
(
"status"
)).
isEqualTo
(
999
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
.
get
(
"status"
)).
isEqualTo
(
999
);
}
}
@Test
@Test
void
testManagementErrorPage
()
{
void
testManagementErrorPage
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
new
TestRestTemplate
(
"user"
,
"password"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/error"
,
Map
.
class
));
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/error"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getBody
().
get
(
"status"
)).
isEqualTo
(
999
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
.
get
(
"status"
)).
isEqualTo
(
999
);
}
}
private
String
getPassword
()
{
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
return
"password"
;
static
<
K
,
V
>
ResponseEntity
<
Map
<
K
,
V
>>
asMapEntity
(
ResponseEntity
<
Map
>
entity
)
{
return
(
ResponseEntity
)
entity
;
}
}
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortSampleActuatorApplicationTests.java
View file @
f1ec810c
...
@@ -47,27 +47,23 @@ class ManagementPortSampleActuatorApplicationTests {
...
@@ -47,27 +47,23 @@ class ManagementPortSampleActuatorApplicationTests {
@Test
@Test
void
testHome
()
{
void
testHome
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
new
TestRestTemplate
(
"user"
,
"password"
).
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
));
.
getForEntity
(
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getBody
().
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
}
}
@Test
@Test
void
testMetrics
()
{
void
testMetrics
()
{
testHome
();
// makes sure some requests have been made
testHome
();
// makes sure some requests have been made
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
new
TestRestTemplate
()
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
()
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/actuator/metrics"
,
Map
.
class
));
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/actuator/metrics"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
}
@Test
@Test
void
testHealth
()
{
void
testHealth
()
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
withBasicAuth
(
"user"
,
getPassword
()
)
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
withBasicAuth
(
"user"
,
"password"
)
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/actuator/health"
,
String
.
class
);
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/actuator/health"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
...
@@ -77,17 +73,15 @@ class ManagementPortSampleActuatorApplicationTests {
...
@@ -77,17 +73,15 @@ class ManagementPortSampleActuatorApplicationTests {
@Test
@Test
void
testErrorPage
()
{
void
testErrorPage
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
new
TestRestTemplate
(
"user"
,
"password"
)
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
(
"user"
,
getPassword
())
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/error"
,
Map
.
class
));
.
getForEntity
(
"http://localhost:"
+
this
.
managementPort
+
"/error"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getBody
().
get
(
"status"
)).
isEqualTo
(
999
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
.
get
(
"status"
)).
isEqualTo
(
999
);
}
}
private
String
getPassword
()
{
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
return
"password"
;
static
<
K
,
V
>
ResponseEntity
<
Map
<
K
,
V
>>
asMapEntity
(
ResponseEntity
<
Map
>
entity
)
{
return
(
ResponseEntity
)
entity
;
}
}
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/NoManagementSampleActuatorApplicationTests.java
View file @
f1ec810c
...
@@ -42,26 +42,23 @@ class NoManagementSampleActuatorApplicationTests {
...
@@ -42,26 +42,23 @@ class NoManagementSampleActuatorApplicationTests {
@Test
@Test
void
testHome
()
{
void
testHome
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
()).
getForEntity
(
"/"
,
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"/"
,
Map
.
class
));
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getBody
().
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
}
}
@Test
@Test
void
testMetricsNotAvailable
()
{
void
testMetricsNotAvailable
()
{
testHome
();
// makes sure some requests have been made
testHome
();
// makes sure some requests have been made
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
()).
getForEntity
(
"/metrics"
,
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"/metrics"
,
Map
.
class
));
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
}
}
private
String
getPassword
()
{
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
return
"password"
;
static
<
K
,
V
>
ResponseEntity
<
Map
<
K
,
V
>>
asMapEntity
(
ResponseEntity
<
Map
>
entity
)
{
return
(
ResponseEntity
)
entity
;
}
}
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java
View file @
f1ec810c
...
@@ -55,62 +55,51 @@ class SampleActuatorApplicationTests {
...
@@ -55,62 +55,51 @@ class SampleActuatorApplicationTests {
@Test
@Test
void
testHomeIsSecure
()
{
void
testHomeIsSecure
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
this
.
restTemplate
.
getForEntity
(
"/"
,
Map
.
class
));
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
getForEntity
(
"/"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getBody
().
get
(
"error"
)).
isEqualTo
(
"Unauthorized"
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
.
get
(
"error"
)).
isEqualTo
(
"Unauthorized"
);
assertThat
(
entity
.
getHeaders
()).
doesNotContainKey
(
"Set-Cookie"
);
assertThat
(
entity
.
getHeaders
()).
doesNotContainKey
(
"Set-Cookie"
);
}
}
@Test
@Test
void
testMetricsIsSecure
()
{
void
testMetricsIsSecure
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
getForEntity
(
"/actuator/metrics"
,
Map
.
class
);
this
.
restTemplate
.
getForEntity
(
"/actuator/metrics"
,
Map
.
class
)
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
entity
=
this
.
restTemplate
.
getForEntity
(
"/actuator/metrics/"
,
Map
.
class
);
entity
=
asMapEntity
(
this
.
restTemplate
.
getForEntity
(
"/actuator/metrics/"
,
Map
.
class
)
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
entity
=
this
.
restTemplate
.
getForEntity
(
"/actuator/metrics/foo"
,
Map
.
class
);
entity
=
asMapEntity
(
this
.
restTemplate
.
getForEntity
(
"/actuator/metrics/foo"
,
Map
.
class
)
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
entity
=
this
.
restTemplate
.
getForEntity
(
"/actuator/metrics.json"
,
Map
.
class
);
entity
=
asMapEntity
(
this
.
restTemplate
.
getForEntity
(
"/actuator/metrics.json"
,
Map
.
class
)
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
}
}
@Test
@Test
void
testHome
()
{
void
testHome
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
()).
getForEntity
(
"/"
,
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"/"
,
Map
.
class
));
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getBody
().
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
}
}
@SuppressWarnings
(
"unchecked"
)
@Test
@Test
@SuppressWarnings
(
"unchecked"
)
void
testMetrics
()
{
void
testMetrics
()
{
testHome
();
// makes sure some requests have been made
testHome
();
// makes sure some requests have been made
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
())
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"/actuator/metrics"
,
Map
.
class
));
.
getForEntity
(
"/actuator/metrics"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
entity
.
getBody
()).
containsKey
(
"names"
);
assertThat
(
body
).
containsKey
(
"names"
);
List
<
String
>
names
=
(
List
<
String
>)
entity
.
getBody
().
get
(
"names"
);
assertThat
((
List
<
String
>)
body
.
get
(
"names"
)).
contains
(
"jvm.buffer.count"
);
assertThat
(
names
).
contains
(
"jvm.buffer.count"
);
}
}
@Test
@Test
void
testEnv
()
{
void
testEnv
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
())
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"/actuator/env"
,
Map
.
class
));
.
getForEntity
(
"/actuator/env"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getBody
()).
containsKey
(
"propertySources"
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
).
containsKey
(
"propertySources"
);
}
}
@Test
@Test
...
@@ -133,7 +122,7 @@ class SampleActuatorApplicationTests {
...
@@ -133,7 +122,7 @@ class SampleActuatorApplicationTests {
@Test
@Test
void
testErrorPage
()
{
void
testErrorPage
()
{
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
()
).
getForEntity
(
"/foo"
,
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"/foo"
,
String
.
class
);
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
String
body
=
entity
.
getBody
();
String
body
=
entity
.
getBody
();
...
@@ -145,7 +134,7 @@ class SampleActuatorApplicationTests {
...
@@ -145,7 +134,7 @@ class SampleActuatorApplicationTests {
HttpHeaders
headers
=
new
HttpHeaders
();
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setAccept
(
Arrays
.
asList
(
MediaType
.
TEXT_HTML
));
headers
.
setAccept
(
Arrays
.
asList
(
MediaType
.
TEXT_HTML
));
HttpEntity
<?>
request
=
new
HttpEntity
<
Void
>(
headers
);
HttpEntity
<?>
request
=
new
HttpEntity
<
Void
>(
headers
);
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
()
).
exchange
(
"/foo"
,
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
exchange
(
"/foo"
,
HttpMethod
.
GET
,
request
,
String
.
class
);
HttpMethod
.
GET
,
request
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
String
body
=
entity
.
getBody
();
String
body
=
entity
.
getBody
();
...
@@ -155,32 +144,26 @@ class SampleActuatorApplicationTests {
...
@@ -155,32 +144,26 @@ class SampleActuatorApplicationTests {
@Test
@Test
void
testErrorPageDirectAccess
()
{
void
testErrorPageDirectAccess
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
()).
getForEntity
(
"/error"
,
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"/error"
,
Map
.
class
));
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getBody
().
get
(
"error"
)).
isEqualTo
(
"None"
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
entity
.
getBody
().
get
(
"status"
)).
isEqualTo
(
999
);
assertThat
(
body
.
get
(
"error"
)).
isEqualTo
(
"None"
);
assertThat
(
body
.
get
(
"status"
)).
isEqualTo
(
999
);
}
}
@Test
@Test
@SuppressWarnings
(
"unchecked"
)
void
testBeans
()
{
void
testBeans
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
())
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"/actuator/beans"
,
Map
.
class
));
.
getForEntity
(
"/actuator/beans"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
containsOnlyKeys
(
"contexts"
);
assertThat
(
entity
.
getBody
()).
containsOnlyKeys
(
"contexts"
);
}
}
@SuppressWarnings
(
"unchecked"
)
@Test
@Test
@SuppressWarnings
(
"unchecked"
)
void
testConfigProps
()
{
void
testConfigProps
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
())
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"/actuator/configprops"
,
Map
.
class
));
.
getForEntity
(
"/actuator/configprops"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
Map
<
String
,
Object
>
contexts
=
(
Map
<
String
,
Object
>)
body
.
get
(
"contexts"
);
Map
<
String
,
Object
>
contexts
=
(
Map
<
String
,
Object
>)
body
.
get
(
"contexts"
);
...
@@ -191,17 +174,15 @@ class SampleActuatorApplicationTests {
...
@@ -191,17 +174,15 @@ class SampleActuatorApplicationTests {
@Test
@Test
void
testLegacy
()
{
void
testLegacy
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
())
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"/actuator/legacy"
,
Map
.
class
));
.
getForEntity
(
"/actuator/legacy"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getBody
()).
contains
(
entry
(
"legacy"
,
"legacy"
));
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
).
contains
(
entry
(
"legacy"
,
"legacy"
));
}
}
private
String
getPassword
()
{
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
return
"password"
;
static
<
K
,
V
>
ResponseEntity
<
Map
<
K
,
V
>>
asMapEntity
(
ResponseEntity
<
Map
>
entity
)
{
return
(
ResponseEntity
)
entity
;
}
}
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ServletPathSampleActuatorApplicationTests.java
View file @
f1ec810c
...
@@ -42,19 +42,16 @@ class ServletPathSampleActuatorApplicationTests {
...
@@ -42,19 +42,16 @@ class ServletPathSampleActuatorApplicationTests {
@Test
@Test
void
testErrorPath
()
{
void
testErrorPath
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
())
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"/spring/error"
,
Map
.
class
));
.
getForEntity
(
"/spring/error"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(
entity
.
getBody
().
get
(
"error"
)).
isEqualTo
(
"None"
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
entity
.
getBody
().
get
(
"status"
)).
isEqualTo
(
999
);
assertThat
(
body
.
get
(
"error"
)).
isEqualTo
(
"None"
);
assertThat
(
body
.
get
(
"status"
)).
isEqualTo
(
999
);
}
}
@Test
@Test
void
testHealth
()
{
void
testHealth
()
{
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
()
)
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
)
.
getForEntity
(
"/spring/actuator/health"
,
String
.
class
);
.
getForEntity
(
"/spring/actuator/health"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
assertThat
(
entity
.
getBody
()).
contains
(
"\"status\":\"UP\""
);
...
@@ -62,17 +59,16 @@ class ServletPathSampleActuatorApplicationTests {
...
@@ -62,17 +59,16 @@ class ServletPathSampleActuatorApplicationTests {
@Test
@Test
void
testHomeIsSecure
()
{
void
testHomeIsSecure
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
this
.
restTemplate
.
getForEntity
(
"/spring/"
,
Map
.
class
));
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
getForEntity
(
"/spring/"
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
UNAUTHORIZED
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
.
get
(
"error"
)).
isEqualTo
(
"Unauthorized"
);
assertThat
(
body
.
get
(
"error"
)).
isEqualTo
(
"Unauthorized"
);
assertThat
(
entity
.
getHeaders
()).
doesNotContainKey
(
"Set-Cookie"
);
assertThat
(
entity
.
getHeaders
()).
doesNotContainKey
(
"Set-Cookie"
);
}
}
private
String
getPassword
()
{
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
return
"password"
;
static
<
K
,
V
>
ResponseEntity
<
Map
<
K
,
V
>>
asMapEntity
(
ResponseEntity
<
Map
>
entity
)
{
return
(
ResponseEntity
)
entity
;
}
}
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ShutdownSampleActuatorApplicationTests.java
View file @
f1ec810c
...
@@ -47,11 +47,9 @@ class ShutdownSampleActuatorApplicationTests {
...
@@ -47,11 +47,9 @@ class ShutdownSampleActuatorApplicationTests {
@Test
@Test
void
testHome
()
{
void
testHome
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
()).
getForEntity
(
"/"
,
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
).
getForEntity
(
"/"
,
Map
.
class
));
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
assertThat
(
body
.
get
(
"message"
)).
isEqualTo
(
"Hello Phil"
);
}
}
...
@@ -59,17 +57,15 @@ class ShutdownSampleActuatorApplicationTests {
...
@@ -59,17 +57,15 @@ class ShutdownSampleActuatorApplicationTests {
@Test
@Test
@DirtiesContext
@DirtiesContext
void
testShutdown
()
{
void
testShutdown
()
{
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
<
String
,
Object
>>
entity
=
asMapEntity
(
this
.
restTemplate
.
withBasicAuth
(
"user"
,
"password"
)
ResponseEntity
<
Map
>
entity
=
this
.
restTemplate
.
withBasicAuth
(
"user"
,
getPassword
())
.
postForEntity
(
"/actuator/shutdown"
,
null
,
Map
.
class
));
.
postForEntity
(
"/actuator/shutdown"
,
null
,
Map
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
@SuppressWarnings
(
"unchecked"
)
assertThat
(((
String
)
entity
.
getBody
().
get
(
"message"
))).
contains
(
"Shutting down"
);
Map
<
String
,
Object
>
body
=
entity
.
getBody
();
assertThat
(((
String
)
body
.
get
(
"message"
))).
contains
(
"Shutting down"
);
}
}
private
String
getPassword
()
{
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
return
"password"
;
static
<
K
,
V
>
ResponseEntity
<
Map
<
K
,
V
>>
asMapEntity
(
ResponseEntity
<
Map
>
entity
)
{
return
(
ResponseEntity
)
entity
;
}
}
@Configuration
(
proxyBeanMethods
=
false
)
@Configuration
(
proxyBeanMethods
=
false
)
...
...
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