@@ -129,6 +129,13 @@ void shouldApplyServletRegistrationAnnotation() {
129129 assertThat (servletRegistrationBean .getServletName ()).isEqualTo ("test" );
130130 assertThat (servletRegistrationBean .isAsyncSupported ()).isFalse ();
131131 assertThat (servletRegistrationBean .getUrlMappings ()).containsExactly ("/test/*" );
132+ assertThat (servletRegistrationBean .getInitParameters ())
133+ .containsExactlyInAnyOrderEntriesOf (Map .of ("env" , "test" , "debug" , "true" ));
134+ assertThat (servletRegistrationBean .getMultipartConfig ()).isNotNull ();
135+ assertThat (servletRegistrationBean .getMultipartConfig ().getLocation ()).isEqualTo ("/tmp" );
136+ assertThat (servletRegistrationBean .getMultipartConfig ().getMaxFileSize ()).isEqualTo (1024 );
137+ assertThat (servletRegistrationBean .getMultipartConfig ().getMaxRequestSize ()).isEqualTo (4096 );
138+ assertThat (servletRegistrationBean .getMultipartConfig ().getFileSizeThreshold ()).isEqualTo (128 );
132139 });
133140 }
134141
@@ -209,29 +216,6 @@ void shouldApplyOrderFromOrderAttribute() {
209216 .isEqualTo (ServletConfigurationWithAnnotationAndOrder .ORDER ));
210217 }
211218
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-
235219 private void load (Class <?>... configuration ) {
236220 this .context = new AnnotationConfigApplicationContext (configuration );
237221 }
@@ -269,7 +253,11 @@ static class ServletConfigurationWithAnnotation {
269253
270254 @ Bean
271255 @ ServletRegistration (enabled = false , name = "test" , asyncSupported = false , urlMappings = "/test/*" ,
272- loadOnStartup = 1 )
256+ loadOnStartup = 1 ,
257+ initParameters = { @ WebInitParam (name = "env" , value = "test" ),
258+ @ WebInitParam (name = "debug" , value = "true" ) },
259+ multipartConfig = @ MultipartConfig (location = "/tmp" , maxFileSize = 1024 , maxRequestSize = 4096 ,
260+ fileSizeThreshold = 128 ))
273261 TestServlet testServlet () {
274262 return new TestServlet ();
275263 }
@@ -479,19 +467,4 @@ public void onStartup(ServletContext servletContext) {
479467
480468 }
481469
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-
497470}
0 commit comments