Quantcast
Channel: Active questions tagged servlets - Stack Overflow
Viewing all articles
Browse latest Browse all 675

How to use spring's MockMultipartHttpServletRequest? Getting "no multipart boundary was found"

$
0
0

Clearly I'm not using this test fixture right. My servlet works just fine in tomcat, but when I try to use this mock, the multi-part boundary is not found. "the request was rejected because no multipart boundary was found".

There is an answer here that shows how to use this using a text file, but that answer sets the boundary string explicitly and embeds the file as test. I would think I would not need to do with by hand with methods like mockrequest.addFile(...)

What am I not setting here or how I am doing this wrong?

@org.testng.annotations.Testpublic void testDoPost() throws Exception{    MockMultipartFile file = new MockMultipartFile("test.zip", "test.zip", "application/zip", MyServletTest.class.getResourceAsStream("/test.zip"));    MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest();    mockRequest.addFile(file);    mockRequest.set    mockRequest.setMethod("POST");    mockRequest.setParameter("variant", "php");    mockRequest.setParameter("os", "mac");    mockRequest.setParameter("version", "3.4");    MockHttpServletResponse response = new MockHttpServletResponse();    new MyServletTest().doPost(mockRequest, response);    //  BOOM !}

Here is the exception

Caused by: blablah:   the request was rejected because no multipart boundary was found

Viewing all articles
Browse latest Browse all 675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>