Polishing
This commit is contained in:
@@ -44,8 +44,7 @@ import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequ
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
@@ -65,7 +64,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standal
|
||||
* @author Jaebin Joo
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class MultipartControllerTests {
|
||||
class MultipartControllerTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"/multipartfile", "/multipartfile-via-put", "/part"})
|
||||
@@ -96,14 +95,14 @@ public class MultipartControllerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithSingleFileNotPresent() throws Exception {
|
||||
void multipartRequestWithSingleFileNotPresent() throws Exception {
|
||||
standaloneSetup(new MultipartController()).build()
|
||||
.perform(multipart("/multipartfile"))
|
||||
.andExpect(status().isFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithFileArray() throws Exception {
|
||||
void multipartRequestWithFileArray() throws Exception {
|
||||
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
|
||||
MockMultipartFile filePart1 = new MockMultipartFile("file", "orig", null, fileContent);
|
||||
MockMultipartFile filePart2 = new MockMultipartFile("file", "orig", null, fileContent);
|
||||
@@ -119,21 +118,21 @@ public class MultipartControllerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithFileArrayNotPresent() throws Exception {
|
||||
void multipartRequestWithFileArrayNotPresent() throws Exception {
|
||||
standaloneSetup(new MultipartController()).build()
|
||||
.perform(multipart("/multipartfilearray"))
|
||||
.andExpect(status().isFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithFileArrayNoMultipart() throws Exception {
|
||||
void multipartRequestWithFileArrayNoMultipart() throws Exception {
|
||||
standaloneSetup(new MultipartController()).build()
|
||||
.perform(post("/multipartfilearray"))
|
||||
.andExpect(status().isFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithFileList() throws Exception {
|
||||
void multipartRequestWithFileList() throws Exception {
|
||||
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
|
||||
MockMultipartFile filePart1 = new MockMultipartFile("file", "orig", null, fileContent);
|
||||
MockMultipartFile filePart2 = new MockMultipartFile("file", "orig", null, fileContent);
|
||||
@@ -149,21 +148,21 @@ public class MultipartControllerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithFileListNotPresent() throws Exception {
|
||||
void multipartRequestWithFileListNotPresent() throws Exception {
|
||||
standaloneSetup(new MultipartController()).build()
|
||||
.perform(multipart("/multipartfilelist"))
|
||||
.andExpect(status().isFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithFileListNoMultipart() throws Exception {
|
||||
void multipartRequestWithFileListNoMultipart() throws Exception {
|
||||
standaloneSetup(new MultipartController()).build()
|
||||
.perform(post("/multipartfilelist"))
|
||||
.andExpect(status().isFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithOptionalFile() throws Exception {
|
||||
void multipartRequestWithOptionalFile() throws Exception {
|
||||
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
|
||||
MockMultipartFile filePart = new MockMultipartFile("file", "orig", null, fileContent);
|
||||
|
||||
@@ -178,7 +177,7 @@ public class MultipartControllerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithOptionalFileNotPresent() throws Exception {
|
||||
void multipartRequestWithOptionalFileNotPresent() throws Exception {
|
||||
byte[] json = "{\"name\":\"yeeeah\"}".getBytes(StandardCharsets.UTF_8);
|
||||
MockMultipartFile jsonPart = new MockMultipartFile("json", "json", "application/json", json);
|
||||
|
||||
@@ -190,7 +189,7 @@ public class MultipartControllerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithOptionalFileArray() throws Exception {
|
||||
void multipartRequestWithOptionalFileArray() throws Exception {
|
||||
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
|
||||
MockMultipartFile filePart1 = new MockMultipartFile("file", "orig", null, fileContent);
|
||||
MockMultipartFile filePart2 = new MockMultipartFile("file", "orig", null, fileContent);
|
||||
@@ -206,7 +205,7 @@ public class MultipartControllerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithOptionalFileArrayNotPresent() throws Exception {
|
||||
void multipartRequestWithOptionalFileArrayNotPresent() throws Exception {
|
||||
byte[] json = "{\"name\":\"yeeeah\"}".getBytes(StandardCharsets.UTF_8);
|
||||
MockMultipartFile jsonPart = new MockMultipartFile("json", "json", "application/json", json);
|
||||
|
||||
@@ -218,7 +217,7 @@ public class MultipartControllerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithOptionalFileList() throws Exception {
|
||||
void multipartRequestWithOptionalFileList() throws Exception {
|
||||
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
|
||||
MockMultipartFile filePart1 = new MockMultipartFile("file", "orig", null, fileContent);
|
||||
MockMultipartFile filePart2 = new MockMultipartFile("file", "orig", null, fileContent);
|
||||
@@ -234,7 +233,7 @@ public class MultipartControllerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithOptionalFileListNotPresent() throws Exception {
|
||||
void multipartRequestWithOptionalFileListNotPresent() throws Exception {
|
||||
byte[] json = "{\"name\":\"yeeeah\"}".getBytes(StandardCharsets.UTF_8);
|
||||
MockMultipartFile jsonPart = new MockMultipartFile("json", "json", "application/json", json);
|
||||
|
||||
@@ -246,7 +245,7 @@ public class MultipartControllerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartRequestWithDataBindingToFile() throws Exception {
|
||||
void multipartRequestWithDataBindingToFile() throws Exception {
|
||||
byte[] fileContent = "bar".getBytes(StandardCharsets.UTF_8);
|
||||
MockPart filePart = new MockPart("file", "orig", fileContent);
|
||||
|
||||
@@ -257,7 +256,7 @@ public class MultipartControllerTests {
|
||||
}
|
||||
|
||||
@Test // SPR-13317
|
||||
public void multipartRequestWrapped() throws Exception {
|
||||
void multipartRequestWrapped() throws Exception {
|
||||
byte[] json = "{\"name\":\"yeeeah\"}".getBytes(StandardCharsets.UTF_8);
|
||||
MockMultipartFile jsonPart = new MockMultipartFile("json", "json", "application/json", json);
|
||||
|
||||
@@ -272,7 +271,7 @@ public class MultipartControllerTests {
|
||||
@Controller
|
||||
private static class MultipartController {
|
||||
|
||||
@RequestMapping(value = "/multipartfile", method = RequestMethod.POST)
|
||||
@PostMapping("/multipartfile")
|
||||
public String processMultipartFile(@RequestParam(required = false) MultipartFile file,
|
||||
@RequestPart(required = false) Map<String, String> json, Model model) throws IOException {
|
||||
|
||||
@@ -286,7 +285,6 @@ public class MultipartControllerTests {
|
||||
return "redirect:/index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/multipartfilearray", method = RequestMethod.POST)
|
||||
@PutMapping("/multipartfile-via-put")
|
||||
public String processMultipartFileViaHttpPut(@RequestParam(required = false) MultipartFile file,
|
||||
@RequestPart(required = false) Map<String, String> json, Model model) throws IOException {
|
||||
@@ -294,6 +292,7 @@ public class MultipartControllerTests {
|
||||
return processMultipartFile(file, json, model);
|
||||
}
|
||||
|
||||
@PostMapping("/multipartfilearray")
|
||||
public String processMultipartFileArray(@RequestParam(required = false) MultipartFile[] file,
|
||||
@RequestPart(required = false) Map<String, String> json, Model model) throws IOException {
|
||||
|
||||
@@ -309,7 +308,7 @@ public class MultipartControllerTests {
|
||||
return "redirect:/index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/multipartfilelist", method = RequestMethod.POST)
|
||||
@PostMapping("/multipartfilelist")
|
||||
public String processMultipartFileList(@RequestParam(required = false) List<MultipartFile> file,
|
||||
@RequestPart(required = false) Map<String, String> json, Model model) throws IOException {
|
||||
|
||||
@@ -325,7 +324,7 @@ public class MultipartControllerTests {
|
||||
return "redirect:/index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/optionalfile", method = RequestMethod.POST)
|
||||
@PostMapping("/optionalfile")
|
||||
public String processOptionalFile(@RequestParam Optional<MultipartFile> file,
|
||||
@RequestPart Map<String, String> json, Model model) throws IOException {
|
||||
|
||||
@@ -337,7 +336,7 @@ public class MultipartControllerTests {
|
||||
return "redirect:/index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/optionalfilearray", method = RequestMethod.POST)
|
||||
@PostMapping("/optionalfilearray")
|
||||
public String processOptionalFileArray(@RequestParam Optional<MultipartFile[]> file,
|
||||
@RequestPart Map<String, String> json, Model model) throws IOException {
|
||||
|
||||
@@ -351,7 +350,7 @@ public class MultipartControllerTests {
|
||||
return "redirect:/index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/optionalfilelist", method = RequestMethod.POST)
|
||||
@PostMapping("/optionalfilelist")
|
||||
public String processOptionalFileList(@RequestParam Optional<List<MultipartFile>> file,
|
||||
@RequestPart Map<String, String> json, Model model) throws IOException {
|
||||
|
||||
@@ -365,7 +364,7 @@ public class MultipartControllerTests {
|
||||
return "redirect:/index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/part", method = RequestMethod.POST)
|
||||
@PostMapping("/part")
|
||||
public String processPart(@RequestPart Part part,
|
||||
@RequestPart Map<String, String> json, Model model) throws IOException {
|
||||
|
||||
@@ -378,13 +377,13 @@ public class MultipartControllerTests {
|
||||
return "redirect:/index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/json", method = RequestMethod.POST)
|
||||
@PostMapping("/json")
|
||||
public String processMultipart(@RequestPart Map<String, String> json, Model model) {
|
||||
model.addAttribute("json", json);
|
||||
return "redirect:/index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/multipartfilebinding", method = RequestMethod.POST)
|
||||
@PostMapping("/multipartfilebinding")
|
||||
public String processMultipartFileBean(
|
||||
MultipartFileBean multipartFileBean, Model model, BindingResult bindingResult) throws IOException {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user