Merge branch '4.0.x'

Closes gh-49345
This commit is contained in:
Andy Wilkinson
2026-02-27 12:13:30 +00:00
2 changed files with 93 additions and 0 deletions
@@ -26,12 +26,14 @@ import java.time.Duration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.test.context.PropertyMapping;
import org.springframework.boot.test.context.PropertyMapping.Skip;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* Annotation that can be applied to a test class to enable a {@link WebTestClient}.
*
* @author Stephane Nicoll
* @author Jay Choi
* @since 4.0.0
* @see WebTestClientAutoConfiguration
*/
@@ -48,6 +50,7 @@ public @interface AutoConfigureWebTestClient {
* {@link Duration#parse(CharSequence)}).
* @return the web client timeout
*/
@PropertyMapping(skip = Skip.ON_DEFAULT_VALUE)
String timeout() default "";
}
@@ -0,0 +1,90 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.webtestclient.autoconfigure;
import java.time.Duration;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.config.EnableWebFlux;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link SpringBootTest @SpringBootTest} with
* {@link AutoConfigureWebTestClient @AutoConfigureWebTestClient} timeout property
* binding.
*
* @author Jay Choi
* @author Andy Wilkinson
*/
@SpringBootTest(properties = { "spring.main.web-application-type=reactive" },
classes = ExampleWebTestClientApplication.class)
class WebTestClientTimeoutSpringBootTestIntegrationTests {
@Nested
@EnableWebFlux
@AutoConfigureWebTestClient
@TestPropertySource(properties = "spring.test.webtestclient.timeout=30s")
class TimeoutFromProperty {
@Autowired
private WebTestClient webClient;
@Test
void timeoutIsApplied() {
assertThat(this.webClient).hasFieldOrPropertyWithValue("responseTimeout", Duration.ofSeconds(30));
}
}
@Nested
@EnableWebFlux
@AutoConfigureWebTestClient(timeout = "25s")
class TimeoutFromAnnotation {
@Autowired
private WebTestClient webClient;
@Test
void timeoutIsApplied() {
assertThat(this.webClient).hasFieldOrPropertyWithValue("responseTimeout", Duration.ofSeconds(25));
}
}
@Nested
@EnableWebFlux
@AutoConfigureWebTestClient
class DefaultTimeout {
@Autowired
private WebTestClient webClient;
@Test
void timeoutIsApplied() {
assertThat(this.webClient).hasFieldOrPropertyWithValue("responseTimeout", Duration.ofSeconds(5));
}
}
}