Hi,

I'm trying to set up testing for my Wicket Application but ran across this
error message:
"org.apache.wicket.protocol.http.WebSession cannot be cast to
my.CustomSession"

The page (LoginPage) I'm testing does:
--------
(CustomSession) Session.get();
--------
This is the point where the error message occurs.

In my CustomApplication (which extends SpringWebApplication) I've overridden
newSession():
--------
@Override
public Session newSession(Request request, Response response) {
        CustomSession session = new CustomSession(request);
        return session;
}
--------

I found a couple of threads where the solution was to create an instance of
CustomApplication and pass it to WicketTester:
--------
tester = new WicketTester(new CustomApplication());
--------

Unfortunately this leads to this error message:
--------
java.lang.IllegalStateException: No WebApplicationContext found: no
ContextLoaderListener registered?
                at
org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:86)
                at
org.apache.wicket.spring.SpringWebApplication.internalInit(SpringWebApplication.java:77)
                at
org.apache.wicket.protocol.http.WicketFilter.init(WicketFilter.java:511)
                at
org.apache.wicket.protocol.http.MockWebApplication.<init>(MockWebApplication.java:148)
                at
org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:204)
                at
org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:308)
                at
org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:291)
                at my.LoginPageTest.setUp(LoginPageTest.java:32)
--------

So my next approach was to override getWicketSession() in WicketTester() and
let it return my CustomSession instead of WebSession:
--------
tester = new WicketTester() {
        @Override
        public WebSession getWicketSession() {
                return new CustomSession(getWicketRequest());
        }
};
--------

But this method never get's called.

I started debugging and found that the WebSession get's explicitely created
in 
MockWebApplication.createRequestCycle():495
no matter if I override getWicketSession() or not. So I realized that
overriding getWicketSession() is kind of useless.


Anyone got a hint?

Thanks in advance!


Sven
-- 
View this message in context: 
http://www.nabble.com/org.apache.wicket.protocol.http.WebSession-cannot-be-cast-to-my.CustomSession-tp15480791p15480791.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to