|
20 | 20 | import java.util.List;
|
21 | 21 |
|
22 | 22 | import org.junit.jupiter.api.Test;
|
| 23 | +import org.junit.jupiter.api.condition.EnabledForJreRange; |
| 24 | +import org.junit.jupiter.api.condition.JRE; |
23 | 25 |
|
24 | 26 | import org.springframework.boot.autoconfigure.AutoConfigurations;
|
25 | 27 | import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
26 | 28 | import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
27 | 29 | import org.springframework.boot.autoconfigure.http.client.HttpClientAutoConfiguration;
|
| 30 | +import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration; |
28 | 31 | import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder;
|
29 | 32 | import org.springframework.boot.http.client.ClientHttpRequestFactorySettings;
|
30 | 33 | import org.springframework.boot.http.client.ClientHttpRequestFactorySettings.Redirects;
|
31 | 34 | import org.springframework.boot.ssl.SslBundle;
|
32 | 35 | import org.springframework.boot.ssl.SslBundles;
|
33 | 36 | import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
| 37 | +import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; |
| 38 | +import org.springframework.boot.test.context.runner.WebApplicationContextRunner; |
34 | 39 | import org.springframework.boot.web.client.RestClientCustomizer;
|
35 | 40 | import org.springframework.boot.web.codec.CodecCustomizer;
|
36 | 41 | import org.springframework.context.annotation.Bean;
|
|
53 | 58 | * @author Arjen Poutsma
|
54 | 59 | * @author Moritz Halbritter
|
55 | 60 | * @author Dmytro Nosan
|
| 61 | + * @author Dmitry Sulman |
56 | 62 | */
|
57 | 63 | class RestClientAutoConfigurationTests {
|
58 | 64 |
|
@@ -260,6 +266,57 @@ void shouldSupplyRestClientBuilderConfigurerWithAutoConfiguredHttpSettings() {
|
260 | 266 | });
|
261 | 267 | }
|
262 | 268 |
|
| 269 | + @Test |
| 270 | + void whenReactiveWebApplicationRestClientIsNotConfigured() { |
| 271 | + new ReactiveWebApplicationContextRunner() |
| 272 | + .withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class)) |
| 273 | + .run((context) -> { |
| 274 | + assertThat(context).doesNotHaveBean(HttpMessageConvertersRestClientCustomizer.class); |
| 275 | + assertThat(context).doesNotHaveBean(RestClientBuilderConfigurer.class); |
| 276 | + assertThat(context).doesNotHaveBean(RestClient.Builder.class); |
| 277 | + }); |
| 278 | + } |
| 279 | + |
| 280 | + @Test |
| 281 | + void whenServletWebApplicationRestClientIsConfigured() { |
| 282 | + new WebApplicationContextRunner().withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class)) |
| 283 | + .run((context) -> { |
| 284 | + assertThat(context).hasSingleBean(HttpMessageConvertersRestClientCustomizer.class); |
| 285 | + assertThat(context).hasSingleBean(RestClientBuilderConfigurer.class); |
| 286 | + assertThat(context).hasSingleBean(RestClient.Builder.class); |
| 287 | + }); |
| 288 | + } |
| 289 | + |
| 290 | + @Test |
| 291 | + @EnabledForJreRange(min = JRE.JAVA_21) |
| 292 | + void whenReactiveWebApplicationAndVirtualThreadsEnabledAndTaskExecutorBean() { |
| 293 | + new ReactiveWebApplicationContextRunner().withPropertyValues("spring.threads.virtual.enabled=true") |
| 294 | + .withConfiguration( |
| 295 | + AutoConfigurations.of(RestClientAutoConfiguration.class, TaskExecutionAutoConfiguration.class)) |
| 296 | + .run((context) -> { |
| 297 | + assertThat(context).hasSingleBean(HttpMessageConvertersRestClientCustomizer.class); |
| 298 | + assertThat(context).hasSingleBean(RestClientBuilderConfigurer.class); |
| 299 | + assertThat(context).hasSingleBean(RestClient.Builder.class); |
| 300 | + }); |
| 301 | + } |
| 302 | + |
| 303 | + @Test |
| 304 | + @EnabledForJreRange(min = JRE.JAVA_21) |
| 305 | + void whenReactiveWebApplicationAndVirtualThreadsDisabled() { |
| 306 | + new ReactiveWebApplicationContextRunner().withPropertyValues("spring.threads.virtual.enabled=false") |
| 307 | + .withConfiguration( |
| 308 | + AutoConfigurations.of(RestClientAutoConfiguration.class, TaskExecutionAutoConfiguration.class)) |
| 309 | + .run((context) -> assertThat(context).doesNotHaveBean(RestClient.Builder.class)); |
| 310 | + } |
| 311 | + |
| 312 | + @Test |
| 313 | + @EnabledForJreRange(min = JRE.JAVA_21) |
| 314 | + void whenReactiveWebApplicationAndVirtualThreadsEnabledAndNoTaskExecutorBean() { |
| 315 | + new ReactiveWebApplicationContextRunner().withPropertyValues("spring.threads.virtual.enabled=true") |
| 316 | + .withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class)) |
| 317 | + .run((context) -> assertThat(context).doesNotHaveBean(RestClient.Builder.class)); |
| 318 | + } |
| 319 | + |
263 | 320 | @Configuration(proxyBeanMethods = false)
|
264 | 321 | static class CodecConfiguration {
|
265 | 322 |
|
|
0 commit comments