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());
}
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());
}
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();
}
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);
}
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());
}
Aggregations