Results 1 to 4 of 4

Thread: Easymock + StrutsTestCase + DelegatingActionProxy

  1. #1
    Join Date
    Feb 2006
    Posts
    8

    Default Easymock + StrutsTestCase + DelegatingActionProxy

    Hi,

    I would like to unit test my struts actions (that are currently spring-managed using ContextLoaderPlugin and DelegatingActionProxy) with strutstestcase and easymock.

    I can use StrutsTestCase only for integration tests at the moment, because the real dependencies, as configured in applicationContext.xml are injected into my actions. I want my Easymock objects to be used by the actions instead.

    Since struts actions are singletons, is there not a way to access the instances somehow, so I can manually inject my mocks in the testcase?

    If that's not possible, what would you think of making the dependencies of my actions static? So I could use MyAction.setBlaService(blaMock); in my tests.
    Would this have any drawbacks?

  2. #2
    Join Date
    Feb 2006
    Posts
    8

    Default

    I found a solution that seems to works for me now:

    Code:
    context = (WebApplicationContext) getActionServlet().getServletContext().getAttribute("org.springframework.web.struts.ContextLoaderPlugIn.CONTEXT.");
    HomeAction homeAction = (HomeAction) context.getBean("/toHome");
    homeAction.setLoggingConsultDelegate(loggingConsultDelegateMock);

  3. #3
    Join Date
    Jul 2006
    Posts
    8

    Default

    Quote Originally Posted by knot
    I found a solution that seems to works for me now:

    Code:
    context = (WebApplicationContext) getActionServlet().getServletContext().getAttribute("org.springframework.web.struts.ContextLoaderPlugIn.CONTEXT.");
    HomeAction homeAction = (HomeAction) context.getBean("/toHome");
    homeAction.setLoggingConsultDelegate(loggingConsultDelegateMock);
    Very nice. This is close to what I need but I am stumped by a problem that you may be able to help with.

    If the struts action has a constructor and Spring handles injecting a referenced bean as the constructor-arg how can you get a Mock injected instead of the referenced bean?

    I have spent days thinking about it and cannot figure it out.

  4. #4
    Join Date
    Aug 2012
    Posts
    2

    Default

    Hi
    I am trying to use MockStrutsTest case to test my application that uses DelegatingActionProxy. The classic method (for pure struts action testing...i.e providing the setRequestPathInfo, requestParameters and actionPerform() ..) doesn't seem to work in this case. Can anyone suggest how can I go about this ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •