|
16 | 16 |
|
17 | 17 | package org.springframework.boot.autoconfigure.web.reactive;
|
18 | 18 |
|
| 19 | +import org.apache.catalina.startup.Tomcat; |
| 20 | +import org.eclipse.jetty.server.Server; |
19 | 21 | import org.junit.Test;
|
20 | 22 | import org.mockito.Mockito;
|
| 23 | +import reactor.netty.http.server.HttpServer; |
21 | 24 |
|
22 | 25 | import org.springframework.boot.autoconfigure.AutoConfigurations;
|
23 |
| -import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration; |
| 26 | +import org.springframework.boot.test.context.FilteredClassLoader; |
24 | 27 | import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
|
25 |
| -import org.springframework.boot.test.context.runner.WebApplicationContextRunner; |
26 | 28 | import org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory;
|
27 | 29 | import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
|
28 |
| -import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; |
29 | 30 | import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
|
30 | 31 | import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
|
31 | 32 | import org.springframework.boot.web.embedded.tomcat.TomcatProtocolHandlerCustomizer;
|
32 | 33 | import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory;
|
33 | 34 | import org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer;
|
34 | 35 | import org.springframework.boot.web.embedded.undertow.UndertowDeploymentInfoCustomizer;
|
35 | 36 | import org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory;
|
36 |
| -import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; |
37 | 37 | import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext;
|
38 | 38 | import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext;
|
39 | 39 | import org.springframework.boot.web.reactive.server.ConfigurableReactiveWebServerFactory;
|
40 | 40 | import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
|
41 | 41 | import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
42 |
| -import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; |
43 | 42 | import org.springframework.context.ApplicationContextException;
|
44 | 43 | import org.springframework.context.annotation.Bean;
|
45 | 44 | import org.springframework.context.annotation.Configuration;
|
@@ -161,44 +160,55 @@ public void tomcatProtocolHandlerCustomizerBeanIsAddedToFactory() {
|
161 | 160 |
|
162 | 161 | @Test
|
163 | 162 | public void jettyServerCustomizerBeanIsAddedToFactory() {
|
164 |
| - ReactiveWebApplicationContextRunner runner = new ReactiveWebApplicationContextRunner( |
| 163 | + new ReactiveWebApplicationContextRunner( |
165 | 164 | AnnotationConfigReactiveWebApplicationContext::new)
|
166 | 165 | .withConfiguration(AutoConfigurations
|
167 | 166 | .of(ReactiveWebServerFactoryAutoConfiguration.class))
|
168 |
| - .withUserConfiguration(JettyServerCustomizer.class); |
169 |
| - runner.run((context) -> { |
170 |
| - JettyReactiveWebServerFactory factory = context |
171 |
| - .getBean(JettyReactiveWebServerFactory.class); |
172 |
| - assertThat(factory.getServerCustomizers()).hasSize(1); |
173 |
| - }); |
| 167 | + .withClassLoader( |
| 168 | + new FilteredClassLoader(Tomcat.class, HttpServer.class)) |
| 169 | + .withUserConfiguration(JettyServerCustomizerConfiguration.class, |
| 170 | + HttpHandlerConfiguration.class) |
| 171 | + .run((context) -> { |
| 172 | + JettyReactiveWebServerFactory factory = context |
| 173 | + .getBean(JettyReactiveWebServerFactory.class); |
| 174 | + assertThat(factory.getServerCustomizers()).hasSize(1); |
| 175 | + }); |
174 | 176 | }
|
175 | 177 |
|
176 | 178 | @Test
|
177 | 179 | public void undertowDeploymentInfoCustomizerBeanIsAddedToFactory() {
|
178 |
| - ReactiveWebApplicationContextRunner runner = new ReactiveWebApplicationContextRunner( |
| 180 | + new ReactiveWebApplicationContextRunner( |
179 | 181 | AnnotationConfigReactiveWebApplicationContext::new)
|
180 | 182 | .withConfiguration(AutoConfigurations
|
181 | 183 | .of(ReactiveWebServerFactoryAutoConfiguration.class))
|
182 |
| - .withUserConfiguration(UndertowDeploymentInfoCustomizer.class); |
183 |
| - runner.run((context) -> { |
184 |
| - UndertowReactiveWebServerFactory factory = context |
185 |
| - .getBean(UndertowReactiveWebServerFactory.class); |
186 |
| - assertThat(factory.getDeploymentInfoCustomizers()).hasSize(1); |
187 |
| - }); |
| 184 | + .withClassLoader(new FilteredClassLoader(Tomcat.class, |
| 185 | + HttpServer.class, Server.class)) |
| 186 | + .withUserConfiguration( |
| 187 | + UndertowDeploymentInfoCustomizerConfiguration.class, |
| 188 | + HttpHandlerConfiguration.class) |
| 189 | + .run((context) -> { |
| 190 | + UndertowReactiveWebServerFactory factory = context |
| 191 | + .getBean(UndertowReactiveWebServerFactory.class); |
| 192 | + assertThat(factory.getDeploymentInfoCustomizers()).hasSize(1); |
| 193 | + }); |
188 | 194 | }
|
189 | 195 |
|
190 | 196 | @Test
|
191 | 197 | public void undertowBuilderCustomizerBeanIsAddedToFactory() {
|
192 |
| - ReactiveWebApplicationContextRunner runner = new ReactiveWebApplicationContextRunner( |
| 198 | + new ReactiveWebApplicationContextRunner( |
193 | 199 | AnnotationConfigReactiveWebApplicationContext::new)
|
194 | 200 | .withConfiguration(AutoConfigurations
|
195 | 201 | .of(ReactiveWebServerFactoryAutoConfiguration.class))
|
196 |
| - .withUserConfiguration(UndertowBuilderCustomizer.class); |
197 |
| - runner.run((context) -> { |
198 |
| - UndertowReactiveWebServerFactory factory = context |
199 |
| - .getBean(UndertowReactiveWebServerFactory.class); |
200 |
| - assertThat(factory.getBuilderCustomizers()).hasSize(1); |
201 |
| - }); |
| 202 | + .withClassLoader(new FilteredClassLoader(Tomcat.class, |
| 203 | + HttpServer.class, Server.class)) |
| 204 | + .withUserConfiguration( |
| 205 | + UndertowBuilderCustomizerConfiguration.class, |
| 206 | + HttpHandlerConfiguration.class) |
| 207 | + .run((context) -> { |
| 208 | + UndertowReactiveWebServerFactory factory = context |
| 209 | + .getBean(UndertowReactiveWebServerFactory.class); |
| 210 | + assertThat(factory.getBuilderCustomizers()).hasSize(1); |
| 211 | + }); |
202 | 212 | }
|
203 | 213 |
|
204 | 214 | @Test
|
@@ -300,6 +310,42 @@ public TomcatProtocolHandlerCustomizer protocolHandlerCustomizer() {
|
300 | 310 |
|
301 | 311 | }
|
302 | 312 |
|
| 313 | + @Configuration(proxyBeanMethods = false) |
| 314 | + static class JettyServerCustomizerConfiguration { |
| 315 | + |
| 316 | + @Bean |
| 317 | + public JettyServerCustomizer protocolHandlerCustomizer() { |
| 318 | + return (server) -> { |
| 319 | + |
| 320 | + }; |
| 321 | + } |
| 322 | + |
| 323 | + } |
| 324 | + |
| 325 | + @Configuration(proxyBeanMethods = false) |
| 326 | + static class UndertowBuilderCustomizerConfiguration { |
| 327 | + |
| 328 | + @Bean |
| 329 | + public UndertowBuilderCustomizer protocolHandlerCustomizer() { |
| 330 | + return (builder) -> { |
| 331 | + |
| 332 | + }; |
| 333 | + } |
| 334 | + |
| 335 | + } |
| 336 | + |
| 337 | + @Configuration(proxyBeanMethods = false) |
| 338 | + static class UndertowDeploymentInfoCustomizerConfiguration { |
| 339 | + |
| 340 | + @Bean |
| 341 | + public UndertowDeploymentInfoCustomizer protocolHandlerCustomizer() { |
| 342 | + return (deploymentInfo) -> { |
| 343 | + |
| 344 | + }; |
| 345 | + } |
| 346 | + |
| 347 | + } |
| 348 | + |
303 | 349 | @Configuration(proxyBeanMethods = false)
|
304 | 350 | static class ForwardedHeaderTransformerConfiguration {
|
305 | 351 |
|
|
0 commit comments