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));
}
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);
}
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;
}
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;
}
Aggregations