Search in sources :

Example 6 with MockHttpServletRequest

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;
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) MultiFileUploadField(org.apache.wicket.markup.html.form.upload.MultiFileUploadField) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) MultiFileUploadField(org.apache.wicket.markup.html.form.upload.MultiFileUploadField) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField)

Example 7 with MockHttpServletRequest

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, ".");
}
Also used : WebSocketConnectionOriginFilter(org.apache.wicket.protocol.ws.api.WebSocketConnectionOriginFilter) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) WebSocketSettings(org.apache.wicket.protocol.ws.WebSocketSettings)

Example 8 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
 *
 * @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;
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest)

Example 9 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
 *
 * @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;
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest)

Example 10 with MockHttpServletRequest

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 + "/");
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest)

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