|
| 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