Search in sources :

Example 1 with MockPageWithLink

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

the class WicketTesterTest method clickResourceLinkWithResourceReference.

/**
 * https://issues.apache.org/jira/browse/WICKET-4810
 *
 * Clicking on ResourceLink should deliver the resource reference's content
 */
@Test
public void clickResourceLinkWithResourceReference() {
    MockPageWithLink page = new MockPageWithLink();
    String content = "content";
    final ByteArrayResource resource = new ByteArrayResource("text/plain", content.getBytes(), "fileName.txt");
    ResourceReference reference = new ResourceReference(WicketTesterTest.class, "resourceLinkWithResourceReferenceTest") {

        @Override
        public IResource getResource() {
            return resource;
        }
    };
    ResourceLink<Void> link = new ResourceLink<Void>(MockPageWithLink.LINK_ID, reference);
    page.add(link);
    tester.startPage(page);
    tester.clickLink(MockPageWithLink.LINK_ID, false);
    assertEquals(tester.getContentTypeFromResponseHeader(), "text/plain");
    assertEquals(content, tester.getLastResponseAsString());
}
Also used : ResourceLink(org.apache.wicket.markup.html.link.ResourceLink) ByteArrayResource(org.apache.wicket.request.resource.ByteArrayResource) ResourceReference(org.apache.wicket.request.resource.ResourceReference) MockPageWithLink(org.apache.wicket.MockPageWithLink) Test(org.junit.Test)

Example 2 with MockPageWithLink

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

the class WicketTesterTest method clickResourceLinkWithResource.

/**
 * https://issues.apache.org/jira/browse/WICKET-4437
 *
 * Clicking on ResourceLink should deliver the resource content
 */
@Test
public void clickResourceLinkWithResource() {
    MockPageWithLink page = new MockPageWithLink();
    String content = "content";
    ByteArrayResource resource = new ByteArrayResource("text/plain", content.getBytes(), "fileName.txt");
    ResourceLink<Void> link = new ResourceLink<Void>(MockPageWithLink.LINK_ID, resource);
    page.add(link);
    tester.startPage(page);
    tester.clickLink(MockPageWithLink.LINK_ID, false);
    assertEquals(tester.getContentTypeFromResponseHeader(), "text/plain");
    assertEquals(content, tester.getLastResponseAsString());
}
Also used : ResourceLink(org.apache.wicket.markup.html.link.ResourceLink) ByteArrayResource(org.apache.wicket.request.resource.ByteArrayResource) MockPageWithLink(org.apache.wicket.MockPageWithLink) Test(org.junit.Test)

Example 3 with MockPageWithLink

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

the class WicketTesterTest method assertComponentOnAjaxResponse.

/**
 */
@Test
public void assertComponentOnAjaxResponse() {
    final Page page = new MockPageWithLink();
    AjaxLink<Void> ajaxLink = new AjaxLink<Void>(MockPageWithLink.LINK_ID) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            // Replace the link with a normal Link
            Link<Void> link = new Link<Void>(MockPageWithLink.LINK_ID) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick() {
                }
            };
            link.setOutputMarkupId(true);
            page.replace(link);
            target.add(link);
        }
    };
    ajaxLink.setOutputMarkupId(true);
    page.add(ajaxLink);
    tester.startPage(page);
    // Click the link
    tester.clickLink(MockPageWithLink.LINK_ID);
    // The link must be a Link :)
    tester.assertComponent(MockPageWithLink.LINK_ID, Link.class);
    // This must not fail
    tester.assertComponentOnAjaxResponse(MockPageWithLink.LINK_ID);
    tester.dumpPage();
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Page(org.apache.wicket.Page) ComponentFeedbackResourceTestingPage(org.apache.wicket.util.tester.apps_8.ComponentFeedbackResourceTestingPage) DummyPage(org.apache.wicket.resource.DummyPage) SuccessPage(org.apache.wicket.util.tester.apps_1.SuccessPage) ResultPage(org.apache.wicket.util.tester.apps_6.ResultPage) LinkPage(org.apache.wicket.util.tester.apps_6.LinkPage) MockInnerClassPage(org.apache.wicket.util.tester.MockPageParameterPage.MockInnerClassPage) AccessDeniedPage(org.apache.wicket.markup.html.pages.AccessDeniedPage) WebPage(org.apache.wicket.markup.html.WebPage) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) MockPageWithLink(org.apache.wicket.MockPageWithLink) MockPanelWithLink(org.apache.wicket.MockPanelWithLink) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) TestLink(org.apache.wicket.util.tester.DummyHomePage.TestLink) Link(org.apache.wicket.markup.html.link.Link) MockPageWithLink(org.apache.wicket.MockPageWithLink) ResourceLink(org.apache.wicket.markup.html.link.ResourceLink) Test(org.junit.Test)

Example 4 with MockPageWithLink

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

the class WicketTesterClickExternalLinkTest method clickExternalLink.

@Test
public void clickExternalLink() {
    MockPageWithLink page = new MockPageWithLink();
    String href = "http://wicket.apache.org";
    page.add(new ExternalLink(MockPageWithLink.LINK_ID, href, "Wicket site"));
    tester.startPage(page);
    tester.clickLink(MockPageWithLink.LINK_ID, false);
    tester.assertRedirectUrl(href);
}
Also used : MockPageWithLink(org.apache.wicket.MockPageWithLink) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink) Test(org.junit.Test)

Example 5 with MockPageWithLink

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

the class AbstractLinkTest method testSetBodyModel.

/**
 * @see <a href="https://issues.apache.org/jira/browse/WICKET-3338">WICKET-3338</a>
 */
@Test
public void testSetBodyModel() {
    final String linkBody = "Link body";
    MockPageWithLink mockPageWithLink = new MockPageWithLink();
    AbstractLink link = new AbstractLink("link") {

        private static final long serialVersionUID = 1L;
    };
    link.setMarkupId("link");
    link.setBody(Model.of(linkBody));
    mockPageWithLink.add(link);
    tester.startPage(mockPageWithLink);
    TagTester tagTester = tester.getTagById("link");
    Assert.assertEquals(linkBody, tagTester.getValue());
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) MockPageWithLink(org.apache.wicket.MockPageWithLink) Test(org.junit.Test)

Aggregations

MockPageWithLink (org.apache.wicket.MockPageWithLink)9 Test (org.junit.Test)9 ResourceLink (org.apache.wicket.markup.html.link.ResourceLink)3 TagTester (org.apache.wicket.util.tester.TagTester)3 ByteArrayResource (org.apache.wicket.request.resource.ByteArrayResource)2 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Component (org.apache.wicket.Component)1 MockPanelWithLink (org.apache.wicket.MockPanelWithLink)1 Page (org.apache.wicket.Page)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)1 WebComponent (org.apache.wicket.markup.html.WebComponent)1 WebPage (org.apache.wicket.markup.html.WebPage)1 ExternalLink (org.apache.wicket.markup.html.link.ExternalLink)1 Link (org.apache.wicket.markup.html.link.Link)1 AccessDeniedPage (org.apache.wicket.markup.html.pages.AccessDeniedPage)1 HttpsConfig (org.apache.wicket.protocol.https.HttpsConfig)1 HttpsMapper (org.apache.wicket.protocol.https.HttpsMapper)1