use of org.apache.wicket.request.Response in project wicket by apache.
the class HeaderResponseTest method before.
/**
* Prepare
*/
@Before
public void before() {
final Response realResponse = new StringResponse();
headerResponse = new HeaderResponse() {
@Override
protected Response getRealResponse() {
return realResponse;
}
};
reference = new ResourceReference("testReference") {
private static final long serialVersionUID = 1L;
@Override
public IResource getResource() {
return null;
}
};
RequestCycle requestCycle = mock(RequestCycle.class);
when(requestCycle.urlFor(any(IRequestHandler.class))).thenReturn(RESOURCE_NAME);
when(requestCycle.find(any())).thenReturn(Optional.empty());
Request request = mock(Request.class);
when(request.getCharset()).thenReturn(Charset.defaultCharset());
when(requestCycle.getRequest()).thenReturn(request);
UrlRenderer urlRenderer = mock(UrlRenderer.class);
when(urlRenderer.renderContextRelativeUrl((any(String.class)))).thenReturn(RESOURCE_NAME);
when(requestCycle.getUrlRenderer()).thenReturn(urlRenderer);
ThreadContext.setRequestCycle(requestCycle);
}
use of org.apache.wicket.request.Response in project wicket by apache.
the class RequestCycleUrlForTest method before.
@Before
public void before() {
Request request = mock(Request.class);
Url baseUrl = Url.parse("");
when(request.getClientUrl()).thenReturn(baseUrl);
Response response = new StringResponse() {
@Override
public String encodeURL(CharSequence url) {
return url + JSESSIONID;
}
};
IRequestMapper mapper = mock(IRequestMapper.class);
Url bookmarkablePageUrl = Url.parse(BOOKMARKABLE_PAGE_URL);
when(mapper.mapHandler(argThat(new ExactClassMatcher<BookmarkablePageRequestHandler>(BookmarkablePageRequestHandler.class)))).thenReturn(bookmarkablePageUrl);
Url resourceUrl = Url.parse(RESOURCE_URL);
when(mapper.mapHandler(argThat(new ExactClassMatcher<ResourceRequestHandler>(ResourceRequestHandler.class)))).thenReturn(resourceUrl);
Url resourceReferenceUrl = Url.parse(RES_REF_URL);
when(mapper.mapHandler(argThat(new ExactClassMatcher<ResourceReferenceRequestHandler>(ResourceReferenceRequestHandler.class)))).thenReturn(resourceReferenceUrl);
IExceptionMapper exceptionMapper = mock(IExceptionMapper.class);
RequestCycleContext context = new RequestCycleContext(request, response, mapper, exceptionMapper);
requestCycle = new RequestCycle(context);
requestCycle.getUrlRenderer().setBaseUrl(baseUrl);
}
use of org.apache.wicket.request.Response in project wicket by apache.
the class PackageResourceReferenceTest method testContentRangeHeaders.
/**
* See WICKET-5819 - Media tags
*/
@Test
public void testContentRangeHeaders() {
// Test header fields
ResourceReference reference = new PackageResourceReference(scope, "resource.txt", locales[1], styles[1], variations[1]);
Request request = tester.getRequestCycle().getRequest();
Response response = tester.getRequestCycle().getResponse();
MockHttpServletResponse mockHttpServletResponse = (MockHttpServletResponse) response.getContainerResponse();
Attributes mockAttributes = new Attributes(request, response);
reference.getResource().respond(mockAttributes);
Assert.assertEquals(ContentRangeType.BYTES.getTypeName(), mockHttpServletResponse.getHeader("Accept-Range"));
// For normal: If a resource supports content range no content is delivered
// if no "Range" header is given, but we have to deliver it, because
// other resources then media should get the content. (e.g. CSS, JS, etc.) Browsers
// detecting media requests and automatically add the "Range" header for
// partial content and they don't make an initial request to detect if a media
// resource supports Content-Range (by the Accept-Range header)
Assert.assertEquals("resource_var_style_en.txt", new String(mockHttpServletResponse.getBinaryContent()));
}
use of org.apache.wicket.request.Response in project wicket by apache.
the class FilteringHeaderResponseTest method createBucketOnTheFlyForFilteredHeaderItem.
/**
* https://issues.apache.org/jira/browse/WICKET-5057
* @throws Exception
*/
@Test
public void createBucketOnTheFlyForFilteredHeaderItem() throws Exception {
try (FilteringHeaderResponse headerResponse = new FilteringHeaderResponse(new HeaderResponse() {
@Override
protected Response getRealResponse() {
return new StringResponse();
}
}, "headerBucketName", Collections.emptyList())) {
String filterName = "filterName";
String headerContent = "content";
FilteredHeaderItem item = new FilteredHeaderItem(StringHeaderItem.forString(headerContent), filterName);
headerResponse.render(item);
CharSequence realContent = headerResponse.getContent(filterName);
assertEquals(headerContent, realContent.toString());
}
}
use of org.apache.wicket.request.Response in project wicket by apache.
the class SessionSizeModelTest method testToleranceOnProblematicSessions.
/**
* @see <a href="https://issues.apache.org/jira/browse/WICKET-3355">WICKET-3355</a>
*/
@Test
public void testToleranceOnProblematicSessions() {
new WicketTester(new MockApplication() {
@Override
public Session newSession(final Request request, final Response response) {
return new TestSession(request);
}
});
SessionSizeModel model = new SessionSizeModel();
assertEquals(null, model.getObject());
}
Aggregations