|
27 | 27 | import jakarta.servlet.ServletContext;
|
28 | 28 | import jakarta.servlet.ServletRequest;
|
29 | 29 | import jakarta.servlet.ServletResponse;
|
| 30 | +import jakarta.servlet.annotation.MultipartConfig; |
30 | 31 | import jakarta.servlet.annotation.WebInitParam;
|
31 | 32 | import jakarta.servlet.http.HttpServlet;
|
32 | 33 | import jakarta.servlet.http.HttpServletRequest;
|
|
51 | 52 | * @author Andy Wilkinson
|
52 | 53 | * @author Moritz Halbritter
|
53 | 54 | * @author Daeho Kwon
|
| 55 | + * @author Dmytro Danilenkov |
54 | 56 | */
|
55 | 57 | class ServletContextInitializerBeansTests {
|
56 | 58 |
|
@@ -207,6 +209,29 @@ void shouldApplyOrderFromOrderAttribute() {
|
207 | 209 | .isEqualTo(ServletConfigurationWithAnnotationAndOrder.ORDER));
|
208 | 210 | }
|
209 | 211 |
|
| 212 | + @Test |
| 213 | + void shouldApplyExtendedServletRegistrationAnnotation() { |
| 214 | + load(ServletConfigurationWithExtendedAttributes.class); |
| 215 | + ServletContextInitializerBeans initializerBeans = new ServletContextInitializerBeans( |
| 216 | + this.context.getBeanFactory(), TestServletContextInitializer.class); |
| 217 | + assertThatSingleServletRegistration(initializerBeans, (bean) -> { |
| 218 | + assertThat(bean.getServletName()).isEqualTo("extended"); |
| 219 | + assertThat(bean.getUrlMappings()).containsExactly("/extended/*"); |
| 220 | + assertThat(bean.getInitParameters()).containsEntry("hello", "world").containsEntry("flag", "true"); |
| 221 | + assertThat(bean.getMultipartConfig()).isNotNull(); |
| 222 | + assertThat(bean.getMultipartConfig().getLocation()).isEqualTo("/tmp"); |
| 223 | + assertThat(bean.getMultipartConfig().getMaxFileSize()).isEqualTo(1024); |
| 224 | + assertThat(bean.getMultipartConfig().getMaxRequestSize()).isEqualTo(4096); |
| 225 | + assertThat(bean.getMultipartConfig().getFileSizeThreshold()).isEqualTo(128); |
| 226 | + }); |
| 227 | + |
| 228 | + } |
| 229 | + |
| 230 | + private void assertThatSingleServletRegistration(ServletContextInitializerBeans initializerBeans, |
| 231 | + ThrowingConsumer<ServletRegistrationBean<?>> code) { |
| 232 | + assertThatSingleRegistration(initializerBeans, ServletRegistrationBean.class, code::acceptThrows); |
| 233 | + } |
| 234 | + |
210 | 235 | private void load(Class<?>... configuration) {
|
211 | 236 | this.context = new AnnotationConfigApplicationContext(configuration);
|
212 | 237 | }
|
@@ -454,4 +479,19 @@ public void onStartup(ServletContext servletContext) {
|
454 | 479 |
|
455 | 480 | }
|
456 | 481 |
|
| 482 | + @Configuration(proxyBeanMethods = false) |
| 483 | + static class ServletConfigurationWithExtendedAttributes { |
| 484 | + |
| 485 | + @Bean |
| 486 | + @ServletRegistration(name = "extended", urlMappings = "/extended/*", |
| 487 | + initParameters = { @WebInitParam(name = "hello", value = "world"), |
| 488 | + @WebInitParam(name = "flag", value = "true") }, |
| 489 | + multipartConfig = @MultipartConfig(location = "/tmp", maxFileSize = 1024, maxRequestSize = 4096, |
| 490 | + fileSizeThreshold = 128)) |
| 491 | + TestServlet testServletWithInitParametersAndMultipart() { |
| 492 | + return new TestServlet(); |
| 493 | + } |
| 494 | + |
| 495 | + } |
| 496 | + |
457 | 497 | }
|
0 commit comments