Hi,

Ik had the same problem. I digged in the code and found that the Mock
implementation of the request used -as you say- the default Locale.
Unfortunately, there was no way to set de Locale on that mock request...

I ended up to set the default locale using Locale.setDefault(getLocale())
when I create the WicketTester instance. (getLocale() can then be overridden
by concerned Test)
This might not be the most elegant solution, but it certainly does its
job....

On Thu, Oct 15, 2009 at 1:45 PM, Per Newgro <[email protected]> wrote:

> Hi
>
> i would like to test my code on new session creation in application.
> A task in this process is to validate the resulting session locale.
> Because the session locale will be taken from the request i have to provide
> my test value in the Wickettester.servletRequest attribute.
>
> But how can i set it manually to avoid usage of system default locale?
>
> MyApplication
> public Session newSession(Request request, Response response) {
>  MySession session = new MySession(request);
>  if (isInvalid(session.getLocale())) {
>    session.setLocale(Locale.ENGLISH);
>  }
>  return session;
> }
>
> private boolean isInvalid(Locale locale) {
>  return isUndefined(new Locale(locale.getLanguage()))
>      && isUndefined(locale);
> }
>
> private boolean isUndefined(Locale locale) {
>  return !_locales.contains(locale);
> }
>
> MyApplicationTest
>
> @Test
> public void invalidLanguageLocale() {
>  assertEquals(Locale.CHINESE,
>    prepareSession(toHtmlHeaderString(Locale.ENGLISH)).getLocale());
> }
>
> private String toHtmlHeaderString(Locale locale) {
>  String result = locale.getLanguage();
>  if (locale.getCountry() != null
>   && locale.getCountry().trim().length() > 0) {
>    result = result + "-" + locale.getCountry();
>  }
>  return result;
> }
>
> private Session prepareSession(String locale) {
>  _tester.setupRequestAndResponse();
>  MockHttpServletRequest request = _tester.getServletRequest();
>  request.addHeader("Accept-Language", locale);
>  Session session = (Session)
>                _testee.newSession(_tester.getWicketRequest(),
>                _tester.getWicketResponse());
>  return session;
> }
>
> --
> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>


-- 
Pieter Degraeuwe
Systemworks bvba
Belgiëlaan 61
9070 Destelbergen
GSM: +32 (0)485/68.60.85
Email: [email protected]
visit us at http://www.systemworks.be

Reply via email to