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();
}
}
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);
}
};
}
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());
}
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());
}
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);
}
Aggregations