44
44
import org .springframework .ui .Model ;
45
45
import org .springframework .util .StreamUtils ;
46
46
import org .springframework .validation .BindingResult ;
47
- import org .springframework .web .bind .annotation .RequestMapping ;
48
- import org .springframework .web .bind .annotation .RequestMethod ;
47
+ import org .springframework .web .bind .annotation .PostMapping ;
49
48
import org .springframework .web .bind .annotation .PutMapping ;
50
49
import org .springframework .web .bind .annotation .RequestParam ;
51
50
import org .springframework .web .bind .annotation .RequestPart ;
65
64
* @author Jaebin Joo
66
65
* @author Sam Brannen
67
66
*/
68
- public class MultipartControllerTests {
67
+ class MultipartControllerTests {
69
68
70
69
@ ParameterizedTest
71
70
@ ValueSource (strings = {"/multipartfile" , "/multipartfile-via-put" , "/part" })
@@ -96,14 +95,14 @@ void multipartRequestWithSingleFileOrPart(String url) throws Exception {
96
95
}
97
96
98
97
@ Test
99
- public void multipartRequestWithSingleFileNotPresent () throws Exception {
98
+ void multipartRequestWithSingleFileNotPresent () throws Exception {
100
99
standaloneSetup (new MultipartController ()).build ()
101
100
.perform (multipart ("/multipartfile" ))
102
101
.andExpect (status ().isFound ());
103
102
}
104
103
105
104
@ Test
106
- public void multipartRequestWithFileArray () throws Exception {
105
+ void multipartRequestWithFileArray () throws Exception {
107
106
byte [] fileContent = "bar" .getBytes (StandardCharsets .UTF_8 );
108
107
MockMultipartFile filePart1 = new MockMultipartFile ("file" , "orig" , null , fileContent );
109
108
MockMultipartFile filePart2 = new MockMultipartFile ("file" , "orig" , null , fileContent );
@@ -119,21 +118,21 @@ public void multipartRequestWithFileArray() throws Exception {
119
118
}
120
119
121
120
@ Test
122
- public void multipartRequestWithFileArrayNotPresent () throws Exception {
121
+ void multipartRequestWithFileArrayNotPresent () throws Exception {
123
122
standaloneSetup (new MultipartController ()).build ()
124
123
.perform (multipart ("/multipartfilearray" ))
125
124
.andExpect (status ().isFound ());
126
125
}
127
126
128
127
@ Test
129
- public void multipartRequestWithFileArrayNoMultipart () throws Exception {
128
+ void multipartRequestWithFileArrayNoMultipart () throws Exception {
130
129
standaloneSetup (new MultipartController ()).build ()
131
130
.perform (post ("/multipartfilearray" ))
132
131
.andExpect (status ().isFound ());
133
132
}
134
133
135
134
@ Test
136
- public void multipartRequestWithFileList () throws Exception {
135
+ void multipartRequestWithFileList () throws Exception {
137
136
byte [] fileContent = "bar" .getBytes (StandardCharsets .UTF_8 );
138
137
MockMultipartFile filePart1 = new MockMultipartFile ("file" , "orig" , null , fileContent );
139
138
MockMultipartFile filePart2 = new MockMultipartFile ("file" , "orig" , null , fileContent );
@@ -149,21 +148,21 @@ public void multipartRequestWithFileList() throws Exception {
149
148
}
150
149
151
150
@ Test
152
- public void multipartRequestWithFileListNotPresent () throws Exception {
151
+ void multipartRequestWithFileListNotPresent () throws Exception {
153
152
standaloneSetup (new MultipartController ()).build ()
154
153
.perform (multipart ("/multipartfilelist" ))
155
154
.andExpect (status ().isFound ());
156
155
}
157
156
158
157
@ Test
159
- public void multipartRequestWithFileListNoMultipart () throws Exception {
158
+ void multipartRequestWithFileListNoMultipart () throws Exception {
160
159
standaloneSetup (new MultipartController ()).build ()
161
160
.perform (post ("/multipartfilelist" ))
162
161
.andExpect (status ().isFound ());
163
162
}
164
163
165
164
@ Test
166
- public void multipartRequestWithOptionalFile () throws Exception {
165
+ void multipartRequestWithOptionalFile () throws Exception {
167
166
byte [] fileContent = "bar" .getBytes (StandardCharsets .UTF_8 );
168
167
MockMultipartFile filePart = new MockMultipartFile ("file" , "orig" , null , fileContent );
169
168
@@ -178,7 +177,7 @@ public void multipartRequestWithOptionalFile() throws Exception {
178
177
}
179
178
180
179
@ Test
181
- public void multipartRequestWithOptionalFileNotPresent () throws Exception {
180
+ void multipartRequestWithOptionalFileNotPresent () throws Exception {
182
181
byte [] json = "{\" name\" :\" yeeeah\" }" .getBytes (StandardCharsets .UTF_8 );
183
182
MockMultipartFile jsonPart = new MockMultipartFile ("json" , "json" , "application/json" , json );
184
183
@@ -190,7 +189,7 @@ public void multipartRequestWithOptionalFileNotPresent() throws Exception {
190
189
}
191
190
192
191
@ Test
193
- public void multipartRequestWithOptionalFileArray () throws Exception {
192
+ void multipartRequestWithOptionalFileArray () throws Exception {
194
193
byte [] fileContent = "bar" .getBytes (StandardCharsets .UTF_8 );
195
194
MockMultipartFile filePart1 = new MockMultipartFile ("file" , "orig" , null , fileContent );
196
195
MockMultipartFile filePart2 = new MockMultipartFile ("file" , "orig" , null , fileContent );
@@ -206,7 +205,7 @@ public void multipartRequestWithOptionalFileArray() throws Exception {
206
205
}
207
206
208
207
@ Test
209
- public void multipartRequestWithOptionalFileArrayNotPresent () throws Exception {
208
+ void multipartRequestWithOptionalFileArrayNotPresent () throws Exception {
210
209
byte [] json = "{\" name\" :\" yeeeah\" }" .getBytes (StandardCharsets .UTF_8 );
211
210
MockMultipartFile jsonPart = new MockMultipartFile ("json" , "json" , "application/json" , json );
212
211
@@ -218,7 +217,7 @@ public void multipartRequestWithOptionalFileArrayNotPresent() throws Exception {
218
217
}
219
218
220
219
@ Test
221
- public void multipartRequestWithOptionalFileList () throws Exception {
220
+ void multipartRequestWithOptionalFileList () throws Exception {
222
221
byte [] fileContent = "bar" .getBytes (StandardCharsets .UTF_8 );
223
222
MockMultipartFile filePart1 = new MockMultipartFile ("file" , "orig" , null , fileContent );
224
223
MockMultipartFile filePart2 = new MockMultipartFile ("file" , "orig" , null , fileContent );
@@ -234,7 +233,7 @@ public void multipartRequestWithOptionalFileList() throws Exception {
234
233
}
235
234
236
235
@ Test
237
- public void multipartRequestWithOptionalFileListNotPresent () throws Exception {
236
+ void multipartRequestWithOptionalFileListNotPresent () throws Exception {
238
237
byte [] json = "{\" name\" :\" yeeeah\" }" .getBytes (StandardCharsets .UTF_8 );
239
238
MockMultipartFile jsonPart = new MockMultipartFile ("json" , "json" , "application/json" , json );
240
239
@@ -246,7 +245,7 @@ public void multipartRequestWithOptionalFileListNotPresent() throws Exception {
246
245
}
247
246
248
247
@ Test
249
- public void multipartRequestWithDataBindingToFile () throws Exception {
248
+ void multipartRequestWithDataBindingToFile () throws Exception {
250
249
byte [] fileContent = "bar" .getBytes (StandardCharsets .UTF_8 );
251
250
MockPart filePart = new MockPart ("file" , "orig" , fileContent );
252
251
@@ -257,7 +256,7 @@ public void multipartRequestWithDataBindingToFile() throws Exception {
257
256
}
258
257
259
258
@ Test // SPR-13317
260
- public void multipartRequestWrapped () throws Exception {
259
+ void multipartRequestWrapped () throws Exception {
261
260
byte [] json = "{\" name\" :\" yeeeah\" }" .getBytes (StandardCharsets .UTF_8 );
262
261
MockMultipartFile jsonPart = new MockMultipartFile ("json" , "json" , "application/json" , json );
263
262
@@ -272,7 +271,7 @@ public void multipartRequestWrapped() throws Exception {
272
271
@ Controller
273
272
private static class MultipartController {
274
273
275
- @ RequestMapping ( value = "/multipartfile" , method = RequestMethod . POST )
274
+ @ PostMapping ( "/multipartfile" )
276
275
public String processMultipartFile (@ RequestParam (required = false ) MultipartFile file ,
277
276
@ RequestPart (required = false ) Map <String , String > json , Model model ) throws IOException {
278
277
@@ -286,14 +285,14 @@ public String processMultipartFile(@RequestParam(required = false) MultipartFile
286
285
return "redirect:/index" ;
287
286
}
288
287
289
- @ RequestMapping (value = "/multipartfilearray" , method = RequestMethod .POST )
290
288
@ PutMapping ("/multipartfile-via-put" )
291
289
public String processMultipartFileViaHttpPut (@ RequestParam (required = false ) MultipartFile file ,
292
290
@ RequestPart (required = false ) Map <String , String > json , Model model ) throws IOException {
293
291
294
292
return processMultipartFile (file , json , model );
295
293
}
296
294
295
+ @ PostMapping ("/multipartfilearray" )
297
296
public String processMultipartFileArray (@ RequestParam (required = false ) MultipartFile [] file ,
298
297
@ RequestPart (required = false ) Map <String , String > json , Model model ) throws IOException {
299
298
@@ -309,7 +308,7 @@ public String processMultipartFileArray(@RequestParam(required = false) Multipar
309
308
return "redirect:/index" ;
310
309
}
311
310
312
- @ RequestMapping ( value = "/multipartfilelist" , method = RequestMethod . POST )
311
+ @ PostMapping ( "/multipartfilelist" )
313
312
public String processMultipartFileList (@ RequestParam (required = false ) List <MultipartFile > file ,
314
313
@ RequestPart (required = false ) Map <String , String > json , Model model ) throws IOException {
315
314
@@ -325,7 +324,7 @@ public String processMultipartFileList(@RequestParam(required = false) List<Mult
325
324
return "redirect:/index" ;
326
325
}
327
326
328
- @ RequestMapping ( value = "/optionalfile" , method = RequestMethod . POST )
327
+ @ PostMapping ( "/optionalfile" )
329
328
public String processOptionalFile (@ RequestParam Optional <MultipartFile > file ,
330
329
@ RequestPart Map <String , String > json , Model model ) throws IOException {
331
330
@@ -337,7 +336,7 @@ public String processOptionalFile(@RequestParam Optional<MultipartFile> file,
337
336
return "redirect:/index" ;
338
337
}
339
338
340
- @ RequestMapping ( value = "/optionalfilearray" , method = RequestMethod . POST )
339
+ @ PostMapping ( "/optionalfilearray" )
341
340
public String processOptionalFileArray (@ RequestParam Optional <MultipartFile []> file ,
342
341
@ RequestPart Map <String , String > json , Model model ) throws IOException {
343
342
@@ -351,7 +350,7 @@ public String processOptionalFileArray(@RequestParam Optional<MultipartFile[]> f
351
350
return "redirect:/index" ;
352
351
}
353
352
354
- @ RequestMapping ( value = "/optionalfilelist" , method = RequestMethod . POST )
353
+ @ PostMapping ( "/optionalfilelist" )
355
354
public String processOptionalFileList (@ RequestParam Optional <List <MultipartFile >> file ,
356
355
@ RequestPart Map <String , String > json , Model model ) throws IOException {
357
356
@@ -365,7 +364,7 @@ public String processOptionalFileList(@RequestParam Optional<List<MultipartFile>
365
364
return "redirect:/index" ;
366
365
}
367
366
368
- @ RequestMapping ( value = "/part" , method = RequestMethod . POST )
367
+ @ PostMapping ( "/part" )
369
368
public String processPart (@ RequestPart Part part ,
370
369
@ RequestPart Map <String , String > json , Model model ) throws IOException {
371
370
@@ -378,13 +377,13 @@ public String processPart(@RequestPart Part part,
378
377
return "redirect:/index" ;
379
378
}
380
379
381
- @ RequestMapping ( value = "/json" , method = RequestMethod . POST )
380
+ @ PostMapping ( "/json" )
382
381
public String processMultipart (@ RequestPart Map <String , String > json , Model model ) {
383
382
model .addAttribute ("json" , json );
384
383
return "redirect:/index" ;
385
384
}
386
385
387
- @ RequestMapping ( value = "/multipartfilebinding" , method = RequestMethod . POST )
386
+ @ PostMapping ( "/multipartfilebinding" )
388
387
public String processMultipartFileBean (
389
388
MultipartFileBean multipartFileBean , Model model , BindingResult bindingResult ) throws IOException {
390
389
0 commit comments