Search in sources :

Example 16 with BufferedWebResponse

use of org.apache.wicket.protocol.http.BufferedWebResponse in project wicket by apache.

the class WebPageRendererTest method testRedirectToBufferIsFallback.

/**
 * Tests that when all the conditions fail the redirect_to_buffer should be used as a fallback
 */
@Test
public void testRedirectToBufferIsFallback() {
    final AtomicBoolean stored = new AtomicBoolean(false);
    PageRenderer renderer = new TestPageRenderer(handler) {

        @Override
        protected boolean isRedirectToBuffer() {
            return false;
        }

        @Override
        protected boolean isOnePassRender() {
            return false;
        }

        @Override
        protected boolean isRedirectToRender() {
            return false;
        }

        @Override
        protected boolean isSessionTemporary() {
            return false;
        }

        @Override
        protected void storeBufferedResponse(Url url, BufferedWebResponse response) {
            stored.set(true);
        }
    };
    when(page.isPageStateless()).thenReturn(false);
    when(provider.isNewPageInstance()).thenReturn(false);
    // needed for earlier checks
    when(urlRenderer.getBaseUrl()).thenReturn(Url.parse("url1"));
    when(requestCycle.mapUrlFor(eq(handler))).thenReturn(Url.parse("url2"));
    renderer.respond(requestCycle);
    verify(response, never()).write(any(byte[].class));
    verify(response).sendRedirect(isNull());
    Assert.assertTrue(stored.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BufferedWebResponse(org.apache.wicket.protocol.http.BufferedWebResponse) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 17 with BufferedWebResponse

use of org.apache.wicket.protocol.http.BufferedWebResponse in project wicket by apache.

the class WebPageRendererTest method testRedirectToBufferStatefulPage.

/**
 * Tests that when the page is stateful and the urls are different then there should be a
 * redirect
 */
@Test
public void testRedirectToBufferStatefulPage() {
    final AtomicBoolean stored = new AtomicBoolean(false);
    PageRenderer renderer = new TestPageRenderer(handler) {

        @Override
        protected boolean isRedirectToBuffer() {
            return true;
        }

        @Override
        protected void storeBufferedResponse(Url url, BufferedWebResponse response) {
            stored.set(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).sendRedirect(isNull());
    Assert.assertTrue(stored.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BufferedWebResponse(org.apache.wicket.protocol.http.BufferedWebResponse) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

BufferedWebResponse (org.apache.wicket.protocol.http.BufferedWebResponse)17 Url (org.apache.wicket.request.Url)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 Test (org.junit.Test)7 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)6 WebResponse (org.apache.wicket.request.http.WebResponse)4 Application (org.apache.wicket.Application)1 MarkupContainer (org.apache.wicket.MarkupContainer)1 Page (org.apache.wicket.Page)1 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)1 BufferedResponseRequestHandler (org.apache.wicket.core.request.handler.BufferedResponseRequestHandler)1 MockApplication (org.apache.wicket.mock.MockApplication)1 MockWebRequest (org.apache.wicket.mock.MockWebRequest)1 WebApplication (org.apache.wicket.protocol.http.WebApplication)1 IRequestHandler (org.apache.wicket.request.IRequestHandler)1 Request (org.apache.wicket.request.Request)1 Response (org.apache.wicket.request.Response)1 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)1