Search in sources :

Example 11 with WicketTester

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

the class Issue3989Test method ajaxRenderOfTransparentlyResolvedLabel.

/**
 * This will fail unless the markup sourcing strategies look for the label {@code innerpanel} in
 * the transparent markup container.
 */
@Test
public void ajaxRenderOfTransparentlyResolvedLabel() {
    WicketTester tester = new WicketTester();
    tester.startPage(HomePage.class);
    tester.assertRenderedPage(HomePage.class);
    tester.clickLink("panel:link");
    tester.assertComponentOnAjaxResponse("panel:innerpanel");
}
Also used : WicketTester(org.apache.wicket.util.tester.WicketTester) Test(org.junit.Test)

Example 12 with WicketTester

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

the class Signin2Test method testSignIn2.

/**
 * Test page.
 */
@Test
public void testSignIn2() {
    WicketTester tester = new WicketTester(new SignIn2Application());
    try {
        tester.startPage(Home.class);
        tester.assertRenderedPage(SignIn2.class);
        FormTester formTester = tester.newFormTester("signInPanel:signInForm");
        formTester.setValue("username", "wicket");
        formTester.setValue("password", "wicket");
        formTester.setValue("rememberMeContainer:rememberMe", "true");
        formTester.submit();
        tester.assertRenderedPage(Home.class);
        // a) With wicket submitting a form will result in a temporary redirect,
        // with the redirect setting the Cookie.
        // b) jWebUnits Cookie test methods are all using the http response
        // object only
        // c) Like a browser, jwebunit will automatically handle the redirect
        // request
        // Hence dumpCookie will not print an Cookie and assertCookiePresent
        // will
        // fail.
        // The only mean available is to indirectly test the cookies. Indirectly
        // because
        // the screen flow depends on the cookies.
        // this.dumpCookies(System.err);
        // this.assertCookiePresent("signInPanel.signInForm.username");
        // this.assertCookiePresent("signInPanel.signInForm.password");
        Collection<Cookie> cookies = tester.getLastResponse().getCookies();
        for (Cookie cookie : cookies) {
            if ("signInPanel.signInForm.username".equals(cookie.getName())) {
                assertEquals("wicket", cookie.getValue());
            }
        }
        tester.startPage(SignOut.class);
        tester.assertRenderedPage(SignOut.class);
        tester.startPage(Home.class);
        tester.assertRenderedPage(SignIn2.class);
    } finally {
        tester.destroy();
    }
}
Also used : Cookie(javax.servlet.http.Cookie) FormTester(org.apache.wicket.util.tester.FormTester) WicketTester(org.apache.wicket.util.tester.WicketTester) SignIn2Application(org.apache.wicket.examples.authentication2.SignIn2Application) Test(org.junit.Test)

Example 13 with WicketTester

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

the class TemplateTest method test_1.

/**
 * Test page.
 */
@Test
public void test_1() {
    WicketTester tester = new WicketTester(new TemplateApplication());
    tester.startPage(tester.getApplication().getHomePage());
    String doc = tester.getLastResponse().getDocument();
    tester.assertContains("Wicket Examples - template");
    tester.assertContains("This example shows two different ways of building your page up from shared parts.");
    tester.startPage(org.apache.wicket.examples.template.pageinheritance.Page1.class);
    doc = tester.getLastResponse().getDocument();
    tester.assertContains("Template example, page 1 - page inheritance");
    tester.assertContains("This is some concrete content from a panel.");
    tester.startPage(org.apache.wicket.examples.template.border.Page1.class);
    tester.assertRenderedPage(org.apache.wicket.examples.template.border.Page1.class);
    doc = tester.getLastResponse().getDocument();
    tester.assertContains("Template example, page 1 - border");
    tester.assertContains("contents here");
    tester.destroy();
}
Also used : WicketTester(org.apache.wicket.util.tester.WicketTester) Test(org.junit.Test)

Example 14 with WicketTester

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

the class HangManTest method testHangmanSuccessWebGame.

/**
 * Tests the webapplication for a successful match.
 */
@Test
public void testHangmanSuccessWebGame() {
    WicketTester tester = new WicketTester(new HangmanApplication());
    try {
        tester.startPage(Home.class, new PageParameters().set("word", "hangman"));
        tester.assertComponent("start", Link.class);
        tester.assertContains("Wicket Examples - hangman");
        tester.clickLink("start");
        tester.assertLabel("guessesRemaining", "5");
        clickLetter(tester, 'f');
        tester.assertLabel("guessesRemaining", "4");
        clickLetter(tester, 'h');
        tester.assertLabel("guessesRemaining", "4");
        clickLetter(tester, 'a');
        clickLetter(tester, 'n');
        clickLetter(tester, 'g');
        clickLetter(tester, 'm');
        tester.assertRenderedPage(Win.class);
    } finally {
        tester.destroy();
    }
}
Also used : WicketTester(org.apache.wicket.util.tester.WicketTester) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Test(org.junit.Test)

Example 15 with WicketTester

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

the class HangManTest method testHangmanFailureWebGame.

/**
 * Tests the webapplication for an unsuccessful match.
 */
@Test
public void testHangmanFailureWebGame() {
    WicketTester tester = new WicketTester(new HangmanApplication());
    try {
        tester.startPage(Home.class, new PageParameters().set("word", "hangman"));
        tester.assertComponent("start", Link.class);
        tester.assertContains("Wicket Examples - hangman");
        tester.clickLink("start");
        tester.assertLabel("guessesRemaining", "5");
        clickLetter(tester, 'f');
        tester.assertLabel("guessesRemaining", "4");
        clickLetter(tester, 'e');
        tester.assertLabel("guessesRemaining", "3");
        clickLetter(tester, 't');
        tester.assertLabel("guessesRemaining", "2");
        clickLetter(tester, 'x');
        tester.assertLabel("guessesRemaining", "1");
        clickLetter(tester, 'z');
        tester.assertRenderedPage(Lose.class);
    } finally {
        tester.destroy();
    }
}
Also used : WicketTester(org.apache.wicket.util.tester.WicketTester) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) 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