|
16 | 16 |
|
17 | 17 | package org.springframework.boot.web.servlet;
|
18 | 18 |
|
| 19 | +import java.util.Collection; |
19 | 20 | import java.util.EnumSet;
|
20 | 21 |
|
21 | 22 | import jakarta.servlet.DispatcherType;
|
|
25 | 26 | import jakarta.servlet.ServletContext;
|
26 | 27 | import jakarta.servlet.ServletRequest;
|
27 | 28 | import jakarta.servlet.ServletResponse;
|
| 29 | +import jakarta.servlet.annotation.WebInitParam; |
28 | 30 | import jakarta.servlet.http.HttpServlet;
|
29 | 31 | import jakarta.servlet.http.HttpServletRequest;
|
30 | 32 | import jakarta.servlet.http.HttpServletResponse;
|
|
47 | 49 | *
|
48 | 50 | * @author Andy Wilkinson
|
49 | 51 | * @author Moritz Halbritter
|
| 52 | + * @author Daeho Kwon |
50 | 53 | */
|
51 | 54 | class ServletContextInitializerBeansTests {
|
52 | 55 |
|
@@ -141,6 +144,14 @@ void shouldApplyFilterRegistrationAnnotation() {
|
141 | 144 | assertThat(filterRegistrationBean.getServletNames()).containsExactly("test");
|
142 | 145 | assertThat(filterRegistrationBean.determineDispatcherTypes()).containsExactly(DispatcherType.ERROR);
|
143 | 146 | assertThat(filterRegistrationBean.getUrlPatterns()).containsExactly("/test/*");
|
| 147 | + assertThat(filterRegistrationBean.getInitParameters()).containsEntry("env", "test") |
| 148 | + .containsEntry("debug", "true"); |
| 149 | + Collection<ServletRegistrationBean<?>> servletRegistrationBeans = filterRegistrationBean |
| 150 | + .getServletRegistrationBeans(); |
| 151 | + assertThat(servletRegistrationBeans).hasSize(1); |
| 152 | + assertThat(servletRegistrationBeans.iterator().next().getServletName()) |
| 153 | + .isEqualTo("testServletRegistrationBean"); |
| 154 | + |
144 | 155 | });
|
145 | 156 | }
|
146 | 157 |
|
@@ -296,11 +307,33 @@ static class FilterConfigurationWithAnnotation {
|
296 | 307 | @Bean
|
297 | 308 | @FilterRegistration(enabled = false, name = "test", asyncSupported = false,
|
298 | 309 | dispatcherTypes = DispatcherType.ERROR, matchAfter = true, servletNames = "test",
|
299 |
| - urlPatterns = "/test/*") |
| 310 | + urlPatterns = "/test/*", |
| 311 | + initParameters = { @WebInitParam(name = "env", value = "test"), |
| 312 | + @WebInitParam(name = "debug", value = "true") }, |
| 313 | + servletRegistrationBeans = { TestServlet.class }) |
300 | 314 | TestFilter testFilter() {
|
301 | 315 | return new TestFilter();
|
302 | 316 | }
|
303 | 317 |
|
| 318 | + @Bean |
| 319 | + ServletRegistrationBean<TestServlet> testServletRegistrationBean() { |
| 320 | + return new ServletRegistrationBean<>(new TestServlet()); |
| 321 | + } |
| 322 | + |
| 323 | + @Bean |
| 324 | + ServletRegistrationBean<NonMatchingServlet> nonMatchingServletRegistrationBean() { |
| 325 | + return new ServletRegistrationBean<>(new NonMatchingServlet()); |
| 326 | + } |
| 327 | + |
| 328 | + static class NonMatchingServlet extends HttpServlet implements ServletContextInitializer { |
| 329 | + |
| 330 | + @Override |
| 331 | + public void onStartup(ServletContext servletContext) { |
| 332 | + |
| 333 | + } |
| 334 | + |
| 335 | + } |
| 336 | + |
304 | 337 | }
|
305 | 338 |
|
306 | 339 | @Configuration(proxyBeanMethods = false)
|
|
0 commit comments