Search in sources :

Example 26 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class UrlRendererTest method test9.

/**
 */
@Test
public void test9() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("a/b/q/d/e")));
    assertEquals("../../../q/c/d/e", r1.renderUrl(Url.parse("a/q/c/d/e")));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 27 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class UrlRendererTest method renderFullUrlAsRelativeToAnAbsoluteBaseUrl.

@Test
public void renderFullUrlAsRelativeToAnAbsoluteBaseUrl() {
    Url baseUrl = Url.parse("http://host:8080/contextPath/filterPath/a/b/c/d");
    Url encodedFullUrl = Url.parse("http://host:8080/contextPath/filterPath/a/b;jsessionid=123456");
    UrlRenderer renderer = new UrlRenderer(new MockWebRequest(baseUrl));
    String encodedRelativeUrl = renderer.renderRelativeUrl(encodedFullUrl);
    assertEquals("../../b;jsessionid=123456", encodedRelativeUrl);
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 28 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class UrlRendererTest method removeCommonPrefixesWithJSessionId.

/**
 * https://issues.apache.org/jira/browse/WICKET-5202
 */
@Test
public void removeCommonPrefixesWithJSessionId() {
    Url baseUrl = new Url(Arrays.asList("", "SomePage;jsessionid=1234"), Arrays.<Url.QueryParameter>asList());
    MockWebRequest request = new MockWebRequest(baseUrl);
    request.setContextPath("/");
    request.setFilterPath("filter");
    UrlRenderer renderer = new UrlRenderer(request);
    renderer.setBaseUrl(baseUrl);
    String rendered = renderer.renderRelativeUrl(Url.parse("/filter;jsessionid=1234"));
    assertEquals("../", rendered);
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 29 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class WebSessionTest method readsLocaleFromRequestOnConstruction.

/**
 * testReadsLocaleFromRequestOnConstruction()
 */
@Test
public void readsLocaleFromRequestOnConstruction() {
    final Locale locale = Locale.TRADITIONAL_CHINESE;
    MockWebRequest request = new MockWebRequest(Url.parse("/")) {

        @Override
        public Locale getLocale() {
            return locale;
        }
    };
    WebSession session = new WebSession(request);
    assertEquals(locale, session.getLocale());
}
Also used : Locale(java.util.Locale) MockWebRequest(org.apache.wicket.mock.MockWebRequest) Test(org.junit.Test)

Example 30 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class SessionDestroyTest method whenSessionIsDestroyed_thenItShouldResetItsState.

/**
 * https://issues.apache.org/jira/browse/WICKET-6310
 */
@Test
public void whenSessionIsDestroyed_thenItShouldResetItsState() {
    final Locale locale = Locale.ENGLISH;
    MockWebRequest request = new MockWebRequest(Url.parse("/")) {

        @Override
        public Locale getLocale() {
            return locale;
        }
    };
    final WebSession session = spy(new WebSession(request));
    // initially #invalidateNow() (and destroy()) are not called
    verify(session, never()).invalidateNow();
    assertThat(session.isSessionInvalidated(), is(false));
    // schedule invalidation
    session.invalidate();
    // the invalidation will happen on #detach(), so #destroy() is still not called
    verify(session, never()).invalidateNow();
    assertThat(session.isSessionInvalidated(), is(true));
    session.detach();
    // the session has been detached so #destroy() has been called and 'sessionInvalidated' is reset
    verify(session, times(1)).invalidateNow();
    assertThat(session.isSessionInvalidated(), is(false));
    // no matter how many times #detach() is called #destroy() should not be called
    session.detach();
    verify(session, times(1)).invalidateNow();
    session.detach();
    session.detach();
    verify(session, times(1)).invalidateNow();
    assertThat(session.isSessionInvalidated(), is(false));
}
Also used : Locale(java.util.Locale) MockWebRequest(org.apache.wicket.mock.MockWebRequest) Test(org.junit.Test)

Aggregations

MockWebRequest (org.apache.wicket.mock.MockWebRequest)54 Test (org.junit.Test)52 UrlRenderer (org.apache.wicket.request.UrlRenderer)47 Url (org.apache.wicket.request.Url)29 Locale (java.util.Locale)2 MockServletContext (org.apache.wicket.protocol.http.mock.MockServletContext)2 IRequestHandler (org.apache.wicket.request.IRequestHandler)2 Binder (com.google.inject.Binder)1 Module (com.google.inject.Module)1 Provider (com.google.inject.Provider)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Session (org.apache.wicket.Session)1 MockApplication (org.apache.wicket.mock.MockApplication)1 WebSession (org.apache.wicket.protocol.http.WebSession)1 IExceptionMapper (org.apache.wicket.request.IExceptionMapper)1 IRequestCycle (org.apache.wicket.request.IRequestCycle)1