Quantcast

Setting the request locale in a unit test

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Setting the request locale in a unit test

David

How can I set the locale of the request inside a (spock) unit test method?

I've tried do

request.addHeader('Accept-Language', 'sv-SE')
and adding
    environments {
      test {
        Locale.setDefault(new Locale('sv_SE'))
      }
in BootStrap.groovy, but request.locale still gives 'en'.

I've also tried to use the localeResolver (def localeResolver, applicationContext.localeResolver and applicationContext.getBean('localeResolver')) but all I get is null.

request.locale and request.locales are both read-only btw.

Running Grails-2.0.3 and spock-0.6.

Google didn't help me, so any suggestions are welcome!

/David
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Setting the request locale in a unit test

David
This post was updated on .

Note to myself:

request.addPreferredLocale(new Locale('sv_SE'))
//defined in org.springframework.mock.web.MockHttpServletRequest

/David

Loading...