Search in sources :

Example 71 with WicketTester

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);
}
Also used : ApplicationContextMock(org.apache.wicket.spring.test.ApplicationContextMock) WicketTester(org.apache.wicket.util.tester.WicketTester) Before(org.junit.Before)

Example 72 with WicketTester

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());
    }
}
Also used : WicketTester(org.apache.wicket.util.tester.WicketTester) TestWicketJavaEEApplication(org.apache.wicket.arquillian.testing.TestWicketJavaEEApplication) AbstractDeploymentTest(org.apache.wicket.arquillian.testing.deployment.AbstractDeploymentTest) Test(org.junit.Test)

Example 73 with WicketTester

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);
}
Also used : WicketTester(org.apache.wicket.util.tester.WicketTester) TestWicketJavaEEApplication(org.apache.wicket.arquillian.testing.TestWicketJavaEEApplication) AbstractDeploymentTest(org.apache.wicket.arquillian.testing.deployment.AbstractDeploymentTest) Test(org.junit.Test)

Example 74 with 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;
        }
    }
}
Also used : IUnauthorizedComponentInstantiationListener(org.apache.wicket.authorization.IUnauthorizedComponentInstantiationListener) RoleAuthorizationStrategy(org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy) WicketTester(org.apache.wicket.util.tester.WicketTester) IUnauthorizedComponentInstantiationListener(org.apache.wicket.authorization.IUnauthorizedComponentInstantiationListener) Component(org.apache.wicket.Component) UnauthorizedInstantiationException(org.apache.wicket.authorization.UnauthorizedInstantiationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnauthorizedInstantiationException(org.apache.wicket.authorization.UnauthorizedInstantiationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 75 with WicketTester

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);
                        }
                    };
                }
            };
        }
    };
}
Also used : MockPageManager(org.apache.wicket.mock.MockPageManager) Behavior(org.apache.wicket.behavior.Behavior) WicketTester(org.apache.wicket.util.tester.WicketTester) Component(org.apache.wicket.Component) IPageManagerProvider(org.apache.wicket.IPageManagerProvider) IManageablePage(org.apache.wicket.page.IManageablePage) IPageManagerContext(org.apache.wicket.page.IPageManagerContext) IComponentInstantiationListener(org.apache.wicket.application.IComponentInstantiationListener)

Aggregations

WicketTester (org.apache.wicket.util.tester.WicketTester)89 Test (org.junit.Test)54 Before (org.junit.Before)26 FormTester (org.apache.wicket.util.tester.FormTester)14 WebApplication (org.apache.wicket.protocol.http.WebApplication)9 MockApplication (org.apache.wicket.mock.MockApplication)6 AbstractDeploymentTest (org.apache.wicket.arquillian.testing.deployment.AbstractDeploymentTest)5 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)5 IPageManagerProvider (org.apache.wicket.IPageManagerProvider)4 IPageManagerContext (org.apache.wicket.page.IPageManagerContext)4 DummyApplication (org.apache.wicket.resource.DummyApplication)4 Component (org.apache.wicket.Component)3 Response (org.apache.wicket.request.Response)3 WicketApplication (sandbox.WicketApplication)3 TestWicketJavaEEApplication (org.apache.wicket.arquillian.testing.TestWicketJavaEEApplication)2 IAuthorizationStrategy (org.apache.wicket.authorization.IAuthorizationStrategy)2 RoleAuthorizationStrategy (org.apache.wicket.authroles.authorization.strategies.role.RoleAuthorizationStrategy)2 MockPageManager (org.apache.wicket.mock.MockPageManager)2 IManageablePage (org.apache.wicket.page.IManageablePage)2 IPageManager (org.apache.wicket.page.IPageManager)2