Search in sources :

Example 21 with MockHttpServletRequest

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

the class FileUploadServletPartTest method uploadServlet30Multipart.

/**
 * Tests support for uploading files with Servlet 3.0 multipart upload
 * https://issues.apache.org/jira/browse/WICKET-5924
 *
 * @throws Exception
 */
@Test
public void uploadServlet30Multipart() throws Exception {
    MockPageWithFormAndUploadField page = tester.startPage(MockPageWithFormAndUploadField.class);
    MockHttpServletRequest httpServletRequest = tester.getRequest();
    FormTester formTester = tester.newFormTester(MockPageWithFormAndUploadField.FORM_ID);
    Servlet3Part part = new Servlet3Part(page.fileUploadField.getInputName());
    httpServletRequest.setPart(MockPageWithFormAndUploadField.FILE_UPLOAD_ID, part);
    formTester.submit();
    page = (MockPageWithFormAndUploadField) tester.getLastRenderedPage();
    FileUpload fileUpload = page.getFileUpload();
    assertArrayEquals(Servlet3Part.DATA, fileUpload.getBytes());
    assertEquals(Servlet3Part.class.getSimpleName(), fileUpload.getClientFileName());
    assertEquals(Servlet3Part.CONTENT_TYPE, fileUpload.getContentType());
    assertArrayEquals(Servlet3Part.DATA, IOUtils.toByteArray(fileUpload.getInputStream()));
    assertThat(part.written.get(), is(nullValue()));
    fileUpload.writeToTempFile();
    assertThat(part.written.get(), is(notNullValue()));
    assertThat(part.deleted.get(), is(false));
    fileUpload.delete();
    assertThat(part.deleted.get(), is(true));
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) FormTester(org.apache.wicket.util.tester.FormTester) Test(org.junit.Test)

Example 22 with MockHttpServletRequest

use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest 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)

Example 23 with MockHttpServletRequest

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

the class TestWebSocketProcessor method createRequest.

/**
 * Creates an HttpServletRequest that is needed by AbstractWebSocketProcessor
 *
 * @return a mock http request
 */
private static MockHttpServletRequest createRequest(final WicketTester wicketTester) {
    Application application = wicketTester.getApplication();
    HttpSession httpSession = wicketTester.getHttpSession();
    MockHttpServletRequest request = new MockHttpServletRequest(application, httpSession, null);
    request.addParameter(WebRequest.PARAM_AJAX_BASE_URL, ".");
    return request;
}
Also used : HttpSession(javax.servlet.http.HttpSession) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) Application(org.apache.wicket.Application) WebApplication(org.apache.wicket.protocol.http.WebApplication)

Example 24 with MockHttpServletRequest

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

the class ApplicationHelper method ensureApplication.

public static IApplication ensureApplication(Long langId) {
    IApplication a = ensureApplication();
    if (ThreadContext.getRequestCycle() == null) {
        ServletWebRequest req = new ServletWebRequest(new MockHttpServletRequest((Application) a, new MockHttpSession(a.getServletContext()), a.getServletContext()), "");
        RequestCycleContext rctx = new RequestCycleContext(req, new MockWebResponse(), a.getRootRequestMapper(), a.getExceptionMapperProvider().get());
        ThreadContext.setRequestCycle(new RequestCycle(rctx));
    }
    if (ThreadContext.getSession() == null) {
        WebSession s = WebSession.get();
        if (langId > 0) {
            ((IWebSession) s).setLanguage(langId);
        }
    }
    return a;
}
Also used : MockWebResponse(org.apache.wicket.mock.MockWebResponse) IApplication(org.apache.openmeetings.IApplication) RequestCycleContext(org.apache.wicket.request.cycle.RequestCycleContext) IWebSession(org.apache.openmeetings.IWebSession) WebSession(org.apache.wicket.protocol.http.WebSession) IWebSession(org.apache.openmeetings.IWebSession) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) MockHttpSession(org.apache.wicket.protocol.http.mock.MockHttpSession) ServletWebRequest(org.apache.wicket.protocol.http.servlet.ServletWebRequest) IApplication(org.apache.openmeetings.IApplication) Application(org.apache.wicket.Application) WebApplication(org.apache.wicket.protocol.http.WebApplication)

Aggregations

MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)24 Test (org.junit.Test)13 MockHttpServletResponse (org.apache.wicket.protocol.http.mock.MockHttpServletResponse)5 Url (org.apache.wicket.request.Url)5 Application (org.apache.wicket.Application)4 IOException (java.io.IOException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)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 MockApplication (org.apache.wicket.mock.MockApplication)2 WebApplication (org.apache.wicket.protocol.http.WebApplication)2 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)2 Request (org.apache.wicket.request.Request)2 Attributes (org.apache.wicket.request.resource.IResource.Attributes)2 UrlAttributes (org.apache.wicket.request.resource.ResourceReference.UrlAttributes)2 ByteArrayResponse (org.apache.wicket.response.ByteArrayResponse)2 StringReader (java.io.StringReader)1