예제 #1
0
  @Test
  public void testJstlLocaleIsSet() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("locale", "es");

    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setSession(new MockHttpSession(null));

    filter.doFilter(request, response, new MockFilterChain());

    assertNotNull(Config.get(request.getSession(), Config.FMT_LOCALE));
  }
예제 #2
0
  @Test
  public void testSetInvalidLocale() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("locale", "foo");

    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setSession(new MockHttpSession(null));

    filter.doFilter(request, response, new MockFilterChain());

    // a locale will get set regardless - there's no such thing as an invalid one
    assertNotNull(request.getSession().getAttribute(Constants.PREFERRED_LOCALE_KEY));
  }
예제 #3
0
  @Test
  public void testSetLocaleInSessionWhenSessionIsNull() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("locale", "es");

    MockHttpServletResponse response = new MockHttpServletResponse();
    filter.doFilter(request, response, new MockFilterChain());

    // no session, should result in null
    assertNull(request.getSession().getAttribute(Constants.PREFERRED_LOCALE_KEY));
    // thread locale should always have it, regardless of session
    assertNotNull(LocaleContextHolder.getLocale());
  }
예제 #4
0
  @Test
  public void testLocaleAndCountry() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(new MockHttpSession());
    request.addParameter("locale", "zh_TW");

    MockHttpServletResponse response = new MockHttpServletResponse();
    filter.doFilter(request, response, new MockFilterChain());

    // session not null, should result in not null
    Locale locale = (Locale) request.getSession().getAttribute(Constants.PREFERRED_LOCALE_KEY);
    assertNotNull(locale);
    assertEquals(new Locale("zh", "TW"), locale);
  }