|
18 | 18 |
|
19 | 19 | import org.assertj.core.api.InstanceOfAssertFactories; |
20 | 20 | import org.junit.jupiter.api.Test; |
| 21 | +import org.junit.jupiter.params.ParameterizedTest; |
| 22 | +import org.junit.jupiter.params.provider.ValueSource; |
21 | 23 | import reactor.core.publisher.Mono; |
22 | 24 |
|
23 | 25 | import org.springframework.boot.autoconfigure.AutoConfigurations; |
|
35 | 37 | import org.springframework.web.reactive.function.server.RouterFunction; |
36 | 38 | import org.springframework.web.reactive.function.server.ServerResponse; |
37 | 39 | import org.springframework.web.server.WebHandler; |
| 40 | +import org.springframework.web.server.adapter.HttpWebHandlerAdapter; |
38 | 41 |
|
39 | 42 | import static org.assertj.core.api.Assertions.assertThat; |
40 | 43 | import static org.springframework.web.reactive.function.server.RequestPredicates.GET; |
@@ -100,6 +103,29 @@ void shouldConfigureBasePathCompositeHandler() { |
100 | 103 | }); |
101 | 104 | } |
102 | 105 |
|
| 106 | + @ParameterizedTest |
| 107 | + @ValueSource(booleans = { true, false }) |
| 108 | + void shouldConfigureDefaultHtmlEscape(boolean enabled) { |
| 109 | + this.contextRunner.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class)) |
| 110 | + .withPropertyValues("spring.webflux.default-html-escape=" + enabled) |
| 111 | + .run((context) -> { |
| 112 | + assertThat(context).hasSingleBean(HttpHandler.class); |
| 113 | + assertThat(context.getBean(HttpHandler.class)).isInstanceOfSatisfying(HttpWebHandlerAdapter.class, |
| 114 | + (adapter) -> assertThat(adapter.getDefaultHtmlEscape()).isEqualTo(enabled)); |
| 115 | + }); |
| 116 | + } |
| 117 | + |
| 118 | + @Test |
| 119 | + void shouldNotConfigureDefaultHtmlEscaperWithoutWebFluxAutoConfiguration() { |
| 120 | + this.contextRunner.withUserConfiguration(CustomWebHandler.class) |
| 121 | + .withPropertyValues("spring.webflux.default-html-escape=true") |
| 122 | + .run((context) -> { |
| 123 | + assertThat(context).hasSingleBean(HttpHandler.class); |
| 124 | + assertThat(context.getBean(HttpHandler.class)).isInstanceOfSatisfying(HttpWebHandlerAdapter.class, |
| 125 | + (adapter) -> assertThat(adapter.getDefaultHtmlEscape()).isNull()); |
| 126 | + }); |
| 127 | + } |
| 128 | + |
103 | 129 | @Configuration(proxyBeanMethods = false) |
104 | 130 | static class CustomHttpHandler { |
105 | 131 |
|
|
0 commit comments