use of org.apache.wicket.Page in project wicket by apache.
the class MarkupFragmentTest method border.
/**
* @throws Exception
*/
@Test
public void border() throws Exception {
Page page = new MyBorderPage();
Border border = (Border) page.get("border");
// Get the associated markup file
IMarkupFragment markup = border.getAssociatedMarkup();
compareMarkupWithFile(markup, "MyBorder_ExpectedResult.html", MyPage.class);
// getMarkup() returns the "calling" tags
markup = border.getMarkup();
compareMarkupWithString(markup, "<span wicket:id=\"border\">test</span>");
// getMarkup(null) returns the markup which is used to find a child component
markup = border.getMarkup(null);
compareMarkupWithString(markup, "<wicket:border> 111 <wicket:body/> 222</wicket:border>");
assertNull(border.getBodyContainer().getAssociatedMarkup());
border.dequeue();
markup = border.getBodyContainer().getMarkup();
compareMarkupWithString(markup, "<wicket:body/>");
markup = border.getBodyContainer().getMarkup(null);
compareMarkupWithString(markup, "<span wicket:id=\"border\">test</span>");
markup = border.getBodyContainer().getParent().getMarkup(border.getBodyContainer());
compareMarkupWithString(markup, "<wicket:body/>");
// getMarkup(null) returns the markup which is used to find a child component
markup = border.getBodyContainer().getMarkup(null);
compareMarkupWithString(markup, "<span wicket:id=\"border\">test</span>");
}
use of org.apache.wicket.Page in project wicket by apache.
the class WicketTesterTest method viewBook.
/**
* @throws Exception
*/
@Test
public void viewBook() throws Exception {
Book mockBook = new Book("xxId", "xxName");
Page page = new ViewBook(mockBook);
tester.startPage(page);
// assertion
tester.assertRenderedPage(ViewBook.class);
tester.assertLabel("id", "xxId");
tester.assertLabel("name", "xxName");
}
use of org.apache.wicket.Page in project wicket by apache.
the class WicketTesterTest method pageConstructor.
/**
* @throws Exception
*/
@Test
public void pageConstructor() throws Exception {
Book mockBook = new Book("xxId", "xxName");
Page page = new ViewBook(mockBook);
tester.startPage(page);
// assertion
tester.assertRenderedPage(ViewBook.class);
tester.clickLink("link");
tester.assertRenderedPage(CreateBook.class);
}
use of org.apache.wicket.Page in project wicket by apache.
the class AjaxLinkClickTest method testAjaxFallbackLinkClick.
/**
* Test that clickLink also works with AjaxFallbackLinks
*
* AjaxFallbackLinks should be clicked and interpreted as an AjaxLink, which means that
* AjaxRequestTarget is not null.
*/
@Test
public void testAjaxFallbackLinkClick() {
final Page page = new MockPageWithLink();
// Create a link, which we test is actually invoked
page.add(new AjaxFallbackLink<Void>("ajaxLink") {
private static final long serialVersionUID = 1L;
public void onClick(Optional<AjaxRequestTarget> targetOptional) {
linkClicked = true;
targetOptional.ifPresent(target -> ajaxRequestTarget = target);
}
});
tester.startPage(page);
tester.clickLink("ajaxLink");
assertTrue(linkClicked);
assertNotNull(ajaxRequestTarget);
}
use of org.apache.wicket.Page in project wicket by apache.
the class StatelessChecker method onBeforeRender.
/**
* @see org.apache.wicket.application.IComponentOnBeforeRenderListener#onBeforeRender(org.apache.wicket.Component)
*/
@Override
public void onBeforeRender(final Component component) {
if (mustCheck(component)) {
final IVisitor<Component, Component> visitor = new IVisitor<Component, Component>() {
@Override
public void component(final Component comp, final IVisit<Component> visit) {
if ((component instanceof Page) && mustCheck(comp)) {
// Do not go deeper, because this component will be
// checked by checker
// itself.
// Actually we could go deeper but that would mean we
// traverse it twice
// (for current component and for inspected one).
// We go deeper for Page because full tree will be
// inspected during
// isPageStateless call.
visit.dontGoDeeper();
} else if (!comp.isStateless()) {
visit.stop(comp);
} else {
// continue
}
}
};
if (component.isStateless() == false) {
StringList statefulBehaviors = new StringList();
for (Behavior b : component.getBehaviors()) {
if (b.getStatelessHint(component) == false) {
statefulBehaviors.add(Classes.name(b.getClass()));
}
}
String reason;
if (statefulBehaviors.size() == 0) {
reason = " Possible reason: no stateless hint";
} else {
reason = " Stateful behaviors: " + statefulBehaviors.join();
}
fail(new StatelessCheckFailureException(component, reason));
return;
}
if (component instanceof MarkupContainer) {
MarkupContainer container = ((MarkupContainer) component);
// Traverse children
final Object o = container.visitChildren(visitor);
if (o != null) {
fail(new StatelessCheckFailureException(container, " Offending component: " + o));
return;
}
}
if (component instanceof Page) {
final Page p = (Page) component;
if (!p.isBookmarkable()) {
fail(new StatelessCheckFailureException(p, " Only bookmarkable pages can be stateless"));
return;
}
if (!p.isPageStateless()) {
fail(new StatelessCheckFailureException(p, " for unknown reason"));
return;
}
}
}
}
Aggregations