Merge branch '5.3.x'
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,8 +38,8 @@ import org.springframework.test.web.reactive.server.EntityExchangeResult;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.test.web.servlet.client.MockMvcWebTestClient;
|
||||
import org.springframework.ui.Model;
|
||||
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;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
@@ -79,6 +79,18 @@ public class MultipartControllerTests {
|
||||
MockMvcWebTestClient.resultActionsFor(exchangeResult)
|
||||
.andExpect(model().attribute("fileContent", fileContent))
|
||||
.andExpect(model().attribute("jsonContent", json));
|
||||
|
||||
// Now try the same with HTTP PUT
|
||||
exchangeResult = testClient.put().uri("/multipartfile-via-put")
|
||||
.bodyValue(bodyBuilder.build())
|
||||
.exchange()
|
||||
.expectStatus().isFound()
|
||||
.expectBody().isEmpty();
|
||||
|
||||
// Further assertions on the server response
|
||||
MockMvcWebTestClient.resultActionsFor(exchangeResult)
|
||||
.andExpect(model().attribute("fileContent", fileContent))
|
||||
.andExpect(model().attribute("jsonContent", json));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -283,10 +295,11 @@ public class MultipartControllerTests {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||
@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 {
|
||||
|
||||
@@ -300,7 +313,14 @@ 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 {
|
||||
|
||||
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 {
|
||||
|
||||
@@ -316,7 +336,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 {
|
||||
|
||||
@@ -332,7 +352,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 {
|
||||
|
||||
@@ -344,7 +364,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 {
|
||||
|
||||
@@ -358,7 +378,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 {
|
||||
|
||||
@@ -372,7 +392,7 @@ public class MultipartControllerTests {
|
||||
return "redirect:/index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/part", method = RequestMethod.POST)
|
||||
@PostMapping("/part")
|
||||
public String processPart(@RequestParam Part part,
|
||||
@RequestPart Map<String, String> json, Model model) throws IOException {
|
||||
|
||||
@@ -382,7 +402,7 @@ 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";
|
||||
|
||||
Reference in New Issue
Block a user