Exemplo n.º 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));
  }
Exemplo n.º 2
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());
  }
Exemplo n.º 3
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));
  }
Exemplo n.º 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);
  }
Exemplo n.º 5
0
 @Before
 public void setUp() throws Exception {
   filter = new LocaleFilter();
   filter.init(new MockFilterConfig());
 }