/** * Retrieve the string with the serialized (JSON/XML) Object if have one as response. * * @return String with the object serialized */ public String serializedResult() throws Exception { if ("application/xml".equals(response.getContentType())) { return response.getContentAsString(); } if ("application/json".equals(response.getContentType())) { return response.getContentAsString(); } return null; }
@Test public void contentTypeHeaderWithMoreComplexCharsetSyntax() { String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar"; response.setHeader("Content-Type", contentType); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); assertEquals("UTF-8", response.getCharacterEncoding()); response = new MockHttpServletResponse(); response.addHeader("Content-Type", contentType); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); assertEquals("UTF-8", response.getCharacterEncoding()); }
@Test public void contentTypeHeaderUTF8() { String contentType = "test/plain;charset=UTF-8"; response.setHeader("Content-Type", contentType); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); assertEquals("UTF-8", response.getCharacterEncoding()); response = new MockHttpServletResponse(); response.addHeader("Content-Type", contentType); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); assertEquals("UTF-8", response.getCharacterEncoding()); }
@Test public void contentTypeHeader() { String contentType = "test/plain"; response.addHeader("Content-Type", contentType); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); assertEquals(WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding()); response = new MockHttpServletResponse(); response.setHeader("Content-Type", contentType); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); assertEquals(WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding()); }
@Test public void setContentTypeUTF8() { String contentType = "test/plain;charset=UTF-8"; response.setContentType(contentType); assertEquals("UTF-8", response.getCharacterEncoding()); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); }
@Test public void setContentType() { String contentType = "test/plain"; response.setContentType(contentType); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); assertEquals(WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding()); }
@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()); }