Skip to content

Commit 2390392

Browse files
committed
Merge branch '3.5.x' into 4.0.x
Closes gh-49344
2 parents 7f7532a + 3754efb commit 2390392

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

module/spring-boot-webtestclient/src/main/java/org/springframework/boot/webtestclient/autoconfigure/AutoConfigureWebTestClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626

2727
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
2828
import org.springframework.boot.test.context.PropertyMapping;
29+
import org.springframework.boot.test.context.PropertyMapping.Skip;
2930
import org.springframework.test.web.reactive.server.WebTestClient;
3031

3132
/**
3233
* Annotation that can be applied to a test class to enable a {@link WebTestClient}.
3334
*
3435
* @author Stephane Nicoll
36+
* @author Jay Choi
3537
* @since 4.0.0
3638
* @see WebTestClientAutoConfiguration
3739
*/
@@ -48,6 +50,7 @@
4850
* {@link Duration#parse(CharSequence)}).
4951
* @return the web client timeout
5052
*/
53+
@PropertyMapping(skip = Skip.ON_DEFAULT_VALUE)
5154
String timeout() default "";
5255

5356
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.webtestclient.autoconfigure;
18+
19+
import java.time.Duration;
20+
21+
import org.junit.jupiter.api.Nested;
22+
import org.junit.jupiter.api.Test;
23+
24+
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.boot.test.context.SpringBootTest;
26+
import org.springframework.test.context.TestPropertySource;
27+
import org.springframework.test.web.reactive.server.WebTestClient;
28+
import org.springframework.web.reactive.config.EnableWebFlux;
29+
30+
import static org.assertj.core.api.Assertions.assertThat;
31+
32+
/**
33+
* Tests for {@link SpringBootTest @SpringBootTest} with
34+
* {@link AutoConfigureWebTestClient @AutoConfigureWebTestClient} timeout property
35+
* binding.
36+
*
37+
* @author Jay Choi
38+
* @author Andy Wilkinson
39+
*/
40+
@SpringBootTest(properties = { "spring.main.web-application-type=reactive" },
41+
classes = ExampleWebTestClientApplication.class)
42+
class WebTestClientTimeoutSpringBootTestIntegrationTests {
43+
44+
@Nested
45+
@EnableWebFlux
46+
@AutoConfigureWebTestClient
47+
@TestPropertySource(properties = "spring.test.webtestclient.timeout=30s")
48+
class TimeoutFromProperty {
49+
50+
@Autowired
51+
private WebTestClient webClient;
52+
53+
@Test
54+
void timeoutIsApplied() {
55+
assertThat(this.webClient).hasFieldOrPropertyWithValue("responseTimeout", Duration.ofSeconds(30));
56+
}
57+
58+
}
59+
60+
@Nested
61+
@EnableWebFlux
62+
@AutoConfigureWebTestClient(timeout = "25s")
63+
class TimeoutFromAnnotation {
64+
65+
@Autowired
66+
private WebTestClient webClient;
67+
68+
@Test
69+
void timeoutIsApplied() {
70+
assertThat(this.webClient).hasFieldOrPropertyWithValue("responseTimeout", Duration.ofSeconds(25));
71+
}
72+
73+
}
74+
75+
@Nested
76+
@EnableWebFlux
77+
@AutoConfigureWebTestClient
78+
class DefaultTimeout {
79+
80+
@Autowired
81+
private WebTestClient webClient;
82+
83+
@Test
84+
void timeoutIsApplied() {
85+
assertThat(this.webClient).hasFieldOrPropertyWithValue("responseTimeout", Duration.ofSeconds(5));
86+
}
87+
88+
}
89+
90+
}

0 commit comments

Comments
 (0)