2222import java .util .Collections ;
2323import java .util .Map ;
2424import java .util .function .Consumer ;
25- import java .util .function .Function ;
2625
2726import jakarta .validation .Valid ;
2827import jakarta .validation .constraints .NotEmpty ;
2928import org .assertj .core .api .InstanceOfAssertFactories ;
3029import org .junit .jupiter .api .Test ;
3130import org .junit .jupiter .api .io .TempDir ;
32- import reactor .core .publisher .Mono ;
3331
3432import org .springframework .boot .actuate .autoconfigure .endpoint .EndpointAutoConfiguration ;
3533import org .springframework .boot .actuate .autoconfigure .endpoint .web .WebEndpointAutoConfiguration ;
5654import org .springframework .web .bind .annotation .PostMapping ;
5755import org .springframework .web .bind .annotation .RequestBody ;
5856import 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 ;
6159
6260import static org .assertj .core .api .Assertions .assertThat ;
6361
@@ -86,12 +84,11 @@ class WebMvcEndpointChildContextConfigurationIntegrationTests {
8684
8785 @ Test // gh-17938
8886 void errorEndpointIsUsedWithEndpoint () {
89- this .runner .run (withWebTestClient ((client ) -> {
87+ this .runner .run (withRestClient ((client ) -> {
9088 Map <String , ?> body = client .get ()
9189 .uri ("actuator/fail" )
9290 .accept (MediaType .APPLICATION_JSON )
93- .exchangeToMono (toResponseBody ())
94- .block ();
91+ .exchange (toResponseBody ());
9592 assertThat (body ).hasEntrySatisfying ("exception" ,
9693 (value ) -> assertThat (value ).asString ().contains ("IllegalStateException" ));
9794 assertThat (body ).hasEntrySatisfying ("message" ,
@@ -102,12 +99,11 @@ void errorEndpointIsUsedWithEndpoint() {
10299 @ Test
103100 void errorPageAndErrorControllerIncludeDetails () {
104101 this .runner .withPropertyValues ("server.error.include-stacktrace=always" , "server.error.include-message=always" )
105- .run (withWebTestClient ((client ) -> {
102+ .run (withRestClient ((client ) -> {
106103 Map <String , ?> body = client .get ()
107104 .uri ("actuator/fail" )
108105 .accept (MediaType .APPLICATION_JSON )
109- .exchangeToMono (toResponseBody ())
110- .block ();
106+ .exchange (toResponseBody ());
111107 assertThat (body ).hasEntrySatisfying ("message" ,
112108 (value ) -> assertThat (value ).asString ().contains ("Epic Fail" ));
113109 assertThat (body ).hasEntrySatisfying ("trace" ,
@@ -117,12 +113,11 @@ void errorPageAndErrorControllerIncludeDetails() {
117113
118114 @ Test
119115 void errorEndpointIsUsedWithRestControllerEndpoint () {
120- this .runner .run (withWebTestClient ((client ) -> {
116+ this .runner .run (withRestClient ((client ) -> {
121117 Map <String , ?> body = client .get ()
122118 .uri ("actuator/failController" )
123119 .accept (MediaType .APPLICATION_JSON )
124- .exchangeToMono (toResponseBody ())
125- .block ();
120+ .exchange (toResponseBody ());
126121 assertThat (body ).hasEntrySatisfying ("exception" ,
127122 (value ) -> assertThat (value ).asString ().contains ("IllegalStateException" ));
128123 assertThat (body ).hasEntrySatisfying ("message" ,
@@ -132,13 +127,12 @@ void errorEndpointIsUsedWithRestControllerEndpoint() {
132127
133128 @ Test
134129 void errorEndpointIsUsedWithRestControllerEndpointOnBindingError () {
135- this .runner .run (withWebTestClient ((client ) -> {
130+ this .runner .run (withRestClient ((client ) -> {
136131 Map <String , ?> body = client .post ()
137132 .uri ("actuator/failController" )
138- .bodyValue (Collections .singletonMap ("content" , "" ))
133+ .body (Collections .singletonMap ("content" , "" ))
139134 .accept (MediaType .APPLICATION_JSON )
140- .exchangeToMono (toResponseBody ())
141- .block ();
135+ .exchange (toResponseBody ());
142136 assertThat (body ).hasEntrySatisfying ("exception" ,
143137 (value ) -> assertThat (value ).asString ().contains ("MethodArgumentNotValidException" ));
144138 assertThat (body ).hasEntrySatisfying ("message" ,
@@ -150,12 +144,12 @@ void errorEndpointIsUsedWithRestControllerEndpointOnBindingError() {
150144
151145 @ Test
152146 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 ) -> {
154148 String body = client .get ()
155149 .uri ("manage/actuator/success" )
156150 .accept (MediaType .APPLICATION_JSON )
157- .exchangeToMono (( response ) -> response . bodyToMono ( String . class ) )
158- .block ( );
151+ .retrieve ( )
152+ .body ( String . class );
159153 assertThat (body ).isEqualTo ("Success" );
160154 }));
161155 }
@@ -182,16 +176,16 @@ private void addConfigTreePropertySource(ConfigurableApplicationContext applicat
182176 }
183177 }
184178
185- private ContextConsumer <AssertableWebApplicationContext > withWebTestClient (Consumer <WebClient > webClient ) {
179+ private ContextConsumer <AssertableWebApplicationContext > withRestClient (Consumer <RestClient > restClient ) {
186180 return (context ) -> {
187181 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 );
190184 };
191185 }
192186
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 , ?>>() {
195189 }));
196190 }
197191
0 commit comments