@Test public void printResponseWithCharacterEncoding() throws Exception { this.response.setCharacterEncoding("UTF-8"); this.response.getWriter().print("text"); this.handler.handle(this.mvcResult); assertValue("MockHttpServletResponse", "Body", "text"); }
@Test public void printResponseWithoutCharacterEncoding() throws Exception { this.response.setCharacterEncoding(null); this.response.getWriter().print("text"); this.handler.handle(this.mvcResult); assertValue("MockHttpServletResponse", "Body", "<no character encoding set>"); }
protected MockHttpServletResponse dispatch(HttpServletRequest request, String charset) throws Exception { MockHttpServletResponse response = null; if (charset == null) { charset = Charset.defaultCharset().name(); } response = new MockHttpServletResponse(); response.setCharacterEncoding(charset); dispatch(request, response); this.lastResponse = response; return response; }
protected MockHttpServletResponse dispatch(HttpServletRequest request, String charset) throws Exception { MockHttpServletResponse response = null; if (charset == null) { response = new MockHttpServletResponse() { public void setCharacterEncoding(String encoding) {} }; } else { response = new MockHttpServletResponse(); response.setCharacterEncoding(charset); } dispatch(request, response); return response; }
@Test public void setCharacterEncodingThenContentType() { response.setCharacterEncoding("UTF-8"); response.setContentType("test/plain"); assertEquals("test/plain", response.getContentType()); assertEquals("test/plain;charset=UTF-8", response.getHeader("Content-Type")); assertEquals("UTF-8", response.getCharacterEncoding()); }
@Test public void setContentTypeThenCharacterEncoding() { response.setContentType("test/plain"); response.setCharacterEncoding("UTF-8"); assertEquals("test/plain", response.getContentType()); assertEquals("test/plain;charset=UTF-8", response.getHeader("Content-Type")); assertEquals("UTF-8", response.getCharacterEncoding()); }
public ServletResponseFactory() { mockResponse.setCharacterEncoding("UTF-8"); }
protected static MockHttpServletResponse createResponse() { final MockHttpServletResponse response = new MockHttpServletResponse(); response.setCharacterEncoding(StandardCharsets.UTF_8.name()); return response; }
/** * Apply the action on the given result. * * @param result the result of the executed request * @throws Exception if a failure occurs */ @Override public void handle(MvcResult result) throws Exception { MockHttpServletResponse response = result.getResponse(); response.setCharacterEncoding(encoding); String swaggerJson = response.getContentAsString(); Swagger2MarkupConverter.fromString(swaggerJson).withMarkupLanguage(markupLanguage) .withPathsGroupedBy(this.pathsGroupedBy) .withExamples(examplesFolderPath).build().intoFolder(outputDir); }