Search in sources :

Example 11 with MockApplication

use of org.apache.wicket.mock.MockApplication 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());
}
Also used : Response(org.apache.wicket.request.Response) MockApplication(org.apache.wicket.mock.MockApplication) Request(org.apache.wicket.request.Request) WicketTester(org.apache.wicket.util.tester.WicketTester) Session(org.apache.wicket.Session) WebSession(org.apache.wicket.protocol.http.WebSession) Test(org.junit.Test)

Example 12 with MockApplication

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

the class LocaleAwarePageParametersTest method newApplication.

@Override
protected WebApplication newApplication() {
    return new MockApplication() {

        @Override
        protected void init() {
            super.init();
            mountPage("unaware", LocaleUnawarePageParametersPage.class);
            mount(new MountedMapper("aware", LocaleAwarePageParametersPage.class) {

                @Override
                protected Locale resolveLocale() {
                    return resolveUserLocale();
                }
            });
        }

        @Override
        public Session newSession(Request request, Response response) {
            final Session session = super.newSession(request, response);
            session.setLocale(Locale.GERMANY);
            return session;
        }
    };
}
Also used : Locale(java.util.Locale) Response(org.apache.wicket.request.Response) MockApplication(org.apache.wicket.mock.MockApplication) Request(org.apache.wicket.request.Request) Session(org.apache.wicket.Session)

Example 13 with MockApplication

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

the class ResourceMapperWithDecoratedResourcesTest method newApplication.

@Override
protected WebApplication newApplication() {
    return new MockApplication() {

        @Override
        public void init() {
            super.init();
            getResourceSettings().setCachingStrategy(new FilenameWithVersionResourceCachingStrategy(new CachingResourceVersion(new MessageDigestResourceVersion())));
            mountResource("stylesheet.css", new CssResourceReference(ResourceMapperWithDecoratedResourcesTest.class, "decorated-resource.css"));
            mountPage("/", HomePage.class);
        }
    };
}
Also used : FilenameWithVersionResourceCachingStrategy(org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy) MockApplication(org.apache.wicket.mock.MockApplication) CachingResourceVersion(org.apache.wicket.request.resource.caching.version.CachingResourceVersion) MessageDigestResourceVersion(org.apache.wicket.request.resource.caching.version.MessageDigestResourceVersion) CssResourceReference(org.apache.wicket.request.resource.CssResourceReference)

Example 14 with MockApplication

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

the class AbstractBookmarkableMapperTest method newApplication.

@Override
protected WebApplication newApplication() {
    return new MockApplication() {

        @Override
        protected void init() {
            super.init();
            getSecuritySettings().setAuthorizationStrategy(new AbstractPageAuthorizationStrategy() {

                @Override
                protected <T extends Page> boolean isPageAuthorized(Class<T> pageClass) {
                    if (pageClass == EmptyPage.class) {
                        throw new RestartResponseAtInterceptPageException(getHomePage());
                    }
                    return true;
                }
            });
        }
    };
}
Also used : EmptyPage(org.apache.wicket.util.tester.WicketTesterLazyIsPageStatelessRedirectToBufferTest.EmptyPage) MockApplication(org.apache.wicket.mock.MockApplication) AbstractPageAuthorizationStrategy(org.apache.wicket.authorization.strategies.page.AbstractPageAuthorizationStrategy) RestartResponseAtInterceptPageException(org.apache.wicket.RestartResponseAtInterceptPageException)

Example 15 with MockApplication

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

the class WebExternalResourceTest method before.

/**
 * @throws Exception
 */
@Before
public void before() throws Exception {
    File tempDir = new File("target/webapp");
    tempDir.mkdir();
    File tempFile = new File(tempDir, "index.html");
    FileOutputStream out = new FileOutputStream(tempFile);
    InputStream in = WebExternalResourceTest.class.getResourceAsStream("index.html");
    Streams.copy(in, out);
    in.close();
    out.close();
    tester = new WicketTester(new MockApplication(), tempDir.getPath());
    // We fake the browser URL, otherwise Wicket doesn't know the requested URL and cannot guess
    // the Content-Type
    tester.getRequest().setURL("index.html");
}
Also used : MockApplication(org.apache.wicket.mock.MockApplication) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) WicketTester(org.apache.wicket.util.tester.WicketTester) File(java.io.File) Before(org.junit.Before)

Aggregations

MockApplication (org.apache.wicket.mock.MockApplication)32 Test (org.junit.Test)14 ResourceSettings (org.apache.wicket.settings.ResourceSettings)6 WicketTester (org.apache.wicket.util.tester.WicketTester)6 Request (org.apache.wicket.request.Request)4 Response (org.apache.wicket.request.Response)4 Before (org.junit.Before)4 FilterChain (javax.servlet.FilterChain)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Session (org.apache.wicket.Session)3 IAuthorizationStrategy (org.apache.wicket.authorization.IAuthorizationStrategy)3 WebApplication (org.apache.wicket.protocol.http.WebApplication)3 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)3 IOException (java.io.IOException)2 Locale (java.util.Locale)2 ServletException (javax.servlet.ServletException)2 ServletRequest (javax.servlet.ServletRequest)2 ServletResponse (javax.servlet.ServletResponse)2 Application (org.apache.wicket.Application)2