Search in sources :

Example 61 with WicketTester

use of org.apache.wicket.util.tester.WicketTester in project wicket by apache.

the class WebExternalResourceTest method before.

/**
 * @throws Exception
 */
@Before
public void before() throws Exception {
    File tempDir = new File("target/webapp");
    tempDir.mkdir();
    File tempFile = new File(tempDir, "index.html");
    FileOutputStream out = new FileOutputStream(tempFile);
    InputStream in = WebExternalResourceTest.class.getResourceAsStream("index.html");
    Streams.copy(in, out);
    in.close();
    out.close();
    tester = new WicketTester(new MockApplication(), tempDir.getPath());
    // We fake the browser URL, otherwise Wicket doesn't know the requested URL and cannot guess
    // the Content-Type
    tester.getRequest().setURL("index.html");
}
Also used : MockApplication(org.apache.wicket.mock.MockApplication) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) WicketTester(org.apache.wicket.util.tester.WicketTester) File(java.io.File) Before(org.junit.Before)

Example 62 with WicketTester

use of org.apache.wicket.util.tester.WicketTester in project wicket by apache.

the class ServletWebRequestTest method useCustomServletWebRequest.

/**
 * https://issues.apache.org/jira/browse/WICKET-4123
 */
@Test
public void useCustomServletWebRequest() {
    WebApplication application = new WebApplication() {

        @Override
        public Class<? extends Page> getHomePage() {
            return CustomRequestPage.class;
        }

        @Override
        public WebRequest newWebRequest(HttpServletRequest servletRequest, String filterPath) {
            return new CustomServletWebRequest(servletRequest, filterPath);
        }
    };
    WicketTester tester = new WicketTester(application);
    try {
        tester.startPage(new CustomRequestPage());
    } finally {
        tester.destroy();
    }
}
Also used : MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) WicketTester(org.apache.wicket.util.tester.WicketTester) WebApplication(org.apache.wicket.protocol.http.WebApplication) Test(org.junit.Test)

Example 63 with WicketTester

use of org.apache.wicket.util.tester.WicketTester in project wicket by apache.

the class PageVersioningTest method setup.

/**
 * setup()
 */
@Before
public void setup() {
    final PageVersioningApplication application = new PageVersioningApplication();
    wicketTester = new WicketTester(application) {

        /**
         * @see org.apache.wicket.util.tester.BaseWicketTester#newTestPageManagerProvider()
         */
        @Override
        protected IPageManagerProvider newTestPageManagerProvider() {
            return new IPageManagerProvider() {

                @Override
                public IPageManager apply(IPageManagerContext pageManagerContext) {
                    final IDataStore dataStore = new InMemoryPageStore();
                    final AsynchronousDataStore asyncDS = new AsynchronousDataStore(dataStore, 100);
                    final DefaultPageStore pageStore = new DefaultPageStore(new JavaSerializer(application.getApplicationKey()), asyncDS, 40);
                    return new PageStoreManager(application.getName(), pageStore, pageManagerContext);
                }
            };
        }
    };
}
Also used : IPageManager(org.apache.wicket.page.IPageManager) PageStoreManager(org.apache.wicket.page.PageStoreManager) AsynchronousDataStore(org.apache.wicket.pageStore.AsynchronousDataStore) WicketTester(org.apache.wicket.util.tester.WicketTester) IPageManagerProvider(org.apache.wicket.IPageManagerProvider) JavaSerializer(org.apache.wicket.serialize.java.JavaSerializer) IPageManagerContext(org.apache.wicket.page.IPageManagerContext) IDataStore(org.apache.wicket.pageStore.IDataStore) DefaultPageStore(org.apache.wicket.pageStore.DefaultPageStore) Before(org.junit.Before)

Example 64 with WicketTester

use of org.apache.wicket.util.tester.WicketTester in project wicket by apache.

the class ComponentEventsTest method setup.

/**
 */
@Before
public void setup() {
    tester = new WicketTester(new TestApplication());
    application = (TestApplication) tester.getApplication();
    session = (TestSession) tester.getSession();
    cycle = (TestRequestCycle) tester.getRequestCycle();
    page = new TestPage();
    c1 = new TestContainer("c1");
    c12 = new TestContainer("c12");
    c13 = new TestContainer("c13");
    c134 = new TestContainer("c134");
    c135 = new TestComponent("c135");
    c6 = new TestComponent("c6");
    page.add(c1);
    c1.add(c12);
    c1.add(c13);
    c13.add(c134);
    c13.add(c135);
    page.add(c6);
    all = new Testable[] { page, c1, c12, c13, c134, c135, c6, application, session, cycle };
    stop = null;
}
Also used : WicketTester(org.apache.wicket.util.tester.WicketTester) Before(org.junit.Before)

Example 65 with WicketTester

use of org.apache.wicket.util.tester.WicketTester in project wicket by apache.

the class FormMethodMismatchTest method withButtonFormSubmittedContinuesWithCorrectMethod.

@Test
public void withButtonFormSubmittedContinuesWithCorrectMethod() {
    final WicketTester tester = new WicketTester();
    final boolean[] onSubmitCalled = new boolean[1];
    final Form<Void> underTest = new Form<Void>("underTest") {

        @Override
        protected void onSubmit() {
            onSubmitCalled[0] = true;
        }
    };
    tester.startPage(new FormWithButtonPage(underTest));
    final FormTester formTester = tester.newFormTester("underTest");
    formTester.submit("button");
    assertTrue(onSubmitCalled[0]);
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) WicketTester(org.apache.wicket.util.tester.WicketTester) Test(org.junit.Test)

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