use of org.apache.wicket.mock.MockApplication in project wicket by apache.
the class AjaxBehaviorEnabledTest method before.
/**
*/
@Before
public void before() {
final IAuthorizationStrategy strategy = new CustomStrategy();
tester = new WicketTester(new MockApplication() {
@Override
public Session newSession(Request request, Response response) {
return new WebSession(request) {
private static final long serialVersionUID = 1L;
@Override
public IAuthorizationStrategy getAuthorizationStrategy() {
return strategy;
}
};
}
});
}
use of org.apache.wicket.mock.MockApplication in project wicket by apache.
the class WicketFilterTest method ignorePaths.
/**
* <a href="https://issues.apache.org/jira/browse/WICKET-3750">WICKET-3750</a>
*
* @throws Exception
*/
@Test
public void ignorePaths() throws Exception {
application = spy(new MockApplication());
WicketFilter filter = new WicketFilter();
filter.init(new FilterTestingConfig());
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getLocale()).thenReturn(new Locale("bg", "BG"));
when(request.getRequestURI()).thenReturn("/contextPath/js/bla.js").thenReturn("/contextPath/css/bla.css").thenReturn("/contextPath/images/bla.img").thenReturn("/contextPath/servlet/wicket/bookmarkable/" + DummyHomePage.class.getName());
when(request.getContextPath()).thenReturn("/contextPath");
when(request.getMethod()).thenReturn("POST");
HttpServletResponse response = mock(HttpServletResponse.class);
when(response.encodeRedirectURL(Matchers.anyString())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return (String) invocation.getArguments()[0];
}
});
FilterChain chain = mock(FilterChain.class);
// execute 3 requests - 1 for bla.js, 1 for bla.css and 1 for bla.img
for (int i = 0; i < 3; i++) {
boolean isProcessed = filter.processRequest(request, response, chain);
assertFalse(isProcessed);
verify(application, Mockito.never()).newWebRequest(Matchers.eq(request), Matchers.anyString());
verify(application, Mockito.never()).newWebResponse(Matchers.any(WebRequest.class), Matchers.eq(response));
verify(chain, Mockito.times(i + 1)).doFilter(request, response);
}
// execute the request to /something/real
boolean isProcessed = filter.processRequest(request, response, chain);
assertTrue(isProcessed);
verify(application).newWebRequest(Matchers.eq(request), Matchers.anyString());
verify(application).newWebResponse(Matchers.any(WebRequest.class), Matchers.eq(response));
// the request is processed so the chain is not executed
verify(chain, Mockito.times(3)).doFilter(request, response);
}
use of org.apache.wicket.mock.MockApplication in project wicket by apache.
the class WicketFilterTest method options.
@Test
public void options() throws IOException, ServletException, ParseException {
try {
application = new MockApplication();
WicketFilter filter = new WicketFilter();
filter.init(new FilterTestingConfig());
ThreadContext.setApplication(application);
final String failure = "Should never get here when an OPTIONS request is issued";
IResource resource = new AbstractResource() {
@Override
protected ResourceResponse newResourceResponse(Attributes attributes) {
fail(failure);
return null;
}
};
application.getSharedResources().add("foo.txt", resource);
// check OPTIONS request is processed correctly
MockHttpServletRequest request = new MockHttpServletRequest(application, null, null);
request.setURL(request.getContextPath() + request.getServletPath() + "/wicket/resource/" + Application.class.getName() + "/foo.txt");
// test that we do not care about case
request.setMethod("OPtioNS");
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_OK, response.getStatus());
assertEquals("0", response.getHeader("Content-Length"));
assertFalse(Strings.isEmpty(response.getHeader("Allow")));
assertTrue(response.getHeader("Allow").toUpperCase().contains("GET"));
assertTrue(response.getHeader("Allow").toUpperCase().contains("POST"));
// try with a GET request to make sure we fail correctly
request = new MockHttpServletRequest(application, null, null);
request.setURL(request.getContextPath() + request.getServletPath() + "/wicket/resource/" + Application.class.getName() + "/foo.txt");
response = new MockHttpServletResponse(request);
try {
filter.doFilter(request, response, new FilterChain() {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
}
});
} catch (AssertionError e) {
assertTrue(failure.equals(e.getMessage()));
}
} finally {
ThreadContext.detach();
}
}
use of org.apache.wicket.mock.MockApplication in project wicket by apache.
the class InterceptTest method newApplication.
@Override
protected WebApplication newApplication() {
return new MockApplication() {
@Override
protected void init() {
getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy.AllowAllAuthorizationStrategy() {
private boolean block = true;
@Override
public <T extends IRequestableComponent> boolean isInstantiationAuthorized(Class<T> componentClass) {
if (block && (componentClass == TargetPage.class || componentClass == HomePage.class)) {
block = false;
throw new RestartResponseAtInterceptPageException(InterceptPage.class);
}
return true;
}
});
super.init();
}
@Override
public Class<? extends Page> getHomePage() {
return HomePage.class;
}
};
}
use of org.apache.wicket.mock.MockApplication in project wicket by apache.
the class ApplicationSettingsTest method testDefaultStringResourceLoaderSetup.
/**
*/
@Test
public void testDefaultStringResourceLoaderSetup() {
ResourceSettings settings = new ResourceSettings(new MockApplication());
List<IStringResourceLoader> loaders = settings.getStringResourceLoaders();
Assert.assertEquals("There should be 5 default loaders", 5, loaders.size());
Assert.assertTrue("First loader one should be the component one", loaders.get(0) instanceof ComponentStringResourceLoader);
Assert.assertTrue("Second loader should be the package one", loaders.get(1) instanceof PackageStringResourceLoader);
Assert.assertTrue("Third loader should be the application one", loaders.get(2) instanceof ClassStringResourceLoader);
Assert.assertTrue("Fourth loader should be the validator one", loaders.get(3) instanceof ValidatorStringResourceLoader);
Assert.assertTrue("Fifth should be the initializer one", loaders.get(4) instanceof InitializerStringResourceLoader);
}
Aggregations