Search in sources :

Example 6 with MockPageWithLinkAndComponent

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

the class AjaxTimerBehaviorTest method addedInAjaxSetsTimout.

/**
 * Tests timer behavior in a component added to an AjaxRequestTarget
 */
@Test
public void addedInAjaxSetsTimout() {
    Duration dur = Duration.seconds(20);
    final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
    final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
    page.add(new WebComponent(MockPageWithLinkAndComponent.COMPONENT_ID).setOutputMarkupId(true));
    page.add(new AjaxLink<Void>(MockPageWithLinkAndComponent.LINK_ID) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            WebMarkupContainer wmc = new WebMarkupContainer(MockPageWithLinkAndComponent.COMPONENT_ID);
            wmc.setOutputMarkupId(true);
            wmc.add(timer);
            page.replace(wmc);
            target.add(wmc);
        }
    });
    tester.startPage(page);
    tester.clickLink(MockPageWithLinkAndComponent.LINK_ID);
    // first render sets timeout
    assertMatches("Wicket.Timer.set", 1);
    tester.executeBehavior(timer);
    assertMatches("Wicket.Timer.set", 1);
}
Also used : WebComponent(org.apache.wicket.markup.html.WebComponent) MockPageWithLinkAndComponent(org.apache.wicket.MockPageWithLinkAndComponent) Duration(org.apache.wicket.util.time.Duration) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Test(org.junit.Test)

Example 7 with MockPageWithLinkAndComponent

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

the class AjaxTimerBehaviorTest method ajaxUpdateDoesNotSetTimeout.

/**
 * tests timer behavior in a WebPage.
 */
@Test
public void ajaxUpdateDoesNotSetTimeout() {
    Duration dur = Duration.seconds(20);
    final AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(dur);
    final MockPageWithLinkAndComponent page = new MockPageWithLinkAndComponent();
    final Label label = new Label(MockPageWithLinkAndComponent.COMPONENT_ID, "Hello");
    page.add(label);
    page.add(new AjaxLink<Void>(MockPageWithLinkAndComponent.LINK_ID) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            target.add(label);
        }
    });
    label.setOutputMarkupId(true);
    label.add(timer);
    tester.startPage(page);
    assertMatches("Wicket.Timer.set", 1);
    tester.clickLink(MockPageWithLinkAndComponent.LINK_ID);
    assertMatches("Wicket.Timer.set", 1);
    tester.executeBehavior(timer);
    assertMatches("Wicket.Timer.set", 1);
}
Also used : MockPageWithLinkAndComponent(org.apache.wicket.MockPageWithLinkAndComponent) Label(org.apache.wicket.markup.html.basic.Label) Duration(org.apache.wicket.util.time.Duration) Test(org.junit.Test)

Aggregations

MockPageWithLinkAndComponent (org.apache.wicket.MockPageWithLinkAndComponent)7 Test (org.junit.Test)6 Label (org.apache.wicket.markup.html.basic.Label)5 Duration (org.apache.wicket.util.time.Duration)4 WebComponent (org.apache.wicket.markup.html.WebComponent)3 Component (org.apache.wicket.Component)2 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1