22
22
import java .util .Collections ;
23
23
import java .util .Map ;
24
24
import java .util .function .Consumer ;
25
- import java .util .function .Function ;
26
25
27
26
import jakarta .validation .Valid ;
28
27
import jakarta .validation .constraints .NotEmpty ;
29
28
import org .assertj .core .api .InstanceOfAssertFactories ;
30
29
import org .junit .jupiter .api .Test ;
31
30
import org .junit .jupiter .api .io .TempDir ;
32
- import reactor .core .publisher .Mono ;
33
31
34
32
import org .springframework .boot .actuate .autoconfigure .endpoint .EndpointAutoConfiguration ;
35
33
import org .springframework .boot .actuate .autoconfigure .endpoint .web .WebEndpointAutoConfiguration ;
56
54
import org .springframework .web .bind .annotation .PostMapping ;
57
55
import org .springframework .web .bind .annotation .RequestBody ;
58
56
import org .springframework .web .bind .annotation .ResponseBody ;
59
- import org .springframework .web .reactive . function . client .ClientResponse ;
60
- import org .springframework .web .reactive . function . client . WebClient ;
57
+ import org .springframework .web .client .RestClient ;
58
+ import org .springframework .web .client . RestClient . RequestHeadersSpec . ExchangeFunction ;
61
59
62
60
import static org .assertj .core .api .Assertions .assertThat ;
63
61
@@ -86,12 +84,11 @@ class WebMvcEndpointChildContextConfigurationIntegrationTests {
86
84
87
85
@ Test // gh-17938
88
86
void errorEndpointIsUsedWithEndpoint () {
89
- this .runner .run (withWebTestClient ((client ) -> {
87
+ this .runner .run (withRestClient ((client ) -> {
90
88
Map <String , ?> body = client .get ()
91
89
.uri ("actuator/fail" )
92
90
.accept (MediaType .APPLICATION_JSON )
93
- .exchangeToMono (toResponseBody ())
94
- .block ();
91
+ .exchange (toResponseBody ());
95
92
assertThat (body ).hasEntrySatisfying ("exception" ,
96
93
(value ) -> assertThat (value ).asString ().contains ("IllegalStateException" ));
97
94
assertThat (body ).hasEntrySatisfying ("message" ,
@@ -102,12 +99,11 @@ void errorEndpointIsUsedWithEndpoint() {
102
99
@ Test
103
100
void errorPageAndErrorControllerIncludeDetails () {
104
101
this .runner .withPropertyValues ("server.error.include-stacktrace=always" , "server.error.include-message=always" )
105
- .run (withWebTestClient ((client ) -> {
102
+ .run (withRestClient ((client ) -> {
106
103
Map <String , ?> body = client .get ()
107
104
.uri ("actuator/fail" )
108
105
.accept (MediaType .APPLICATION_JSON )
109
- .exchangeToMono (toResponseBody ())
110
- .block ();
106
+ .exchange (toResponseBody ());
111
107
assertThat (body ).hasEntrySatisfying ("message" ,
112
108
(value ) -> assertThat (value ).asString ().contains ("Epic Fail" ));
113
109
assertThat (body ).hasEntrySatisfying ("trace" ,
@@ -117,12 +113,11 @@ void errorPageAndErrorControllerIncludeDetails() {
117
113
118
114
@ Test
119
115
void errorEndpointIsUsedWithRestControllerEndpoint () {
120
- this .runner .run (withWebTestClient ((client ) -> {
116
+ this .runner .run (withRestClient ((client ) -> {
121
117
Map <String , ?> body = client .get ()
122
118
.uri ("actuator/failController" )
123
119
.accept (MediaType .APPLICATION_JSON )
124
- .exchangeToMono (toResponseBody ())
125
- .block ();
120
+ .exchange (toResponseBody ());
126
121
assertThat (body ).hasEntrySatisfying ("exception" ,
127
122
(value ) -> assertThat (value ).asString ().contains ("IllegalStateException" ));
128
123
assertThat (body ).hasEntrySatisfying ("message" ,
@@ -132,13 +127,12 @@ void errorEndpointIsUsedWithRestControllerEndpoint() {
132
127
133
128
@ Test
134
129
void errorEndpointIsUsedWithRestControllerEndpointOnBindingError () {
135
- this .runner .run (withWebTestClient ((client ) -> {
130
+ this .runner .run (withRestClient ((client ) -> {
136
131
Map <String , ?> body = client .post ()
137
132
.uri ("actuator/failController" )
138
- .bodyValue (Collections .singletonMap ("content" , "" ))
133
+ .body (Collections .singletonMap ("content" , "" ))
139
134
.accept (MediaType .APPLICATION_JSON )
140
- .exchangeToMono (toResponseBody ())
141
- .block ();
135
+ .exchange (toResponseBody ());
142
136
assertThat (body ).hasEntrySatisfying ("exception" ,
143
137
(value ) -> assertThat (value ).asString ().contains ("MethodArgumentNotValidException" ));
144
138
assertThat (body ).hasEntrySatisfying ("message" ,
@@ -150,12 +144,12 @@ void errorEndpointIsUsedWithRestControllerEndpointOnBindingError() {
150
144
151
145
@ Test
152
146
void whenManagementServerBasePathIsConfiguredThenEndpointsAreBeneathThatPath () {
153
- this .runner .withPropertyValues ("management.server.base-path:/manage" ).run (withWebTestClient ((client ) -> {
147
+ this .runner .withPropertyValues ("management.server.base-path:/manage" ).run (withRestClient ((client ) -> {
154
148
String body = client .get ()
155
149
.uri ("manage/actuator/success" )
156
150
.accept (MediaType .APPLICATION_JSON )
157
- .exchangeToMono (( response ) -> response . bodyToMono ( String . class ) )
158
- .block ( );
151
+ .retrieve ( )
152
+ .body ( String . class );
159
153
assertThat (body ).isEqualTo ("Success" );
160
154
}));
161
155
}
@@ -182,16 +176,16 @@ private void addConfigTreePropertySource(ConfigurableApplicationContext applicat
182
176
}
183
177
}
184
178
185
- private ContextConsumer <AssertableWebApplicationContext > withWebTestClient (Consumer <WebClient > webClient ) {
179
+ private ContextConsumer <AssertableWebApplicationContext > withRestClient (Consumer <RestClient > restClient ) {
186
180
return (context ) -> {
187
181
String port = context .getEnvironment ().getProperty ("local.management.port" );
188
- WebClient client = WebClient .create ("http://localhost:" + port );
189
- webClient .accept (client );
182
+ RestClient client = RestClient .create ("http://localhost:" + port );
183
+ restClient .accept (client );
190
184
};
191
185
}
192
186
193
- private Function < ClientResponse , ? extends Mono < Map <String , ?> >> toResponseBody () {
194
- return ((clientResponse ) -> clientResponse . bodyToMono (new ParameterizedTypeReference <Map <String , ?>>() {
187
+ private ExchangeFunction < Map <String , ?>> toResponseBody () {
188
+ return ((request , response ) -> response . bodyTo (new ParameterizedTypeReference <Map <String , ?>>() {
195
189
}));
196
190
}
197
191
0 commit comments