Announcement Announcement Module
Collapse
No announcement yet.
Easymock + StrutsTestCase + DelegatingActionProxy Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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);

    Comment


    • #3
      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.

      Comment


      • #4
        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 ?

        Comment

        Working...
        X