use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.
the class FormTester method setFile.
/**
* Sets the <code>File</code> on a {@link FileUploadField}.
*
* @param formComponentId
* relative path (from <code>Form</code>) to the selectable
* <code>FormComponent</code>. The <code>FormComponent</code> must be of a type
* <code>FileUploadField</code>.
* @param file
* the <code>File</code> to upload or {@code null} for an empty input
* @param contentType
* the content type of the file. Must be a valid mime type.
* @return This
*/
public FormTester setFile(final String formComponentId, final File file, final String contentType) {
checkClosed();
FormComponent<?> formComponent = (FormComponent<?>) workingForm.get(formComponentId);
MockHttpServletRequest servletRequest = tester.getRequest();
if (formComponent instanceof FileUploadField) {
servletRequest.addFile(formComponent.getInputName(), file, contentType);
} else if (formComponent instanceof MultiFileUploadField) {
String inputName = formComponent.getInputName() + MultiFileUploadField.MAGIC_SEPARATOR + multiFileUploadIndex++;
servletRequest.addFile(inputName, file, contentType);
} else {
fail("'" + formComponentId + "' is not " + "a FileUploadField. You can only attach a file to form " + "component of this type.");
}
return this;
}
use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.
the class WebSocketTesterProcessorTest method configureRequest.
protected void configureRequest(String[] allowedDomains, String[] origins) {
WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(application);
WebSocketConnectionOriginFilter connectionFilter = new WebSocketConnectionOriginFilter(Arrays.asList(allowedDomains));
webSocketSettings.setConnectionFilter(connectionFilter);
MockHttpServletRequest request = tester.getRequest();
for (String origin : origins) {
request.addHeader("Origin", origin);
}
request.addParameter("resourceName", TestWebSocketResource.TEXT);
request.addParameter(WebRequest.PARAM_AJAX_BASE_URL, ".");
}
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
*
* @param page
* the page that may have registered {@link org.apache.wicket.protocol.ws.api.WebSocketBehavior}
* @return a mock http request
*/
private static HttpServletRequest createRequest(final WicketTester wicketTester, final Page page) {
Args.notNull(page, "page");
MockHttpServletRequest request = createRequest(wicketTester);
request.addParameter("pageId", page.getId());
return request;
}
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
*
* @param resourceName
* the page that may have registered {@link org.apache.wicket.protocol.ws.api.WebSocketBehavior}
* @return a mock http request
*/
private static HttpServletRequest createRequest(final WicketTester wicketTester, final String resourceName) {
Args.notNull(resourceName, "resourceName");
MockHttpServletRequest request = createRequest(wicketTester);
request.addParameter("resourceName", resourceName);
return request;
}
use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.
the class CustomHomePageTest method requestHomePage.
private void requestHomePage(final WicketTester tester) {
MockHttpServletRequest request = tester.getRequest();
String contextPath = request.getContextPath();
String filterPrefix = request.getFilterPrefix();
tester.executeUrl(contextPath + "/" + filterPrefix + "/");
}
Aggregations