Announcement Announcement Module
Collapse
No announcement yet.
EasyMock Testing : Errors - Controller does not run in an ApplicationContext Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • EasyMock Testing : Errors - Controller does not run in an ApplicationContext

    Hi,

    I am facing a problem while testing a controller which is extending SimpleFormController.

    I have tried to read some message from resource file using:
    getApplicationContext().getMessage(key, args[], local);

    while testing this controller using EasyMock, its complaining with the message "
    AbcController does not run in an ApplicationContext.

    Your guidence will be highly appricated.

    regards,
    bakul.

  • #2
    I have the same issue. Is there a solution to this?

    The error is being generated from the ApplicationObjectSupport object and getMessageSourceAccessor() method. The test case extends AbstractDependencyInjectionSpringContextTests and the getConfigLocations returns valid paths for the spring configuration.

    Any help would be appreciated.

    Cheers
    Neil

    Comment


    • #3
      How did you initialise your Controller? You have to either set the ApplicationContext manually, or use one to instantiate the Controller.

      Comment


      • #4
        Thanks for the reply David. The issue has now been resolved as follows.

        The mock test extends the class AbstractDependencyInjectionSpringContextTests. The following code configures the spring application context.

        private static String[] paths = {"classpath:applicationContext.xml", "classpath:LAP-servlet-test.xml"};

        protected String[] getConfigLocations()
        {
        return paths;
        }


        I have updated the code to get the controller automatically (previously using dependency injection) and the issue is resolved. The code I that works is as follows.

        this.applicationContext.refresh();
        return (MyController) this.applicationContext.getBean("myController", MyController.class);

        Note we had another issue where we needed a new version of the controller for each test which is where the refresh code comes from. As such we get a new controller object for each test.

        Cheers
        Neil

        Comment

        Working...
        X