use of org.apache.wicket.util.tester.WicketTester in project wicket by apache.
the class AnnotatedFieldInBehaviorPage method before.
/**
* @throws Exception
*/
@Before
public void before() throws Exception {
tester = new WicketTester();
ctx = new ApplicationContextMock();
SpringComponentInjector springInjector = new SpringComponentInjector(tester.getApplication(), ctx);
tester.getApplication().getComponentInstantiationListeners().add(springInjector);
}
use of org.apache.wicket.util.tester.WicketTester in project wicket by apache.
the class ArquillianContainerProvidedTest method testNewApplication.
/**
* Test with new application.
*/
@Test
public void testNewApplication() throws MalformedURLException {
setWicketTester(new WicketTester(new TestWicketJavaEEApplication()));
assertNotNull(getWicketTester().getApplication());
log.info("Using mock servletcontext.");
log.info("WebApplication MOCK after wicketTester Name: " + getWicketTester().getApplication().getName());
log.info("ServletContext MOCK after wicketTester Name: " + getWicketTester().getServletContext().getServletContextName());
log.info("Server info: " + getWicketTester().getServletContext().getServerInfo());
assertEquals("Wicket Mock Test Environment v1.0", getWicketTester().getServletContext().getServerInfo());
// USING MOCK.
try {
findResourcesServletContext();
fail("Should not be able to find '/pages/InsertContact.html' in the mocked servlet context");
} catch (IllegalStateException isx) {
assertEquals(RESOURCE_PAGES_INSERT_CONTACT_HTML_NOT_FOUND, isx.getMessage());
}
}
use of org.apache.wicket.util.tester.WicketTester in project wicket by apache.
the class ArquillianContainerProvidedTest method testNewApplicationTryReuseServletContextFilter.
/**
* Creating another application and trying to reuse the ServletContext/Filter.
*/
@Test
public void testNewApplicationTryReuseServletContextFilter() {
try {
log.info("Trying to reuse container's ServletContext/Filter.");
setWicketTester(new WicketTester(new TestWicketJavaEEApplication(), false));
fail("Should not be able to reuse the servlet context");
} catch (IllegalStateException e) {
assertEquals("servletContext is not set yet. Any code in your Application object that uses the wicket filter instance should be put in the init() method instead of your constructor", e.getMessage());
}
assertNull(wicketTester);
}
use of org.apache.wicket.util.tester.WicketTester in project wicket by apache.
the class AnnotationsRoleTest method testNotAuthorized.
/**
* @throws Exception
*/
@Test
public void testNotAuthorized() throws Exception {
WicketTester tester = new WicketTester();
tester.getApplication().getSecuritySettings().setAuthorizationStrategy(new RoleAuthorizationStrategy(new UserRolesAuthorizer("USER")));
final class Listener implements IUnauthorizedComponentInstantiationListener {
private boolean eventReceived = false;
@Override
public void onUnauthorizedInstantiation(Component component) {
eventReceived = true;
}
}
Listener listener = new Listener();
tester.getApplication().getSecuritySettings().setUnauthorizedComponentInstantiationListener(listener);
try {
tester.startPage(AdminPage.class);
assertTrue("an authorization exception event should have been received", listener.eventReceived);
} catch (Exception e) {
if (!(e.getCause() instanceof InvocationTargetException && ((InvocationTargetException) e.getCause()).getTargetException() instanceof UnauthorizedInstantiationException)) {
throw e;
}
}
}
use of org.apache.wicket.util.tester.WicketTester in project wicket by apache.
the class DontStoreNotRenderedPageTestCase method newWicketTester.
@Override
protected WicketTester newWicketTester(WebApplication app) {
app.getComponentInstantiationListeners().add(new IComponentInstantiationListener() {
@Override
public void onInstantiation(Component component) {
// WICKET-5546 behavior added before Page#init()
component.add(new Behavior() {
});
}
});
return new WicketTester(app) {
@Override
protected IPageManagerProvider newTestPageManagerProvider() {
return new IPageManagerProvider() {
@Override
public IPageManager apply(IPageManagerContext context) {
return new MockPageManager() {
@Override
public void touchPage(IManageablePage page) {
Assert.assertFalse("PageB should not be touched!", page instanceof PageB);
super.touchPage(page);
}
};
}
};
}
};
}
Aggregations