Search in sources :

Example 16 with MockApplication

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

the class WicketFilterTest method notModifiedResponseIncludesExpiresHeader.

/**
 * @throws IOException
 * @throws ServletException
 * @throws ParseException
 */
@Test
public void notModifiedResponseIncludesExpiresHeader() throws IOException, ServletException, ParseException {
    try {
        application = new MockApplication();
        WicketFilter filter = new WicketFilter();
        filter.init(new FilterTestingConfig());
        ThreadContext.setApplication(application);
        DynamicImageResource resource = new DynamicImageResource() {

            private static final long serialVersionUID = 1L;

            @Override
            protected byte[] getImageData(Attributes attributes) {
                throw new UnsupportedOperationException("Not implemented");
            }

            @Override
            protected ResourceResponse newResourceResponse(Attributes attributes) {
                ResourceResponse response = super.newResourceResponse(attributes);
                response.setCacheDurationToMaximum();
                return response;
            }
        };
        application.getSharedResources().add("foo.gif", resource);
        MockHttpServletRequest request = new MockHttpServletRequest(application, null, null);
        request.setURL(request.getContextPath() + request.getServletPath() + "/wicket/resource/" + Application.class.getName() + "/foo.gif");
        setIfModifiedSinceToNextWeek(request);
        MockHttpServletResponse response = new MockHttpServletResponse(request);
        filter.doFilter(request, response, new FilterChain() {

            @Override
            public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
            }
        });
        assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatus());
        String responseExpiresHeader = response.getHeader("Expires");
        assertNotNull("Expires header must be set on not modified response", responseExpiresHeader);
        Date responseExpires = headerDateFormat.parse(responseExpiresHeader);
        assertTrue("Expected later than current date but was " + responseExpires, responseExpires.after(new Date()));
    } finally {
        ThreadContext.detach();
    }
}
Also used : DynamicImageResource(org.apache.wicket.request.resource.DynamicImageResource) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) MockHttpServletResponse(org.apache.wicket.protocol.http.mock.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) MockApplication(org.apache.wicket.mock.MockApplication) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) FilterChain(javax.servlet.FilterChain) IOException(java.io.IOException) Date(java.util.Date) ServletException(javax.servlet.ServletException) MockApplication(org.apache.wicket.mock.MockApplication) Application(org.apache.wicket.Application) MockHttpServletResponse(org.apache.wicket.protocol.http.mock.MockHttpServletResponse) Test(org.junit.Test)

Example 17 with MockApplication

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

the class CryptedUrlWebRequestCodingStrategyTest method newApplication.

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

        @Override
        protected void init() {
            super.init();
            // install crypto mapper to encrypt all application urls
            getSecuritySettings().setCryptFactory(new TestCryptFactory());
            CompoundRequestMapper root = new CompoundRequestMapper();
            root.add(new CryptoMapper(getRootRequestMapper(), this));
            setRootRequestMapper(root);
        }
    };
}
Also used : MockApplication(org.apache.wicket.mock.MockApplication) CryptoMapper(org.apache.wicket.core.request.mapper.CryptoMapper) CompoundRequestMapper(org.apache.wicket.request.mapper.CompoundRequestMapper)

Example 18 with MockApplication

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

the class ApplicationSettingsTest method testExceptionOnMissingResourceDefaultValue.

/**
 * @throws Exception
 */
@Test
public void testExceptionOnMissingResourceDefaultValue() throws Exception {
    ResourceSettings settings = new ResourceSettings(new MockApplication());
    Assert.assertTrue("exceptionOnMissingResource should default to true", settings.getThrowExceptionOnMissingResource());
}
Also used : MockApplication(org.apache.wicket.mock.MockApplication) ResourceSettings(org.apache.wicket.settings.ResourceSettings) Test(org.junit.Test)

Example 19 with MockApplication

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

the class ApplicationSettingsTest method testExceptionOnMissingResourceSetsCorrectly.

/**
 * @throws Exception
 */
@Test
public void testExceptionOnMissingResourceSetsCorrectly() throws Exception {
    ResourceSettings settings = new ResourceSettings(new MockApplication());
    settings.setThrowExceptionOnMissingResource(false);
    Assert.assertFalse("exceptionOnMissingResource should have been set to false", settings.getThrowExceptionOnMissingResource());
}
Also used : MockApplication(org.apache.wicket.mock.MockApplication) ResourceSettings(org.apache.wicket.settings.ResourceSettings) Test(org.junit.Test)

Example 20 with MockApplication

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

the class ApplicationSettingsTest method testOverrideStringResourceLoaderSetup.

/**
 */
@Test
public void testOverrideStringResourceLoaderSetup() {
    ResourceSettings settings = new ResourceSettings(new MockApplication());
    settings.getStringResourceLoaders().clear();
    settings.getStringResourceLoaders().add(new BundleStringResourceLoader("org.apache.wicket.resource.DummyResources"));
    settings.getStringResourceLoaders().add(new ComponentStringResourceLoader());
    List<IStringResourceLoader> loaders = settings.getStringResourceLoaders();
    Assert.assertEquals("There should be 2 overridden loaders", 2, loaders.size());
    Assert.assertTrue("First loader one should be the bundle one", loaders.get(0) instanceof BundleStringResourceLoader);
    Assert.assertTrue("Second loader should be the component one", loaders.get(1) instanceof ComponentStringResourceLoader);
}
Also used : ComponentStringResourceLoader(org.apache.wicket.resource.loader.ComponentStringResourceLoader) MockApplication(org.apache.wicket.mock.MockApplication) ResourceSettings(org.apache.wicket.settings.ResourceSettings) IStringResourceLoader(org.apache.wicket.resource.loader.IStringResourceLoader) BundleStringResourceLoader(org.apache.wicket.resource.loader.BundleStringResourceLoader) 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