26
26
27
27
import org .springframework .http .HttpHeaders ;
28
28
import org .springframework .http .MediaType ;
29
+ import org .springframework .util .AntPathMatcher ;
29
30
import org .springframework .web .bind .annotation .RequestMethod ;
30
31
import org .springframework .web .servlet .handler .PathPatternsParameterizedTest ;
31
32
import org .springframework .web .servlet .handler .PathPatternsTestUtils ;
@@ -48,8 +49,8 @@ class RequestMappingInfoTests {
48
49
@ SuppressWarnings ("unused" )
49
50
static Stream <RequestMappingInfo .Builder > pathPatternsArguments () {
50
51
RequestMappingInfo .BuilderConfiguration config = new RequestMappingInfo .BuilderConfiguration ();
51
- config .setPatternParser (new PathPatternParser ());
52
- return Stream .of (RequestMappingInfo .paths (). options ( config ) , RequestMappingInfo .paths ());
52
+ config .setPathMatcher (new AntPathMatcher ());
53
+ return Stream .of (RequestMappingInfo .paths (), RequestMappingInfo .paths (). options ( config ));
53
54
}
54
55
55
56
@@ -86,6 +87,13 @@ void createEmpty(RequestMappingInfo.Builder infoBuilder) {
86
87
assertThat (info .getCustomCondition ()).isSameAs (result .getCustomCondition ());
87
88
}
88
89
90
+ @ Test // gh-31662
91
+ void pathPatternByDefault () {
92
+ RequestMappingInfo info = RequestMappingInfo .paths ().build ();
93
+ assertThat (info .getPathPatternsCondition ()).isNotNull ();
94
+ assertThat (info .getPatternsCondition ()).isNull ();
95
+ }
96
+
89
97
@ PathPatternsParameterizedTest
90
98
void matchPatternsCondition (RequestMappingInfo .Builder builder ) {
91
99
@@ -105,7 +113,7 @@ void matchPatternsCondition(RequestMappingInfo.Builder builder) {
105
113
106
114
@ Test
107
115
void matchParamsCondition () {
108
- MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/foo" , false );
116
+ MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/foo" , true );
109
117
request .setParameter ("foo" , "bar" );
110
118
111
119
RequestMappingInfo info = RequestMappingInfo .paths ("/foo" ).params ("foo=bar" ).build ();
@@ -121,7 +129,7 @@ void matchParamsCondition() {
121
129
122
130
@ Test
123
131
void matchHeadersCondition () {
124
- MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/foo" , false );
132
+ MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/foo" , true );
125
133
request .addHeader ("foo" , "bar" );
126
134
127
135
RequestMappingInfo info = RequestMappingInfo .paths ("/foo" ).headers ("foo=bar" ).build ();
@@ -137,7 +145,7 @@ void matchHeadersCondition() {
137
145
138
146
@ Test
139
147
void matchConsumesCondition () {
140
- MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/foo" , false );
148
+ MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/foo" , true );
141
149
request .setContentType ("text/plain" );
142
150
143
151
RequestMappingInfo info = RequestMappingInfo .paths ("/foo" ).consumes ("text/plain" ).build ();
@@ -153,7 +161,7 @@ void matchConsumesCondition() {
153
161
154
162
@ Test
155
163
void matchProducesCondition () {
156
- MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/foo" , false );
164
+ MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/foo" , true );
157
165
request .addHeader ("Accept" , "text/plain" );
158
166
159
167
RequestMappingInfo info = RequestMappingInfo .paths ("/foo" ).produces ("text/plain" ).build ();
@@ -169,7 +177,7 @@ void matchProducesCondition() {
169
177
170
178
@ Test
171
179
void matchCustomCondition () {
172
- MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/foo" , false );
180
+ MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/foo" , true );
173
181
request .setParameter ("foo" , "bar" );
174
182
175
183
RequestMappingInfo info = RequestMappingInfo .paths ("/foo" ).params ("foo=bar" ).build ();
@@ -189,7 +197,7 @@ void compareToWithImplicitVsExplicitHttpMethodDeclaration() {
189
197
RequestMappingInfo oneMethod = RequestMappingInfo .paths ().methods (GET ).build ();
190
198
RequestMappingInfo oneMethodOneParam = RequestMappingInfo .paths ().methods (GET ).params ("foo" ).build ();
191
199
192
- MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/" , false );
200
+ MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/" , true );
193
201
Comparator <RequestMappingInfo > comparator = (info , otherInfo ) -> info .compareTo (otherInfo , request );
194
202
195
203
List <RequestMappingInfo > list = asList (noMethods , oneMethod , oneMethodOneParam );
@@ -204,7 +212,7 @@ void compareToWithImplicitVsExplicitHttpMethodDeclaration() {
204
212
@ Test
205
213
// SPR-14383
206
214
void compareToWithHttpHeadMapping () {
207
- MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/" , false );
215
+ MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("GET" , "/" , true );
208
216
request .setMethod ("HEAD" );
209
217
request .addHeader ("Accept" , "application/json" );
210
218
@@ -297,7 +305,7 @@ void equalsMethod(RequestMappingInfo.Builder infoBuilder) {
297
305
298
306
@ Test
299
307
void preFlightRequest () {
300
- MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("OPTIONS" , "/foo" , false );
308
+ MockHttpServletRequest request = PathPatternsTestUtils .initRequest ("OPTIONS" , "/foo" , true );
301
309
request .addHeader (HttpHeaders .ORIGIN , "https://domain.com" );
302
310
request .addHeader (HttpHeaders .ACCESS_CONTROL_REQUEST_METHOD , "POST" );
303
311
0 commit comments