Search in sources :

Example 26 with MockApplication

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

the class WicketSessionFilterTest method newApplication.

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

        @Override
        protected void init() {
            super.init();
            // use HttpSessionStore because we need to test it
            setSessionStoreProvider(() -> new HttpSessionStore());
        }
    };
}
Also used : MockApplication(org.apache.wicket.mock.MockApplication) HttpSessionStore(org.apache.wicket.session.HttpSessionStore)

Example 27 with MockApplication

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

the class PageIdPoliticTest method setUp.

@Before
public void setUp() throws Exception {
    application = new MockApplication();
    dataStore = new InMemoryPageStore() {

        @Override
        public void storeData(String sessionId, int pageId, byte[] pageAsBytes) {
            super.storeData(sessionId, pageId, pageAsBytes);
            storeCount++;
        }
    };
    tester = new WicketTester(application) {

        @Override
        protected IPageManagerProvider newTestPageManagerProvider() {
            return new IPageManagerProvider() {

                @Override
                public IPageManager apply(IPageManagerContext pageManagerContext) {
                    IPageStore pageStore = new DefaultPageStore(new JavaSerializer(application.getApplicationKey()), dataStore, 4);
                    return new PageStoreManager(application.getName(), pageStore, pageManagerContext);
                }
            };
        }
    };
}
Also used : IPageStore(org.apache.wicket.pageStore.IPageStore) IPageManager(org.apache.wicket.page.IPageManager) MockApplication(org.apache.wicket.mock.MockApplication) IPageManagerProvider(org.apache.wicket.IPageManagerProvider) JavaSerializer(org.apache.wicket.serialize.java.JavaSerializer) DefaultPageStore(org.apache.wicket.pageStore.DefaultPageStore) PageStoreManager(org.apache.wicket.page.PageStoreManager) WicketTester(org.apache.wicket.util.tester.WicketTester) IPageManagerContext(org.apache.wicket.page.IPageManagerContext) InMemoryPageStore(org.apache.wicket.versioning.InMemoryPageStore) Before(org.junit.Before)

Example 28 with MockApplication

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

the class JavaScriptPackageResourceTest method newApplication.

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

        @Override
        protected void init() {
            super.init();
            getResourceSettings().setJavaScriptCompressor(new IJavaScriptCompressor() {

                @Override
                public String compress(String original) {
                    return APP_COMPRESSED;
                }
            });
        }
    };
}
Also used : MockApplication(org.apache.wicket.mock.MockApplication) IJavaScriptCompressor(org.apache.wicket.javascript.IJavaScriptCompressor)

Example 29 with MockApplication

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

the class LessResourceReferenceTest method newApplication.

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

        @Override
        protected void init() {
            super.init();
            SecurePackageResourceGuard guard = (SecurePackageResourceGuard) getResourceSettings().getPackageResourceGuard();
            guard.addPattern("+*.less");
        }

        /**
         * Register custom ResourceReferenceRegistry that creates LessResourceReference
         * for requests with .less extension
         */
        @Override
        protected ResourceReferenceRegistry newResourceReferenceRegistry() {
            return new ResourceReferenceRegistry(new LessResourceReferenceFactory());
        }
    };
}
Also used : SecurePackageResourceGuard(org.apache.wicket.markup.html.SecurePackageResourceGuard) MockApplication(org.apache.wicket.mock.MockApplication)

Example 30 with MockApplication

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

the class MetaInfStaticResourceReferenceTest method testWithServlet30.

/**
 * Test with Servlet 3.0 container
 *
 * @throws MalformedURLException
 *             should not happen
 */
@Test
public void testWithServlet30() throws MalformedURLException {
    MockApplication application = new MockApplication();
    MockServletContext servletContext = new MockServletContext(application, "/");
    BaseWicketTester tester = new BaseWicketTester(application, servletContext);
    MetaInfStaticResourceReference metaRes = new MetaInfStaticResourceReference(getClass(), STATIC_RESOURCE_NAME);
    PackageResourceReference packRes = new PackageResourceReference(getClass(), STATIC_RESOURCE_NAME);
    Url packUrl = tester.getRequestCycle().mapUrlFor(packRes, null);
    Url metaUrl = tester.getRequestCycle().mapUrlFor(metaRes, null);
    Assert.assertNotNull(metaUrl);
    Assert.assertNotNull(packUrl);
    Assert.assertFalse("Meta and pack resource should not map to the same url under servlet 3.0.", metaUrl.equals(packUrl));
    String metaUrlStr = metaUrl.toString();
    if (metaUrlStr.charAt(1) != '/') {
        metaUrlStr = "/" + metaUrlStr;
    }
    // meta resource is served by the servlet container under 3.0
    URL metaNetUrl = servletContext.getResource(metaUrlStr);
    Assert.assertNotNull("Meta resource is not found by the 3.0 servlet container.", metaNetUrl);
    MockWebRequest request = new MockWebRequest(packUrl);
    IRequestHandler requestHandler = tester.getApplication().getRootRequestMapper().mapRequest(request);
    // the pack resource is still served by wicket
    Assert.assertNotNull(requestHandler);
}
Also used : MockApplication(org.apache.wicket.mock.MockApplication) IRequestHandler(org.apache.wicket.request.IRequestHandler) MockWebRequest(org.apache.wicket.mock.MockWebRequest) BaseWicketTester(org.apache.wicket.util.tester.BaseWicketTester) MockServletContext(org.apache.wicket.protocol.http.mock.MockServletContext) Url(org.apache.wicket.request.Url) URL(java.net.URL) Test(org.junit.Test)

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