Java Code Examples for org.springframework.mock.web.test.MockMultipartHttpServletRequest#setCharacterEncoding()
The following examples show how to use
org.springframework.mock.web.test.MockMultipartHttpServletRequest#setCharacterEncoding() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestPartServletServerHttpRequestTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void getBodyViaRequestParameterWithRequestEncoding() throws Exception { MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() { @Override public HttpHeaders getMultipartHeaders(String paramOrFileName) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); return headers; } }; byte[] bytes = {(byte) 0xC4}; mockRequest.setParameter("part", new String(bytes, StandardCharsets.ISO_8859_1)); mockRequest.setCharacterEncoding("iso-8859-1"); ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part"); byte[] result = FileCopyUtils.copyToByteArray(request.getBody()); assertArrayEquals(bytes, result); }
Example 2
Source File: RequestPartServletServerHttpRequestTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void getBodyViaRequestParameterWithRequestEncoding() throws Exception { MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() { @Override public HttpHeaders getMultipartHeaders(String paramOrFileName) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); return headers; } }; byte[] bytes = {(byte) 0xC4}; mockRequest.setParameter("part", new String(bytes, StandardCharsets.ISO_8859_1)); mockRequest.setCharacterEncoding("iso-8859-1"); ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part"); byte[] result = FileCopyUtils.copyToByteArray(request.getBody()); assertArrayEquals(bytes, result); }
Example 3
Source File: RequestPartServletServerHttpRequestTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void getBodyViaRequestParameterWithRequestEncoding() throws Exception { MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() { @Override public HttpHeaders getMultipartHeaders(String paramOrFileName) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); return headers; } }; byte[] bytes = {(byte) 0xC4}; mockRequest.setParameter("part", new String(bytes, Charset.forName("iso-8859-1"))); mockRequest.setCharacterEncoding("iso-8859-1"); ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part"); byte[] result = FileCopyUtils.copyToByteArray(request.getBody()); assertArrayEquals(bytes, result); }