You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Alexander Gubin <ag...@greatergood.net> on 2011/09/09 21:26:28 UTC
testing setResponsePage with Panel or Page
Hi all,
I have a panel that redirects to another page if the user isn't logged
in, e.g
public MyPanel(String id) {
super(id);
Integer accountId = sessionBean.getAccountId();
if (accountId == null) { // not logged in, redirect to login
getRequestCycle().setRedirect(true);
setResponsePage(LoginPage.class, new PageParameters("siteId=" +
sessionBean.getSiteId()));
return;
}
... do normal panel display
}
I naively setup my test like this:
tester.startPanel(new ITestPanelSource() {
@Override
public Panel getTestPanel(String panelId) {
return new MyPanel(panelId);
}
});
tester.assertRenderedPage(LoginPage.class);
but I get:
- Redirecting to /BaseTestCase$1/BaseTestCase$1/?wicket:interface=:1::::
- Unable to find component with id 'welcome' in [MarkupContainer
[Component id = panel]]. This means that you declared wicket:id=welcome
in your markup, but that you either did not add the component to your
page at all, or that the hierarchy does not match.
[markup = file:/home/Developer/build/component/page/account/MyPanel.html
I see that redirect is logged by Wicket, but
WicketTester still tries to render MyPanel, when it shouldn't...
is there a way to work around this issue?
Sincerely,
Alexander
P.S. testing with enclosing page, e.g. tester.startPage(new MyPage(new
PageParameters())); produces the same error
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: testing setResponsePage with Panel or Page
Posted by Dan Retzlaff <dr...@gmail.com>.
You could try: throw new RestartResponseException(LoginPage.class, new
PageParameters(...));
For login redirects, it's common to
use RestartResponseAtInterceptPageException,
then Component#continueToOriginalDestination() once they've been
authentication.
On Fri, Sep 9, 2011 at 12:26 PM, Alexander Gubin <ag...@greatergood.net>wrote:
> Hi all,
>
> I have a panel that redirects to another page if the user isn't logged in,
> e.g
>
> public MyPanel(String id) {
> super(id);
>
> Integer accountId = sessionBean.getAccountId();
> if (accountId == null) { // not logged in, redirect to login
> getRequestCycle().setRedirect(**true);
> setResponsePage(LoginPage.**class, new PageParameters("siteId=" +
> sessionBean.getSiteId()));
> return;
> }
>
> ... do normal panel display
>
> }
>
> I naively setup my test like this:
>
>
> tester.startPanel(new ITestPanelSource() {
>
> @Override
> public Panel getTestPanel(String panelId) {
> return new MyPanel(panelId);
> }
> });
>
> tester.assertRenderedPage(**LoginPage.class);
>
> but I get:
> - Redirecting to /BaseTestCase$1/BaseTestCase$**1/?wicket:interface=:1::::
>
> - Unable to find component with id 'welcome' in [MarkupContainer [Component
> id = panel]]. This means that you declared wicket:id=welcome in your markup,
> but that you either did not add the component to your page at all, or that
> the hierarchy does not match.
> [markup = file:/home/Developer/build/**component/page/account/**
> MyPanel.html
>
> I see that redirect is logged by Wicket, but
> WicketTester still tries to render MyPanel, when it shouldn't...
>
> is there a way to work around this issue?
>
> Sincerely,
>
> Alexander
>
> P.S. testing with enclosing page, e.g. tester.startPage(new MyPage(new
> PageParameters())); produces the same error
>
>
>
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>