Search in sources :

Example 41 with WicketTester

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

the class FormMethodMismatchTest method formSubmittedContinuesByDefaultWithMismatchingMethod.

@Test
public void formSubmittedContinuesByDefaultWithMismatchingMethod() {
    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 PlainFormPage(underTest));
    final FormTester formTester = tester.newFormTester("underTest");
    tester.getRequest().setMethod("GET");
    formTester.submit();
    assertTrue(onSubmitCalled[0]);
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) WicketTester(org.apache.wicket.util.tester.WicketTester) Test(org.junit.Test)

Example 42 with WicketTester

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

the class FormMethodMismatchTest method formSubmittedContinuesByWithCorrectMethodWhenDesired.

@Test
public void formSubmittedContinuesByWithCorrectMethodWhenDesired() {
    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;
        }

        @Override
        protected MethodMismatchResponse onMethodMismatch() {
            return MethodMismatchResponse.ABORT;
        }
    };
    tester.startPage(new PlainFormPage(underTest));
    final FormTester formTester = tester.newFormTester("underTest");
    formTester.submit();
    assertTrue(onSubmitCalled[0]);
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) WicketTester(org.apache.wicket.util.tester.WicketTester) Test(org.junit.Test)

Example 43 with WicketTester

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

the class FormMethodMismatchTest method withButtonFormSubmittedContinuesByWithCorrectMethodWhenDesired.

@Test
public void withButtonFormSubmittedContinuesByWithCorrectMethodWhenDesired() {
    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;
        }

        @Override
        protected MethodMismatchResponse onMethodMismatch() {
            return MethodMismatchResponse.ABORT;
        }
    };
    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)

Example 44 with WicketTester

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

the class FormMethodMismatchTest method withAjaxButtonFormSubmittedAbortsByWithMismatchingMethodWhenDesired.

@Test
public void withAjaxButtonFormSubmittedAbortsByWithMismatchingMethodWhenDesired() {
    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;
        }

        @Override
        protected MethodMismatchResponse onMethodMismatch() {
            return MethodMismatchResponse.ABORT;
        }
    };
    tester.startPage(new FormWithAjaxButtonPage(underTest));
    final FormTester formTester = tester.newFormTester("underTest");
    tester.getRequest().setMethod("GET");
    formTester.submit("button");
    assertFalse(onSubmitCalled[0]);
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) WicketTester(org.apache.wicket.util.tester.WicketTester) Test(org.junit.Test)

Example 45 with WicketTester

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

the class FormMethodMismatchTest method formSubmittedAbortsByWithMismatchingMethodWhenDesired.

@Test
public void formSubmittedAbortsByWithMismatchingMethodWhenDesired() {
    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;
        }

        @Override
        protected MethodMismatchResponse onMethodMismatch() {
            return MethodMismatchResponse.ABORT;
        }
    };
    tester.startPage(new PlainFormPage(underTest));
    final FormTester formTester = tester.newFormTester("underTest");
    tester.getRequest().setMethod("GET");
    formTester.submit();
    assertFalse(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