5151import org .springframework .web .servlet .ModelAndView ;
5252
5353/**
54- * Test various scenarios for detecting method-level and method parameter annotations depending
55- * on where they are located -- on interfaces, parent classes, in parameterized methods, or in
54+ * Test various scenarios for detecting method-level and method parameter annotations depending
55+ * on where they are located -- on interfaces, parent classes, in parameterized methods, or in
5656 * combination with proxies.
57- *
57+ *
5858 * @author Rossen Stoyanchev
5959 */
6060@ RunWith (Parameterized .class )
6161public class HandlerMethodAnnotationDetectionTests {
62-
62+
6363 @ Parameters
6464 public static Collection <Object []> handlerTypes () {
6565 Object [][] array = new Object [12 ][2 ];
6666
6767 array [0 ] = new Object [] { SimpleController .class , true }; // CGLib proxy
6868 array [1 ] = new Object [] { SimpleController .class , false };
69-
69+
7070 array [2 ] = new Object [] { AbstractClassController .class , true }; // CGLib proxy
7171 array [3 ] = new Object [] { AbstractClassController .class , false };
72-
73- array [4 ] = new Object [] { ParameterizedAbstractClassController .class , false }; // CGLib proxy
74- array [5 ] = new Object [] { ParameterizedAbstractClassController .class , false };
75-
72+
73+ array [4 ] = new Object [] { ParameterizedAbstractClassController .class , false }; // CGLib proxy
74+ array [5 ] = new Object [] { ParameterizedAbstractClassController .class , false };
75+
7676 array [6 ] = new Object [] { InterfaceController .class , true }; // JDK dynamic proxy
77- array [7 ] = new Object [] { InterfaceController .class , false };
78-
79- array [8 ] = new Object [] { ParameterizedInterfaceController .class , false }; // no AOP
80- array [9 ] = new Object [] { ParameterizedInterfaceController .class , false };
81-
77+ array [7 ] = new Object [] { InterfaceController .class , false };
78+
79+ array [8 ] = new Object [] { ParameterizedInterfaceController .class , false }; // no AOP
80+ array [9 ] = new Object [] { ParameterizedInterfaceController .class , false };
81+
8282 array [10 ] = new Object [] { SupportClassController .class , true }; // CGLib proxy
8383 array [11 ] = new Object [] { SupportClassController .class , false };
84-
84+
8585 return Arrays .asList (array );
8686 }
8787
@@ -101,7 +101,7 @@ public HandlerMethodAnnotationDetectionTests(Class<?> controllerType, boolean us
101101 context .getBeanFactory ().registerSingleton ("advisor" , new DefaultPointcutAdvisor (new SimpleTraceInterceptor ()));
102102 }
103103 context .refresh ();
104-
104+
105105 handlerMapping .setApplicationContext (context );
106106 handlerAdapter .afterPropertiesSet ();
107107 exceptionResolver .afterPropertiesSet ();
@@ -113,12 +113,12 @@ public void testRequestMappingMethod() throws Exception {
113113 SimpleDateFormat dateFormat = new SimpleDateFormat (datePattern );
114114 String dateA = "11:01:2011" ;
115115 String dateB = "11:02:2011" ;
116-
116+
117117 MockHttpServletRequest request = new MockHttpServletRequest ("POST" , "/path1/path2" );
118118 request .setParameter ("datePattern" , datePattern );
119119 request .addHeader ("header1" , dateA );
120120 request .addHeader ("header2" , dateB );
121-
121+
122122 HandlerExecutionChain chain = handlerMapping .getHandler (request );
123123 assertNotNull (chain );
124124
@@ -133,7 +133,7 @@ public void testRequestMappingMethod() throws Exception {
133133 assertEquals ("failure" , response .getContentAsString ());
134134 }
135135
136-
136+
137137 /**
138138 * SIMPLE CASE
139139 */
@@ -156,15 +156,15 @@ public void initModel(@RequestHeader("header1") Date date, Model model) {
156156 public Date handle (@ RequestHeader ("header2" ) Date date ) throws Exception {
157157 return date ;
158158 }
159-
159+
160160 @ ExceptionHandler (Exception .class )
161161 @ ResponseBody
162162 public String handleException (Exception exception ) {
163163 return exception .getMessage ();
164164 }
165- }
165+ }
166+
166167
167-
168168 @ Controller
169169 static abstract class MappingAbstractClass {
170170
@@ -177,15 +177,15 @@ static abstract class MappingAbstractClass {
177177 @ RequestMapping (value ="/path1/path2" , method =RequestMethod .POST )
178178 @ ModelAttribute ("attr2" )
179179 public abstract Date handle (Date date , Model model ) throws Exception ;
180-
180+
181181 @ ExceptionHandler (Exception .class )
182182 @ ResponseBody
183183 public abstract String handleException (Exception exception );
184- }
184+ }
185185
186186 /**
187187 * CONTROLLER WITH ABSTRACT CLASS
188- *
188+ *
189189 * <p>All annotations can be on methods in the abstract class except parameter annotations.
190190 */
191191 static class AbstractClassController extends MappingAbstractClass {
@@ -202,14 +202,15 @@ public void initModel(@RequestHeader("header1") Date date, Model model) {
202202 public Date handle (@ RequestHeader ("header2" ) Date date , Model model ) throws Exception {
203203 return date ;
204204 }
205-
205+
206206 public String handleException (Exception exception ) {
207207 return exception .getMessage ();
208208 }
209209 }
210-
211-
212- @ Controller
210+
211+ // SPR-9374
212+
213+ @ RequestMapping
213214 static interface MappingInterface {
214215
215216 @ InitBinder
@@ -221,15 +222,15 @@ static interface MappingInterface {
221222 @ RequestMapping (value ="/path1/path2" , method =RequestMethod .POST )
222223 @ ModelAttribute ("attr2" )
223224 Date handle (@ RequestHeader ("header2" ) Date date , Model model ) throws Exception ;
224-
225+
225226 @ ExceptionHandler (Exception .class )
226227 @ ResponseBody
227228 String handleException (Exception exception );
228- }
229+ }
229230
230231 /**
231232 * CONTROLLER WITH INTERFACE
232- *
233+ *
233234 * No AOP:
234235 * All annotations can be on interface methods except parameter annotations.
235236 *
@@ -250,7 +251,7 @@ public void initModel(@RequestHeader("header1") Date date, Model model) {
250251 public Date handle (@ RequestHeader ("header2" ) Date date , Model model ) throws Exception {
251252 return date ;
252253 }
253-
254+
254255 public String handleException (Exception exception ) {
255256 return exception .getMessage ();
256257 }
@@ -269,15 +270,15 @@ static abstract class MappingParameterizedAbstractClass<A, B, C> {
269270 @ RequestMapping (value ="/path1/path2" , method =RequestMethod .POST )
270271 @ ModelAttribute ("attr2" )
271272 public abstract Date handle (C date , Model model ) throws Exception ;
272-
273+
273274 @ ExceptionHandler (Exception .class )
274275 @ ResponseBody
275276 public abstract String handleException (Exception exception );
276- }
277+ }
277278
278279 /**
279280 * CONTROLLER WITH PARAMETERIZED BASE CLASS
280- *
281+ *
281282 * <p>All annotations can be on methods in the abstract class except parameter annotations.
282283 */
283284 static class ParameterizedAbstractClassController extends MappingParameterizedAbstractClass <String , Date , Date > {
@@ -294,14 +295,13 @@ public void initModel(@RequestHeader("header1") Date date, Model model) {
294295 public Date handle (@ RequestHeader ("header2" ) Date date , Model model ) throws Exception {
295296 return date ;
296297 }
297-
298+
298299 public String handleException (Exception exception ) {
299300 return exception .getMessage ();
300301 }
301302 }
302303
303-
304- @ Controller
304+ @ RequestMapping
305305 static interface MappingParameterizedInterface <A , B , C > {
306306
307307 @ InitBinder
@@ -313,17 +313,17 @@ static interface MappingParameterizedInterface<A, B, C> {
313313 @ RequestMapping (value ="/path1/path2" , method =RequestMethod .POST )
314314 @ ModelAttribute ("attr2" )
315315 Date handle (C date , Model model ) throws Exception ;
316-
316+
317317 @ ExceptionHandler (Exception .class )
318318 @ ResponseBody
319319 String handleException (Exception exception );
320- }
320+ }
321321
322322 /**
323323 * CONTROLLER WITH PARAMETERIZED INTERFACE
324- *
324+ *
325325 * <p>All annotations can be on interface except parameter annotations.
326- *
326+ *
327327 * <p>Cannot be used as JDK dynamic proxy since parameterized interface does not contain type information.
328328 */
329329 static class ParameterizedInterfaceController implements MappingParameterizedInterface <String , Date , Date > {
@@ -344,18 +344,18 @@ public void initModel(@RequestHeader("header1") Date date, Model model) {
344344 public Date handle (@ RequestHeader ("header2" ) Date date , Model model ) throws Exception {
345345 return date ;
346346 }
347-
347+
348348 @ ExceptionHandler (Exception .class )
349349 @ ResponseBody
350350 public String handleException (Exception exception ) {
351351 return exception .getMessage ();
352352 }
353- }
354-
355-
353+ }
354+
355+
356356 /**
357357 * SPR-8248
358- *
358+ *
359359 * <p>Support class contains all annotations. Subclass has type-level @{@link RequestMapping}.
360360 */
361361 @ Controller
@@ -377,17 +377,17 @@ public void initModel(@RequestHeader("header1") Date date, Model model) {
377377 public Date handle (@ RequestHeader ("header2" ) Date date , Model model ) throws Exception {
378378 return date ;
379379 }
380-
380+
381381 @ ExceptionHandler (Exception .class )
382382 @ ResponseBody
383383 public String handleException (Exception exception ) {
384384 return exception .getMessage ();
385385 }
386- }
386+ }
387387
388388 @ Controller
389389 @ RequestMapping ("/path1" )
390390 static class SupportClassController extends MappingSupportClass {
391- }
391+ }
392392
393393}
0 commit comments