use of org.apache.wicket.MockPageWithLink in project wicket by apache.
the class AbstractLinkTest method testRenderUsingGetBody.
/**
* Tests that the {@link AbstractLink} uses the {@link AbstractLink#getBody()} to get its body. This
* method can be overridden to provide a dynamic model.
*/
@Test
public void testRenderUsingGetBody() {
final AtomicInteger counter = new AtomicInteger(0);
MockPageWithLink mockPageWithLink = new MockPageWithLink();
AbstractLink link = new AbstractLink("link") {
private static final long serialVersionUID = 1L;
@Override
public IModel<?> getBody() {
return Model.of(counter.getAndIncrement());
}
};
link.setMarkupId("link");
mockPageWithLink.add(link);
tester.startPage(mockPageWithLink);
TagTester tagTester = tester.getTagById("link");
Assert.assertEquals("0", tagTester.getValue());
tester.startPage(mockPageWithLink);
tagTester = tester.getTagById("link");
Assert.assertEquals("1", tagTester.getValue());
}
use of org.apache.wicket.MockPageWithLink in project wicket by apache.
the class ISecuritySettingsTest method enforceMounts.
/**
* https://issues.apache.org/jira/browse/WICKET-3849
*/
@Test
public void enforceMounts() {
MockPageWithLink pageWithLink = new MockPageWithLink();
pageWithLink.add(new Link<Void>(MockPageWithLink.LINK_ID) {
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
throw new RedirectToUrlException("/wicket/bookmarkable/" + UnknownPage.class.getName());
}
});
tester.startPage(pageWithLink);
tester.assertRenderedPage(MockPageWithLink.class);
tester.clickLink(MockPageWithLink.LINK_ID);
tester.assertRenderedPage(UnknownPage.class);
tester.getApplication().getSecuritySettings().setEnforceMounts(true);
tester.startPage(pageWithLink);
tester.assertRenderedPage(MockPageWithLink.class);
tester.clickLink(MockPageWithLink.LINK_ID);
Assert.assertNull(tester.getLastRenderedPage());
/*
* Test that mounts are enforced when the root compound mapper does not directly contain the mounted mapper.
*/
tester.getApplication().setRootRequestMapper(new HttpsMapper(tester.getApplication().getRootRequestMapper(), new HttpsConfig()));
tester.startPage(pageWithLink);
tester.assertRenderedPage(MockPageWithLink.class);
tester.clickLink(MockPageWithLink.LINK_ID);
Assert.assertNull(tester.getLastRenderedPage());
}
use of org.apache.wicket.MockPageWithLink in project wicket by apache.
the class DebugSettingsTest method setComponentPathAttributeName.
/**
* https://issues.apache.org/jira/browse/WICKET-5498
*/
@Test
public void setComponentPathAttributeName() {
String attributeName = "data-wicket-path";
tester.getApplication().getDebugSettings().setComponentPathAttributeName(attributeName);
MockPageWithLink page = new MockPageWithLink();
Component link = new Link<Void>(MockPageWithLink.LINK_ID) {
@Override
public void onClick() {
}
}.setMarkupId(MockPageWithLink.LINK_ID);
page.add(link);
tester.startPage(page);
TagTester tagTester = tester.getTagById(MockPageWithLink.LINK_ID);
String wicketPath = tagTester.getAttribute(attributeName);
assertEquals(link.getPageRelativePath(), wicketPath);
}
use of org.apache.wicket.MockPageWithLink in project wicket by apache.
the class DifferentPageCheckerTest method serializingAnotherPage.
/**
* https://issues.apache.org/jira/browse/WICKET-5634
*
* Tests that the serialization fails when a checking ObjectOutputStream is
* used with DifferentPageChecker and there is a component in the object tree that
* keeps a reference to a page which is not component.getPage()..
*/
@Test
public void serializingAnotherPage() {
JavaSerializer serializer = new JavaSerializer("JavaSerializerTest") {
@Override
protected ObjectOutputStream newObjectOutputStream(OutputStream out) throws IOException {
IObjectChecker checker = new DifferentPageChecker();
return new CheckingObjectOutputStream(out, checker);
}
};
WebComponent component = new ComponentThatKeepsAReferenceToAnotherPage(MockPageWithLink.LINK_ID);
MockPageWithLink rootPage = new MockPageWithLink();
rootPage.add(component);
byte[] serialized = serializer.serialize(rootPage);
assertNull("The produced byte[] must be null if there was an error", serialized);
}
Aggregations