use of org.apache.wicket.request.cycle.RequestCycle 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.cycle.RequestCycle in project wicket by apache.
the class FilenameWithVersionResourceCachingStrategyTest method testDecorateResponse.
@Test
public void testDecorateResponse() throws Exception {
Duration defaultDuration = Duration.minutes(60);
// setup RequestCycle
BaseWicketTester tester = new BaseWicketTester();
RequestCycle requestCycle = ThreadContext.getRequestCycle();
Application.get().getResourceSettings().setDefaultCacheDuration(defaultDuration);
try {
// version match
requestCycle.setMetaData(IResourceCachingStrategy.URL_VERSION, TEST_RESOURCE_VERSION);
AbstractResource.ResourceResponse response = new AbstractResource.ResourceResponse();
strategy.decorateResponse(response, new TestResource());
assertEquals(WebResponse.MAX_CACHE_DURATION, response.getCacheDuration());
assertEquals(WebResponse.CacheScope.PUBLIC, response.getCacheScope());
// version mismatch
requestCycle.setMetaData(IResourceCachingStrategy.URL_VERSION, "foo");
response = new AbstractResource.ResourceResponse();
strategy.decorateResponse(response, new TestResource());
assertEquals(defaultDuration, response.getCacheDuration());
assertEquals(WebResponse.CacheScope.PRIVATE, response.getCacheScope());
} finally {
tester.destroy();
}
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class WebPageRendererTest method before.
/**
* Common setup
*/
@Before
public void before() {
provider = mock(IPageProvider.class);
page = mock(IRequestablePage.class);
when(provider.getPageInstance()).thenReturn(page);
handler = new RenderPageRequestHandler(provider);
requestCycle = mock(RequestCycle.class);
urlRenderer = mock(UrlRenderer.class);
when(requestCycle.getUrlRenderer()).thenReturn(urlRenderer);
request = mock(WebRequest.class);
when(requestCycle.getRequest()).thenReturn(request);
response = mock(WebResponse.class);
when(requestCycle.getResponse()).thenReturn(response);
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class WebPageRendererTest method testRedirectToBufferNoPageToRender.
/**
* Tests that when during page render another request handler got scheduled. The handler will
* want to overwrite the response, so we need to let it
*/
@Test
public void testRedirectToBufferNoPageToRender() {
final AtomicBoolean stored = new AtomicBoolean(false);
TestPageRenderer renderer = new TestPageRenderer(handler) {
@Override
protected BufferedWebResponse renderPage(Url targetUrl, RequestCycle requestCycle) {
return null;
}
@Override
protected void storeBufferedResponse(Url url, BufferedWebResponse response) {
stored.set(true);
}
};
renderer.redirectToBuffer = true;
// needed for earlier checks
when(urlRenderer.getBaseUrl()).thenReturn(Url.parse("a"));
when(requestCycle.mapUrlFor(eq(handler))).thenReturn(Url.parse("b"));
renderer.respond(requestCycle);
verify(response, never()).write(any(byte[].class));
verify(response, never()).write(any(CharSequence.class));
verify(response, never()).sendRedirect(anyString());
Assert.assertFalse(stored.get());
}
use of org.apache.wicket.request.cycle.RequestCycle in project webanno by webanno.
the class CasStorageServiceImpl method getCache.
private Map<JCasCacheKey, JCasCacheEntry> getCache() {
RequestCycle requestCycle = RequestCycle.get();
Map<JCasCacheKey, JCasCacheEntry> cache = requestCycle.getMetaData(CACHE);
if (cache == null) {
cache = new HashMap<>();
requestCycle.setMetaData(CACHE, cache);
requestCycle.getListeners().add(new AbstractRequestCycleListener() {
@Override
public void onEndRequest(RequestCycle aCycle) {
Map<JCasCacheKey, JCasCacheEntry> _cache = aCycle.getMetaData(CACHE);
if (_cache != null) {
for (Entry<JCasCacheKey, JCasCacheEntry> entry : _cache.entrySet()) {
log.debug("{} - reads: {} writes: {}", entry.getKey(), entry.getValue().reads, entry.getValue().writes);
}
}
}
});
}
return cache;
}
Aggregations