Search in sources :

Example 11 with MockHttpServletResponse

use of org.apache.wicket.protocol.http.mock.MockHttpServletResponse in project wicket by apache.

the class ServletWebResponseTest method setDispositionHeader.

/**
 * WICKET-4934 DownloadLink uses wrong encoding for spaces/non-ASCII characters
 */
@Test
public void setDispositionHeader() {
    ServletWebRequest webRequest = mock(ServletWebRequest.class);
    MockHttpServletRequest httpRequest = mock(MockHttpServletRequest.class);
    HttpServletResponse httpResponse = new MockHttpServletResponse(httpRequest);
    ServletWebResponse response = new ServletWebResponse(webRequest, httpResponse);
    response.setInlineHeader("name with spaces and;,");
    String header = httpResponse.getHeader("Content-Disposition");
    assertEquals("inline; filename=\"name%20with%20spaces%20and%3B%2C\"; filename*=UTF-8''name%20with%20spaces%20and%3B%2C", header);
    // says: "name with bulgarian"
    response.setInlineHeader("name with български");
    header = httpResponse.getHeader("Content-Disposition");
    assertEquals("inline; filename=\"name%20with%20%D0%B1%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D1%81%D0%BA%D0%B8\"; filename*=UTF-8''name%20with%20%D0%B1%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D1%81%D0%BA%D0%B8", header);
    response.setAttachmentHeader("name with spaces");
    header = httpResponse.getHeader("Content-Disposition");
    assertEquals("attachment; filename=\"name%20with%20spaces\"; filename*=UTF-8''name%20with%20spaces", header);
    // says: "name with bulgarian"
    response.setAttachmentHeader("name with български");
    header = httpResponse.getHeader("Content-Disposition");
    assertEquals("attachment; filename=\"name%20with%20%D0%B1%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D1%81%D0%BA%D0%B8\"; filename*=UTF-8''name%20with%20%D0%B1%D1%8A%D0%BB%D0%B3%D0%B0%D1%80%D1%81%D0%BA%D0%B8", header);
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) MockHttpServletResponse(org.apache.wicket.protocol.http.mock.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(org.apache.wicket.protocol.http.mock.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

MockHttpServletResponse (org.apache.wicket.protocol.http.mock.MockHttpServletResponse)11 Test (org.junit.Test)9 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)6 IOException (java.io.IOException)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 FilterChain (javax.servlet.FilterChain)2 ServletException (javax.servlet.ServletException)2 ServletRequest (javax.servlet.ServletRequest)2 ServletResponse (javax.servlet.ServletResponse)2 Cookie (javax.servlet.http.Cookie)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Application (org.apache.wicket.Application)2 MockApplication (org.apache.wicket.mock.MockApplication)2 WicketTester (org.apache.wicket.util.tester.WicketTester)2 StringReader (java.io.StringReader)1 Date (java.util.Date)1 ServletInputStream (javax.servlet.ServletInputStream)1 CookieCollection (org.apache.wicket.protocol.http.mock.CookieCollection)1 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)1 Request (org.apache.wicket.request.Request)1