@@ -129,6 +129,13 @@ void shouldApplyServletRegistrationAnnotation() {
129
129
assertThat (servletRegistrationBean .getServletName ()).isEqualTo ("test" );
130
130
assertThat (servletRegistrationBean .isAsyncSupported ()).isFalse ();
131
131
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 );
132
139
});
133
140
}
134
141
@@ -209,29 +216,6 @@ void shouldApplyOrderFromOrderAttribute() {
209
216
.isEqualTo (ServletConfigurationWithAnnotationAndOrder .ORDER ));
210
217
}
211
218
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
-
235
219
private void load (Class <?>... configuration ) {
236
220
this .context = new AnnotationConfigApplicationContext (configuration );
237
221
}
@@ -269,7 +253,11 @@ static class ServletConfigurationWithAnnotation {
269
253
270
254
@ Bean
271
255
@ 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 ))
273
261
TestServlet testServlet () {
274
262
return new TestServlet ();
275
263
}
@@ -479,19 +467,4 @@ public void onStartup(ServletContext servletContext) {
479
467
480
468
}
481
469
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
-
497
470
}
0 commit comments