Search in sources :

Example 1 with MockPageWithOneComponent

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

the class WicketTesterTest method executeAjaxEvent.

/**
 * Test that the executeAjaxEvent on the WicketTester works.
 */
@Test
public void executeAjaxEvent() {
    // Setup mocks
    final MockPageWithOneComponent page = new MockPageWithOneComponent();
    Label label = new Label("component", "Dblclick This To See Magick");
    label.add(new AjaxEventBehavior("dblclick") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            eventExecuted = true;
        }
    });
    page.add(label);
    // Start the page
    tester.startPage(page);
    // tester.setupRequestAndResponse();
    // Execute the event
    tester.executeAjaxEvent(label, "dblclick");
    assertTrue(eventExecuted);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) MockPageWithOneComponent(org.apache.wicket.MockPageWithOneComponent) AjaxEventBehavior(org.apache.wicket.ajax.AjaxEventBehavior) Label(org.apache.wicket.markup.html.basic.Label) Test(org.junit.Test)

Example 2 with MockPageWithOneComponent

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

the class BehaviorTest method onTagTest.

@Test
public void onTagTest() {
    WebMarkupContainer component = new WebMarkupContainer(MockPageWithOneComponent.COMPONENT_ID);
    MockPageWithOneComponent page = new MockPageWithOneComponent();
    page.add(component);
    String value = "value";
    String key = "key";
    component.add(Behavior.onTag((c, tag) -> tag.put(key, value)));
    component.add(Behavior.onAttribute("class", oldValue -> "zzz"));
    tester.startPage(page);
    TagTester tagTester = tester.getTagByWicketId(MockPageWithOneComponent.COMPONENT_ID);
    assertThat(tagTester.getAttribute(key), is(equalTo(value)));
    assertThat(tagTester.getAttribute("class"), is(equalTo("zzz")));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) MockPageWithOneComponent(org.apache.wicket.MockPageWithOneComponent) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) WicketTestCase(org.apache.wicket.util.tester.WicketTestCase) MockPageWithOneComponent(org.apache.wicket.MockPageWithOneComponent) TagTester(org.apache.wicket.util.tester.TagTester) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Test(org.junit.Test)

Example 3 with MockPageWithOneComponent

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

the class BehaviorTest method onAttributeTest.

@Test
public void onAttributeTest() {
    WebMarkupContainer component = new WebMarkupContainer(MockPageWithOneComponent.COMPONENT_ID);
    MockPageWithOneComponent page = new MockPageWithOneComponent();
    page.add(component);
    String value = "value";
    String key = "key";
    component.add(Behavior.onAttribute(key, oldValue -> value));
    tester.startPage(page);
    TagTester tagTester = tester.getTagByWicketId(MockPageWithOneComponent.COMPONENT_ID);
    assertThat(tagTester.getAttribute(key), is(equalTo(value)));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) MockPageWithOneComponent(org.apache.wicket.MockPageWithOneComponent) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) WicketTestCase(org.apache.wicket.util.tester.WicketTestCase) MockPageWithOneComponent(org.apache.wicket.MockPageWithOneComponent) TagTester(org.apache.wicket.util.tester.TagTester) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Test(org.junit.Test)

Aggregations

MockPageWithOneComponent (org.apache.wicket.MockPageWithOneComponent)3 Test (org.junit.Test)3 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)2 TagTester (org.apache.wicket.util.tester.TagTester)2 WicketTestCase (org.apache.wicket.util.tester.WicketTestCase)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Matchers.is (org.hamcrest.Matchers.is)2 AjaxEventBehavior (org.apache.wicket.ajax.AjaxEventBehavior)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 Label (org.apache.wicket.markup.html.basic.Label)1