28
28
import org .springframework .http .converter .json .SpringHandlerInstantiator ;
29
29
import org .springframework .mock .web .test .MockHttpServletRequest ;
30
30
import org .springframework .stereotype .Controller ;
31
+ import org .springframework .web .bind .annotation .PathVariable ;
31
32
import org .springframework .web .bind .annotation .RequestMapping ;
32
33
import org .springframework .web .context .WebApplicationContext ;
33
34
import org .springframework .web .context .support .WebApplicationContextUtils ;
50
51
*/
51
52
public class StandaloneMockMvcBuilderTests {
52
53
53
- @ Test // SPR-10825
54
- public void placeHoldersInRequestMapping () throws Exception {
54
+ // SPR-10825
55
55
56
+ @ Test
57
+ public void placeHoldersInRequestMapping () throws Exception {
56
58
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder (new PlaceholderController ());
57
59
builder .addPlaceHolderValue ("sys.login.ajax" , "/foo" );
58
60
builder .build ();
@@ -66,7 +68,29 @@ public void placeHoldersInRequestMapping() throws Exception {
66
68
assertEquals ("handleWithPlaceholders" , ((HandlerMethod ) chain .getHandler ()).getMethod ().getName ());
67
69
}
68
70
69
- @ Test // SPR-12553
71
+ // SPR-13637
72
+
73
+ @ Test
74
+ public void suffixPatternMatch () throws Exception {
75
+ TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder (new PersonController ());
76
+ builder .setUseSuffixPatternMatch (false );
77
+ builder .build ();
78
+
79
+ RequestMappingHandlerMapping hm = builder .wac .getBean (RequestMappingHandlerMapping .class );
80
+
81
+ MockHttpServletRequest request = new MockHttpServletRequest ("GET" , "/persons" );
82
+ HandlerExecutionChain chain = hm .getHandler (request );
83
+ assertNotNull (chain );
84
+ assertEquals ("persons" , ((HandlerMethod ) chain .getHandler ()).getMethod ().getName ());
85
+
86
+ request = new MockHttpServletRequest ("GET" , "/persons.xml" );
87
+ chain = hm .getHandler (request );
88
+ assertNull (chain );
89
+ }
90
+
91
+ // SPR-12553
92
+
93
+ @ Test
70
94
public void applicationContextAttribute () {
71
95
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder (new PlaceholderController ());
72
96
builder .addPlaceHolderValue ("sys.login.ajax" , "/foo" );
@@ -100,7 +124,9 @@ public void addFilterPatternContainsNull() {
100
124
builder .addFilter (new ContinueFilter (), (String ) null );
101
125
}
102
126
103
- @ Test // SPR-13375
127
+ // SPR-13375
128
+
129
+ @ Test
104
130
@ SuppressWarnings ("rawtypes" )
105
131
public void springHandlerInstantiator () {
106
132
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder (new PersonController ());
@@ -112,6 +138,7 @@ public void springHandlerInstantiator() {
112
138
113
139
114
140
@ Controller
141
+ @ SuppressWarnings ("unused" )
115
142
private static class PlaceholderController {
116
143
117
144
@ RequestMapping (value = "${sys.login.ajax}" )
@@ -135,17 +162,26 @@ protected WebApplicationContext initWebAppContext() {
135
162
}
136
163
137
164
@ Controller
165
+ @ SuppressWarnings ("unused" )
138
166
private static class PersonController {
167
+
168
+ @ RequestMapping (value ="/persons" )
169
+ public String persons () {
170
+ return null ;
171
+ }
172
+
139
173
@ RequestMapping (value ="/forward" )
140
174
public String forward () {
141
175
return "forward:/persons" ;
142
176
}
143
177
}
144
178
145
179
private class ContinueFilter extends OncePerRequestFilter {
180
+
146
181
@ Override
147
182
protected void doFilterInternal (HttpServletRequest request , HttpServletResponse response ,
148
183
FilterChain filterChain ) throws ServletException , IOException {
184
+
149
185
filterChain .doFilter (request , response );
150
186
}
151
187
}
0 commit comments