2222import java .util .Collections ;
2323import java .util .List ;
2424import java .util .Map ;
25+ import java .util .Optional ;
2526import javax .servlet .MultipartConfigElement ;
2627
2728import org .eclipse .jetty .server .Connector ;
@@ -88,7 +89,6 @@ public class RequestPartIntegrationTests {
8889
8990 @ BeforeClass
9091 public static void startServer () throws Exception {
91-
9292 // Let server pick its own random, available port.
9393 server = new Server (0 );
9494
@@ -144,19 +144,18 @@ public static void stopServer() throws Exception {
144144
145145 @ Test
146146 public void commonsMultipartResolver () throws Exception {
147- testCreate (baseUrl + "/commons-resolver/test" );
147+ testCreate (baseUrl + "/commons-resolver/test" , "Jason" );
148+ testCreate (baseUrl + "/commons-resolver/test" , "Arjen" );
148149 }
149150
150151 @ Test
151152 public void standardMultipartResolver () throws Exception {
152- testCreate (baseUrl + "/standard-resolver/test" );
153+ testCreate (baseUrl + "/standard-resolver/test" , "Jason" );
154+ testCreate (baseUrl + "/standard-resolver/test" , "Arjen" );
153155 }
154156
155- // SPR-13319
156-
157- @ Test
157+ @ Test // SPR-13319
158158 public void standardMultipartResolverWithEncodedFileName () throws Exception {
159-
160159 byte [] boundary = MimeTypeUtils .generateMultipartBoundary ();
161160 String boundaryText = new String (boundary , "US-ASCII" );
162161 Map <String , String > params = Collections .singletonMap ("boundary" , boundaryText );
@@ -183,18 +182,18 @@ public void standardMultipartResolverWithEncodedFileName() throws Exception {
183182 assertEquals (HttpStatus .OK , responseEntity .getStatusCode ());
184183 }
185184
186- private void testCreate (String url ) {
185+ private void testCreate (String url , String basename ) {
187186 MultiValueMap <String , Object > parts = new LinkedMultiValueMap <String , Object >();
188- parts .add ("json-data" , new HttpEntity <TestData >(new TestData ("Jason" )));
189- parts .add ("file-data" , new ClassPathResource ("logo.jpg" , this . getClass ()));
187+ parts .add ("json-data" , new HttpEntity <TestData >(new TestData (basename )));
188+ parts .add ("file-data" , new ClassPathResource ("logo.jpg" , getClass ()));
190189 parts .add ("empty-data" , new HttpEntity <byte []>(new byte [0 ])); // SPR-12860
191190
192191 HttpHeaders headers = new HttpHeaders ();
193192 headers .setContentType (new MediaType ("application" , "octet-stream" , Charset .forName ("ISO-8859-1" )));
194193 parts .add ("iso-8859-1-data" , new HttpEntity <byte []>(new byte [] {(byte ) 0xC4 }, headers )); // SPR-13096
195194
196195 URI location = restTemplate .postForLocation (url , parts );
197- assertEquals ("http://localhost:8080/test/Jason /logo.jpg" , location .toString ());
196+ assertEquals ("http://localhost:8080/test/" + basename + " /logo.jpg" , location .toString ());
198197 }
199198
200199
@@ -208,6 +207,7 @@ public RequestPartTestController controller() {
208207 }
209208 }
210209
210+
211211 @ Configuration
212212 @ SuppressWarnings ("unused" )
213213 static class CommonsMultipartResolverTestConfig extends RequestPartTestConfig {
@@ -218,6 +218,7 @@ public MultipartResolver multipartResolver() {
218218 }
219219 }
220220
221+
221222 @ Configuration
222223 @ SuppressWarnings ("unused" )
223224 static class StandardMultipartResolverTestConfig extends RequestPartTestConfig {
@@ -228,19 +229,20 @@ public MultipartResolver multipartResolver() {
228229 }
229230 }
230231
232+
231233 @ Controller
232234 @ SuppressWarnings ("unused" )
233235 private static class RequestPartTestController {
234236
235- @ RequestMapping (value = "/test" , method = POST , consumes = { "multipart/mixed" , "multipart/form-data" })
237+ @ RequestMapping (value = "/test" , method = POST , consumes = {"multipart/mixed" , "multipart/form-data" })
236238 public ResponseEntity <Object > create (@ RequestPart (name = "json-data" ) TestData testData ,
237- @ RequestPart ("file-data" ) MultipartFile file ,
239+ @ RequestPart ("file-data" ) Optional < MultipartFile > file ,
238240 @ RequestPart (name = "empty-data" , required = false ) TestData emptyData ,
239241 @ RequestPart (name = "iso-8859-1-data" ) byte [] iso88591Data ) {
240242
241243 Assert .assertArrayEquals (new byte []{(byte ) 0xC4 }, iso88591Data );
242244
243- String url = "http://localhost:8080/test/" + testData .getName () + "/" + file .getOriginalFilename ();
245+ String url = "http://localhost:8080/test/" + testData .getName () + "/" + file .get (). getOriginalFilename ();
244246 HttpHeaders headers = new HttpHeaders ();
245247 headers .setLocation (URI .create (url ));
246248 return new ResponseEntity <Object >(headers , HttpStatus .CREATED );
@@ -253,6 +255,7 @@ public ResponseEntity<Void> create(@RequestPart("file") MultipartFile multipartF
253255 }
254256 }
255257
258+
256259 @ SuppressWarnings ("unused" )
257260 private static class TestData {
258261
0 commit comments