java.lang.IllegalArgumentException: Cannot merge with [org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder]

Spring JIRA | Erich Eichinger | 4 years ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    The test below fails with: {panel} java.lang.IllegalArgumentException: Cannot merge with [org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder] at org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder.merge(MockMultipartHttpServletRequestBuilder.java:88) at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:123) {panel} Test: {code} public class FileUploadControllerTest { @Controller public class MyFileUploadController { public static final String MULTIPART_FILEUPLOAD = "/multipartfileupload"; @RequestMapping(value = MULTIPART_FILEUPLOAD, method= RequestMethod.POST) public void multipart_fileupload(@RequestParam MultipartFile file, Model model) throws IOException { model.addAttribute("message", "File '" + file.getOriginalFilename() + "' uploaded successfully: " + new String(file.getBytes())); } } @Test public void fileupload_example() throws Exception { MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new MyFileUploadController()) .defaultRequest(get("/").characterEncoding("utf-8")).build(); mockMvc.perform( fileUpload(MULTIPART_FILEUPLOAD) .file("myfilename", "data".getBytes())) .andExpect(model().attribute("message", "File 'myfilename' uploaded successfully")); } } {code} I'd suggest {{MockMultipartHttpServletRequestBuilder#merge()}} allows to be merged with standard {{MockHttpServletRequestBuilder}} instances.

    Spring JIRA | 4 years ago | Erich Eichinger
    java.lang.IllegalArgumentException: Cannot merge with [org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder]
  2. 0

    The test below fails with: {panel} java.lang.IllegalArgumentException: Cannot merge with [org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder] at org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder.merge(MockMultipartHttpServletRequestBuilder.java:88) at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:123) {panel} Test: {code} public class FileUploadControllerTest { @Controller public class MyFileUploadController { public static final String MULTIPART_FILEUPLOAD = "/multipartfileupload"; @RequestMapping(value = MULTIPART_FILEUPLOAD, method= RequestMethod.POST) public void multipart_fileupload(@RequestParam MultipartFile file, Model model) throws IOException { model.addAttribute("message", "File '" + file.getOriginalFilename() + "' uploaded successfully: " + new String(file.getBytes())); } } @Test public void fileupload_example() throws Exception { MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new MyFileUploadController()) .defaultRequest(get("/").characterEncoding("utf-8")).build(); mockMvc.perform( fileUpload(MULTIPART_FILEUPLOAD) .file("myfilename", "data".getBytes())) .andExpect(model().attribute("message", "File 'myfilename' uploaded successfully")); } } {code} I'd suggest {{MockMultipartHttpServletRequestBuilder#merge()}} allows to be merged with standard {{MockHttpServletRequestBuilder}} instances.

    Spring JIRA | 4 years ago | Erich Eichinger
    java.lang.IllegalArgumentException: Cannot merge with [org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder]

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Cannot merge with [org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder]

      at org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder.merge()
    2. Spring TestContext
      MockMvc.perform
      1. org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder.merge(MockMultipartHttpServletRequestBuilder.java:88)
      2. org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:123)
      2 frames