You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jörn Zaefferer <jo...@googlemail.com> on 2008/03/07 12:11:23 UTC
How to inject Spring Application context into WicketTester
Hi,
my wicket applicatin uses the SpringComponentInjector and @SpringBean
annotations, which works great at runtime where the application
context is present.
I'd like to use WicketTester for JUnit tests:
tester = new WicketTester(new MyApplication());
In MyApplication#init, the component injector is created:
addComponentInstantiationListener(new SpringComponentInjector(this));
That constructor loads the ApplicationContext via
WebApplicationContextUtils.getRequiredWebApplicationContext(webapp.getServletContext()
That is the part which fails in my test, because there is no
ApplicationContext stored in the servlet context. How can I fix that?
My attempts so far:
The description here doesn't help:
http://cwiki.apache.org/WICKET/spring.html#Spring-UnitTestingtheProxyApproach
The injector is already configured at that point.
The alternative would be to put the application context into the
ServletContext, so that WebApplicationContextUtils can find it. I've
found no way to access MockWebApplication.context to set it manually,
though I was able to set it by overwriting newServletContext. Though
.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
context); where context is of type AnnotApplicationContextMock yields
an IllegalStateException, because AnnotApplicationContextMock doesn't
implement WebApplicationContext.
Thanks
Jörn
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How to inject Spring Application context into WicketTester
Posted by Igor Vaynberg <ig...@gmail.com>.
spring wiki page shows how to set it up...
-igor
On Fri, Mar 7, 2008 at 3:11 AM, Jörn Zaefferer
<jo...@googlemail.com> wrote:
> Hi,
>
> my wicket applicatin uses the SpringComponentInjector and @SpringBean
> annotations, which works great at runtime where the application
> context is present.
>
> I'd like to use WicketTester for JUnit tests:
>
> tester = new WicketTester(new MyApplication());
> In MyApplication#init, the component injector is created:
> addComponentInstantiationListener(new SpringComponentInjector(this));
> That constructor loads the ApplicationContext via
> WebApplicationContextUtils.getRequiredWebApplicationContext(webapp.getServletContext()
>
> That is the part which fails in my test, because there is no
> ApplicationContext stored in the servlet context. How can I fix that?
>
> My attempts so far:
> The description here doesn't help:
> http://cwiki.apache.org/WICKET/spring.html#Spring-UnitTestingtheProxyApproach
> The injector is already configured at that point.
>
> The alternative would be to put the application context into the
> ServletContext, so that WebApplicationContextUtils can find it. I've
> found no way to access MockWebApplication.context to set it manually,
> though I was able to set it by overwriting newServletContext. Though
> .setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
> context); where context is of type AnnotApplicationContextMock yields
> an IllegalStateException, because AnnotApplicationContextMock doesn't
> implement WebApplicationContext.
>
> Thanks
> Jörn
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How to inject Spring Application context into WicketTester
Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
No I think its okay:) writing too many mails.. Check it out.. And ask..
Nino Saturnino Martinez Vazquez Wael wrote:
> Eek I might have been wrong.. Sorry..
>
> Nino Saturnino Martinez Vazquez Wael wrote:
>> Checkout the blog tutorial, the unit test part....
>>
>> http://cwiki.apache.org/confluence/display/WICKET/Blog+Tutorial
>>
>> Jörn Zaefferer wrote:
>>> Hi,
>>>
>>> my wicket applicatin uses the SpringComponentInjector and @SpringBean
>>> annotations, which works great at runtime where the application
>>> context is present.
>>>
>>> I'd like to use WicketTester for JUnit tests:
>>>
>>> tester = new WicketTester(new MyApplication());
>>> In MyApplication#init, the component injector is created:
>>> addComponentInstantiationListener(new SpringComponentInjector(this));
>>> That constructor loads the ApplicationContext via
>>> WebApplicationContextUtils.getRequiredWebApplicationContext(webapp.getServletContext()
>>>
>>>
>>> That is the part which fails in my test, because there is no
>>> ApplicationContext stored in the servlet context. How can I fix that?
>>>
>>> My attempts so far:
>>> The description here doesn't help:
>>> http://cwiki.apache.org/WICKET/spring.html#Spring-UnitTestingtheProxyApproach
>>>
>>> The injector is already configured at that point.
>>>
>>> The alternative would be to put the application context into the
>>> ServletContext, so that WebApplicationContextUtils can find it. I've
>>> found no way to access MockWebApplication.context to set it manually,
>>> though I was able to set it by overwriting newServletContext. Though
>>> .setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
>>>
>>> context); where context is of type AnnotApplicationContextMock yields
>>> an IllegalStateException, because AnnotApplicationContextMock doesn't
>>> implement WebApplicationContext.
>>>
>>> Thanks
>>> Jörn
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>
>
--
-Wicket for love
-Jme for fun
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How to inject Spring Application context into WicketTester
Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
Eek I might have been wrong.. Sorry..
Nino Saturnino Martinez Vazquez Wael wrote:
> Checkout the blog tutorial, the unit test part....
>
> http://cwiki.apache.org/confluence/display/WICKET/Blog+Tutorial
>
> Jörn Zaefferer wrote:
>> Hi,
>>
>> my wicket applicatin uses the SpringComponentInjector and @SpringBean
>> annotations, which works great at runtime where the application
>> context is present.
>>
>> I'd like to use WicketTester for JUnit tests:
>>
>> tester = new WicketTester(new MyApplication());
>> In MyApplication#init, the component injector is created:
>> addComponentInstantiationListener(new SpringComponentInjector(this));
>> That constructor loads the ApplicationContext via
>> WebApplicationContextUtils.getRequiredWebApplicationContext(webapp.getServletContext()
>>
>>
>> That is the part which fails in my test, because there is no
>> ApplicationContext stored in the servlet context. How can I fix that?
>>
>> My attempts so far:
>> The description here doesn't help:
>> http://cwiki.apache.org/WICKET/spring.html#Spring-UnitTestingtheProxyApproach
>>
>> The injector is already configured at that point.
>>
>> The alternative would be to put the application context into the
>> ServletContext, so that WebApplicationContextUtils can find it. I've
>> found no way to access MockWebApplication.context to set it manually,
>> though I was able to set it by overwriting newServletContext. Though
>> .setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
>>
>> context); where context is of type AnnotApplicationContextMock yields
>> an IllegalStateException, because AnnotApplicationContextMock doesn't
>> implement WebApplicationContext.
>>
>> Thanks
>> Jörn
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
--
-Wicket for love
-Jme for fun
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How to inject Spring Application context into WicketTester
Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
Checkout the blog tutorial, the unit test part....
http://cwiki.apache.org/confluence/display/WICKET/Blog+Tutorial
Jörn Zaefferer wrote:
> Hi,
>
> my wicket applicatin uses the SpringComponentInjector and @SpringBean
> annotations, which works great at runtime where the application
> context is present.
>
> I'd like to use WicketTester for JUnit tests:
>
> tester = new WicketTester(new MyApplication());
> In MyApplication#init, the component injector is created:
> addComponentInstantiationListener(new SpringComponentInjector(this));
> That constructor loads the ApplicationContext via
> WebApplicationContextUtils.getRequiredWebApplicationContext(webapp.getServletContext()
>
> That is the part which fails in my test, because there is no
> ApplicationContext stored in the servlet context. How can I fix that?
>
> My attempts so far:
> The description here doesn't help:
> http://cwiki.apache.org/WICKET/spring.html#Spring-UnitTestingtheProxyApproach
> The injector is already configured at that point.
>
> The alternative would be to put the application context into the
> ServletContext, so that WebApplicationContextUtils can find it. I've
> found no way to access MockWebApplication.context to set it manually,
> though I was able to set it by overwriting newServletContext. Though
> .setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
> context); where context is of type AnnotApplicationContextMock yields
> an IllegalStateException, because AnnotApplicationContextMock doesn't
> implement WebApplicationContext.
>
> Thanks
> Jörn
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
--
-Wicket for love
-Jme for fun
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How to inject Spring Application context into WicketTester
Posted by lars vonk <la...@gmail.com>.
Hi,
What we did is use the spring testing (see
http://static.springframework.org/spring/docs/2.5.x/reference/testing.html)
capabilities for this:
We created an abstract base class that all test cases that need to
test wicket pages or components
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/applicationContext.xml"})
@TransactionConfiguration
@Transactional
public abstract class AbstractWicketTestCase {
@Autowired
protected MyWebApplication wicketApplication;
protected WicketTester tester;
@Before
public void setup() {
tester = new WicketTest(wicketApplication);
}
}
Hopes this helps.
Lars
On Fri, Mar 7, 2008 at 12:11 PM, Jörn Zaefferer
<jo...@googlemail.com> wrote:
> Hi,
>
> my wicket applicatin uses the SpringComponentInjector and @SpringBean
> annotations, which works great at runtime where the application
> context is present.
>
> I'd like to use WicketTester for JUnit tests:
>
> tester = new WicketTester(new MyApplication());
> In MyApplication#init, the component injector is created:
> addComponentInstantiationListener(new SpringComponentInjector(this));
> That constructor loads the ApplicationContext via
> WebApplicationContextUtils.getRequiredWebApplicationContext(webapp.getServletContext()
>
> That is the part which fails in my test, because there is no
> ApplicationContext stored in the servlet context. How can I fix that?
>
> My attempts so far:
> The description here doesn't help:
> http://cwiki.apache.org/WICKET/spring.html#Spring-UnitTestingtheProxyApproach
> The injector is already configured at that point.
>
> The alternative would be to put the application context into the
> ServletContext, so that WebApplicationContextUtils can find it. I've
> found no way to access MockWebApplication.context to set it manually,
> though I was able to set it by overwriting newServletContext. Though
> .setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
> context); where context is of type AnnotApplicationContextMock yields
> an IllegalStateException, because AnnotApplicationContextMock doesn't
> implement WebApplicationContext.
>
> Thanks
> Jörn
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org