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
<[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
>  For additional commands, e-mail: [EMAIL PROTECTED]
>
>

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

Reply via email to