use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.
the class PackageResourceReferenceTest method makeRangeRequestToBigResource.
private String makeRangeRequestToBigResource(String range) {
ResourceReference reference = new PackageResourceReference(scope, "resource_gt_4096.txt", null, null, null);
ByteArrayResponse byteResponse = new ByteArrayResponse();
Request request = tester.getRequestCycle().getRequest();
MockHttpServletRequest mockHttpServletRequest = (MockHttpServletRequest) request.getContainerRequest();
mockHttpServletRequest.setHeader("range", range);
Attributes mockAttributes = new Attributes(request, byteResponse);
reference.getResource().respond(mockAttributes);
return new String(byteResponse.getBytes());
}
use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.
the class PackageResourceReferenceTest method makeRangeRequest.
private String makeRangeRequest(String range) {
ResourceReference reference = new PackageResourceReference(scope, "resource.txt", locales[1], styles[1], variations[1]);
ByteArrayResponse byteResponse = new ByteArrayResponse();
Request request = tester.getRequestCycle().getRequest();
MockHttpServletRequest mockHttpServletRequest = (MockHttpServletRequest) request.getContainerRequest();
mockHttpServletRequest.setHeader("range", range);
Attributes mockAttributes = new Attributes(request, byteResponse);
reference.getResource().respond(mockAttributes);
return new String(byteResponse.getBytes());
}
use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket-orientdb by OrienteerBAP.
the class WicketOrientDbTester method executeUrl.
public String executeUrl(String _url, final String method, final String content, String username, String password) throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(getApplication(), getHttpSession(), getServletContext()) {
{
setMethod(method);
}
@Override
public ServletInputStream getInputStream() throws IOException {
if (content == null)
return super.getInputStream();
else {
final StringReader sr = new StringReader(content);
return new ServletInputStream() {
@Override
public int read() throws IOException {
return sr.read();
}
};
}
}
};
Url url = Url.parse(_url, Charset.forName(request.getCharacterEncoding()));
request.setUrl(url);
request.setMethod(method);
if (username != null && password != null) {
request.setHeader(LazyAuthorizationRequestCycleListener.AUTHORIZATION_HEADER, "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()));
}
if (!processRequest(request)) {
throw new IOException("Request was not sucessfully sent");
}
MockHttpServletResponse response = getLastResponse();
int status = response.getStatus();
if (status >= HttpServletResponse.SC_OK + 100) {
throw new IOException("Code: " + response.getStatus() + " Message: " + response.getErrorMessage() + " Content: " + response.getDocument());
} else {
return response.getDocument();
}
}
use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.
the class WebApplicationTest method testBodyNotReadBeforeApplicationSetsCharacterEncoding.
/**
* WICKET-6260
*/
@Test
public void testBodyNotReadBeforeApplicationSetsCharacterEncoding() throws Exception {
WebApplication application = tester.getApplication();
HttpServletRequest request = new MockHttpServletRequest(application, null, null) {
@Override
public Map<String, String[]> getParameterMap() {
fail("body should not be read before character encoding is set");
return null;
}
@Override
public String getParameter(String name) {
fail("body should not be read before character encoding is set");
return null;
}
@Override
public Enumeration<String> getParameterNames() {
fail("body should not be read before character encoding is set");
return null;
}
@Override
public String[] getParameterValues(String name) {
fail("body should not be read before character encoding is set");
return null;
}
@Override
public MockRequestParameters getPostParameters() {
fail("body should not be read before character encoding is set");
return null;
}
};
// character encoding not set yet
request.setCharacterEncoding(null);
application.createWebRequest(request, "/");
assertEquals("UTF-8", request.getCharacterEncoding());
}
use of org.apache.wicket.protocol.http.mock.MockHttpServletRequest in project wicket by apache.
the class WicketFilterTest method notModifiedResponseIncludesExpiresHeader.
/**
* @throws IOException
* @throws ServletException
* @throws ParseException
*/
@Test
public void notModifiedResponseIncludesExpiresHeader() throws IOException, ServletException, ParseException {
try {
application = new MockApplication();
WicketFilter filter = new WicketFilter();
filter.init(new FilterTestingConfig());
ThreadContext.setApplication(application);
DynamicImageResource resource = new DynamicImageResource() {
private static final long serialVersionUID = 1L;
@Override
protected byte[] getImageData(Attributes attributes) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
protected ResourceResponse newResourceResponse(Attributes attributes) {
ResourceResponse response = super.newResourceResponse(attributes);
response.setCacheDurationToMaximum();
return response;
}
};
application.getSharedResources().add("foo.gif", resource);
MockHttpServletRequest request = new MockHttpServletRequest(application, null, null);
request.setURL(request.getContextPath() + request.getServletPath() + "/wicket/resource/" + Application.class.getName() + "/foo.gif");
setIfModifiedSinceToNextWeek(request);
MockHttpServletResponse response = new MockHttpServletResponse(request);
filter.doFilter(request, response, new FilterChain() {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
}
});
assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatus());
String responseExpiresHeader = response.getHeader("Expires");
assertNotNull("Expires header must be set on not modified response", responseExpiresHeader);
Date responseExpires = headerDateFormat.parse(responseExpiresHeader);
assertTrue("Expected later than current date but was " + responseExpires, responseExpires.after(new Date()));
} finally {
ThreadContext.detach();
}
}
Aggregations