You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by mscoon <ms...@gmail.com> on 2014/09/01 12:18:30 UTC

Unit tests that use wicket's session and spring session

Hi all,

Might I ask if there are any pointers to writing tests for wicket that can
successfully access wicket's session (i.e. Session.get()) and spring's
session (i.e. use session scoped beans either by autowiring or using the
spring injector)?

Thanks
Marios

Re: Unit tests that use wicket's session and spring session

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

WicketTester.getSession() returns the Wicket session.  You can cast it to
your specialization.

Spring stores its session-scoped beans in as attributes in the http
session. There is a dummy http session in WicketTester tests so everything
should be fine. You don't need to do anything special here.
On Sep 1, 2014 1:19 PM, "mscoon" <ms...@gmail.com> wrote:

> Hi all,
>
> Might I ask if there are any pointers to writing tests for wicket that can
> successfully access wicket's session (i.e. Session.get()) and spring's
> session (i.e. use session scoped beans either by autowiring or using the
> spring injector)?
>
> Thanks
> Marios
>

Re: Unit tests that use wicket's session and spring session

Posted by mscoon <ms...@gmail.com>.
Thank you both for your answers.

Recent versions of Spring have their own way of creating a mock servlet
context and their own mock sessions and requests (MockHttpServletRequest)
and those cannot be combined with wicket (at least I didn't find a way to
do it), because if you go that route there is no wicket session.

I.e. annotating a test with @WebApplication and declaring an autowired
field as org.springframework.mock.web.MockHttpServletRequest will give you
a spring session but no wicket session.

If you instead use WicketTester then it all seems to work.


On Tue, Sep 2, 2014 at 4:04 PM, lucast <lu...@hotmail.com> wrote:

> Hi Marios,
> Have you had a look at the on-line wicket guide?
> https://wicket.apache.org/guide/guide/testingspring.html
>
> That is a really good chapter for setting up Wicket Spring testing.
>
> I hope that helps,
> Lucas
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Unit-tests-that-use-wicket-s-session-and-spring-session-tp4667270p4667297.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Unit tests that use wicket's session and spring session

Posted by lucast <lu...@hotmail.com>.
Hi Marios,
Have you had a look at the on-line wicket guide? 
https://wicket.apache.org/guide/guide/testingspring.html

That is a really good chapter for setting up Wicket Spring testing.

I hope that helps,
Lucas

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Unit-tests-that-use-wicket-s-session-and-spring-session-tp4667270p4667297.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org