You could also take a look at the blog tutorial, has the solution for this as I remember..

http://cwiki.apache.org/WICKET/blog-tutorial.html

From another example here:

final ApplicationContext context = new ClassPathXmlApplicationContext(
               "applicationContext.xml");
       IDBDao base = (IDBDao) context.getBean("dBDao");
       dbProvider = base;
       base.generateDummyData();
       // 2. setup mock injection environment
AnnotApplicationContextMock appctx = new AnnotApplicationContextMock();
       appctx.putBean("dBDao", dbProvider);

ZeuzGroupApplication zeuzGroupApplication = new ZeuzGroupApplication();
       zeuzGroupApplication
               .setSpringComponentInjector(new SpringComponentInjector(
                       zeuzGroupApplication, appctx));
       wicketTester = new WicketTester(zeuzGroupApplication);




Sven Schliesing wrote:
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

--
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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

Reply via email to