|
1 | 1 | /* |
2 | | - * Copyright 2012-2024 the original author or authors. |
| 2 | + * Copyright 2012-2025 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
19 | 19 | import java.util.List; |
20 | 20 |
|
21 | 21 | import org.junit.jupiter.api.Test; |
| 22 | +import org.junit.jupiter.api.condition.EnabledForJreRange; |
| 23 | +import org.junit.jupiter.api.condition.JRE; |
22 | 24 |
|
23 | 25 | import org.springframework.boot.autoconfigure.AutoConfigurations; |
24 | 26 | import org.springframework.boot.autoconfigure.http.HttpMessageConverters; |
25 | 27 | import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration; |
26 | 28 | import org.springframework.boot.autoconfigure.http.client.HttpClientAutoConfiguration; |
27 | 29 | import org.springframework.boot.ssl.SslBundles; |
28 | 30 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
| 31 | +import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; |
| 32 | +import org.springframework.boot.test.context.runner.WebApplicationContextRunner; |
29 | 33 | import org.springframework.boot.web.client.RestClientCustomizer; |
30 | 34 | import org.springframework.boot.web.codec.CodecCustomizer; |
31 | 35 | import org.springframework.context.annotation.Bean; |
@@ -171,6 +175,39 @@ void whenHasFactoryProperty() { |
171 | 175 | }); |
172 | 176 | } |
173 | 177 |
|
| 178 | + @Test |
| 179 | + void whenReactiveWebApplicationRestClientIsNotConfigured() { |
| 180 | + new ReactiveWebApplicationContextRunner() |
| 181 | + .withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class)) |
| 182 | + .run((context) -> { |
| 183 | + assertThat(context).doesNotHaveBean(HttpMessageConvertersRestClientCustomizer.class); |
| 184 | + assertThat(context).doesNotHaveBean(RestClientBuilderConfigurer.class); |
| 185 | + assertThat(context).doesNotHaveBean(RestClient.Builder.class); |
| 186 | + }); |
| 187 | + } |
| 188 | + |
| 189 | + @Test |
| 190 | + void whenServletWebApplicationRestClientIsConfigured() { |
| 191 | + new WebApplicationContextRunner().withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class)) |
| 192 | + .run((context) -> { |
| 193 | + assertThat(context).hasSingleBean(HttpMessageConvertersRestClientCustomizer.class); |
| 194 | + assertThat(context).hasSingleBean(RestClientBuilderConfigurer.class); |
| 195 | + assertThat(context).hasSingleBean(RestClient.Builder.class); |
| 196 | + }); |
| 197 | + } |
| 198 | + |
| 199 | + @Test |
| 200 | + @EnabledForJreRange(min = JRE.JAVA_21) |
| 201 | + void whenReactiveWebApplicationAndVirtualThreadsAreEnabledOnJava21AndLaterRestClientIsConfigured() { |
| 202 | + new ReactiveWebApplicationContextRunner().withPropertyValues("spring.threads.virtual.enabled=true") |
| 203 | + .withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class)) |
| 204 | + .run((context) -> { |
| 205 | + assertThat(context).hasSingleBean(HttpMessageConvertersRestClientCustomizer.class); |
| 206 | + assertThat(context).hasSingleBean(RestClientBuilderConfigurer.class); |
| 207 | + assertThat(context).hasSingleBean(RestClient.Builder.class); |
| 208 | + }); |
| 209 | + } |
| 210 | + |
174 | 211 | @Configuration(proxyBeanMethods = false) |
175 | 212 | static class CodecConfiguration { |
176 | 213 |
|
|
0 commit comments