@@ -58,15 +58,19 @@ void jsonMetaDataMissing() throws Exception {
5858 mockMvc .perform (multipart ("/maps/upload" )
5959 .file (file )
6060 .with (getOAuthTokenWithActiveUser (OAuthScope ._UPLOAD_MAP , NO_AUTHORITIES )))
61- .andExpect (status ().isBadRequest ())
61+ .andExpect (status ().isUnprocessableEntity ())
6262 .andExpect (jsonPath ("$.errors" , hasSize (1 )))
63- .andExpect (jsonPath ("$.errors[0].title" , is ("org.springframework.web.bind.MissingServletRequestParameterException " )))
64- .andExpect (jsonPath ("$.errors[0].detail" , is ("Required request parameter 'metadata' for method parameter type String is not present " )));
63+ .andExpect (jsonPath ("$.errors[0].title" , is ("Missing parameter " )))
64+ .andExpect (jsonPath ("$.errors[0].detail" , is ("A parameter 'metadata' has to be provided. " )));
6565 }
6666
6767 @ Test
68- void successUpload () throws Exception {
69- String jsonString = "{}" ;
68+ void successUploadViaJsonRequestParam () throws Exception {
69+ String jsonString = """
70+ {
71+ "isRanked": true
72+ }
73+ """ ;
7074
7175 String zipFile = "command_conquer_rush.v0007.zip" ;
7276 try (InputStream inputStream = loadMapResourceAsStream (zipFile )) {
@@ -85,6 +89,33 @@ void successUpload() throws Exception {
8589 }
8690 }
8791
92+ @ Test
93+ void successUploadViaMultipartJsonMetadata () throws Exception {
94+ String metadataString = """
95+ {
96+ "isRanked": true,
97+ "licenseId": 1
98+ }
99+ """ ;
100+ MockMultipartFile metadata = new MockMultipartFile ("metadata" , null , "application/json" , metadataString .getBytes ());
101+
102+ String zipFile = "command_conquer_rush.v0007.zip" ;
103+ try (InputStream inputStream = loadMapResourceAsStream (zipFile )) {
104+ MockMultipartFile file = new MockMultipartFile ("file" ,
105+ zipFile ,
106+ "application/zip" ,
107+ ByteStreams .toByteArray (inputStream ));
108+
109+ mockMvc .perform (multipart ("/maps/upload" )
110+ .file (file )
111+ .file (metadata )
112+ .with (getOAuthTokenWithActiveUser (OAuthScope ._UPLOAD_MAP , NO_AUTHORITIES ))
113+ ).andExpect (status ().isOk ());
114+ } finally {
115+ FileUtils .deleteDirectory (fafApiProperties .getMap ().getTargetDirectory ().toFile ());
116+ }
117+ }
118+
88119 private InputStream loadMapResourceAsStream (String filename ) {
89120 return MapsControllerTest .class .getResourceAsStream ("/maps/" + filename );
90121 }
0 commit comments