Search in sources :

Example 41 with Page

use of org.apache.wicket.Page in project wicket by apache.

the class AutoFormLabelPickupTest method localeChangesAreDetectedWithDefaultLabels.

@Test
public void localeChangesAreDetectedWithDefaultLabels() throws Exception {
    Session.get().setLocale(Locale.GERMAN);
    tester.startPage(new PickUpLabelPage(null));
    assertEquals("propertiesDefaultLabel DE", ((FormComponent) tester.getComponentFromLastRenderedPage("form:inputWithDefaultLabel")).getLabel().getObject());
    tester.assertContains("propertiesDefaultLabel DE");
    // change locale to see whether it picks it up
    Session.get().setLocale(Locale.FRENCH);
    Page page = tester.getLastRenderedPage();
    // make sure everything is detached after we just talked to that label model
    page.detach();
    // just re-render the same page instance with the new locale
    tester.startPage(page);
    assertEquals("propertiesDefaultLabel FR", ((FormComponent) tester.getComponentFromLastRenderedPage("form:inputWithDefaultLabel")).getLabel().getObject());
    tester.assertContains("propertiesDefaultLabel FR");
}
Also used : Page(org.apache.wicket.Page) WebPage(org.apache.wicket.markup.html.WebPage) Test(org.junit.Test)

Example 42 with Page

use of org.apache.wicket.Page in project wicket by apache.

the class AutoFormLabelPickupTest method localeChangesAreDetectedWithExplicitMessageKeys.

@Test
public void localeChangesAreDetectedWithExplicitMessageKeys() throws Exception {
    Session.get().setLocale(Locale.GERMAN);
    tester.startPage(new PickUpLabelPage(null));
    assertEquals("label from properties DE", ((FormComponent) tester.getComponentFromLastRenderedPage("form:inputPropertiesLabel")).getLabel().getObject());
    tester.assertContains("label from properties DE");
    // change locale to see whether it picks it up
    Session.get().setLocale(Locale.FRENCH);
    Page page = tester.getLastRenderedPage();
    // make sure everything is detached after we just talked to that label model
    page.detach();
    // just re-render the same page instance with the new locale
    tester.startPage(page);
    assertEquals("label from properties FR", ((FormComponent) tester.getComponentFromLastRenderedPage("form:inputPropertiesLabel")).getLabel().getObject());
    tester.assertContains("label from properties FR");
}
Also used : Page(org.apache.wicket.Page) WebPage(org.apache.wicket.markup.html.WebPage) Test(org.junit.Test)

Example 43 with Page

use of org.apache.wicket.Page in project wicket by apache.

the class PageSizeDebugPanel method getDataModel.

@Override
protected IModel<String> getDataModel() {
    return new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            Page enclosingPage = getPage();
            long pageSize = WicketObjects.sizeof(enclosingPage);
            Bytes pageSizeInBytes = (pageSize > -1 ? Bytes.bytes(pageSize) : null);
            String pageSizeAsString = pageSizeInBytes != null ? pageSizeInBytes.toString() : "unknown";
            return "Page: " + pageSizeAsString;
        }
    };
}
Also used : Bytes(org.apache.wicket.util.lang.Bytes) IModel(org.apache.wicket.model.IModel) Page(org.apache.wicket.Page) WebPage(org.apache.wicket.markup.html.WebPage)

Example 44 with Page

use of org.apache.wicket.Page in project wicket by apache.

the class AjaxLinkClickTest method testBasicAjaxLinkClick.

/**
 * Test that an AjaxLink's onClick method is actually invoked.
 */
@Test
public void testBasicAjaxLinkClick() {
    // Create a link, which we test is actually invoked
    final AjaxLink<Void> ajaxLink = new AjaxLink<Void>("ajaxLink") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            linkClicked = true;
            ajaxRequestTarget = target;
        }
    };
    Page page = new MockPageWithLink();
    page.add(ajaxLink);
    tester.startPage(page);
    tester.clickLink("ajaxLink");
    assertTrue(linkClicked);
    assertNotNull(ajaxRequestTarget);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Page(org.apache.wicket.Page) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) Test(org.junit.Test)

Example 45 with Page

use of org.apache.wicket.Page in project wicket by apache.

the class AjaxLinkClickTest method testFallbackLinkWithAjaxDisabled.

/**
 * Test that when AJAX is disabled, the AjaxFallbackLink is invoked with null as
 * AjaxRequestTarget.
 */
@Test
public void testFallbackLinkWithAjaxDisabled() {
    final Page page = new MockPageWithLink();
    // Create a link, which we test is actually invoked
    page.add(new AjaxFallbackLink<Void>("ajaxLink") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(Optional<AjaxRequestTarget> targetOptional) {
            linkClicked = true;
            targetOptional.ifPresent(target -> ajaxRequestTarget = target);
        }
    });
    tester.startPage(page);
    // Click the link with ajax disabled
    tester.clickLink("ajaxLink", false);
    assertTrue(linkClicked);
    assertNull(ajaxRequestTarget);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Page(org.apache.wicket.Page) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) Optional(java.util.Optional) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Test(org.junit.Test) AjaxFallbackLink(org.apache.wicket.ajax.markup.html.AjaxFallbackLink) WicketTestCase(org.apache.wicket.util.tester.WicketTestCase) Before(org.junit.Before) Page(org.apache.wicket.Page) Test(org.junit.Test)

Aggregations

Page (org.apache.wicket.Page)94 Test (org.junit.Test)50 WebPage (org.apache.wicket.markup.html.WebPage)22 Component (org.apache.wicket.Component)11 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)7 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)7 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)6 IRequestHandler (org.apache.wicket.request.IRequestHandler)6 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)6 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)6 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 PageProvider (org.apache.wicket.core.request.handler.PageProvider)5 IMarkupFragment (org.apache.wicket.markup.IMarkupFragment)5 DummyPage (org.apache.wicket.resource.DummyPage)5 ArrayList (java.util.ArrayList)4 AbstractAjaxBehavior (org.apache.wicket.behavior.AbstractAjaxBehavior)4 AccessDeniedPage (org.apache.wicket.markup.html.pages.AccessDeniedPage)4 Url (org.apache.wicket.request.Url)4 MockInnerClassPage (org.apache.wicket.util.tester.MockPageParameterPage.MockInnerClassPage)4 SuccessPage (org.apache.wicket.util.tester.apps_1.SuccessPage)4