use of org.springframework.context.i18n.TimeZoneAwareLocaleContext in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testResolveLocaleContextWithTimeZone.
@Test
public void testResolveLocaleContextWithTimeZone() {
MockHttpServletRequest request = new MockHttpServletRequest();
Cookie cookie = new Cookie("LanguageKoekje", "nl GMT+1");
request.setCookies(cookie);
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setCookieName("LanguageKoekje");
LocaleContext loc = resolver.resolveLocaleContext(request);
assertEquals("nl", loc.getLocale().getLanguage());
assertTrue(loc instanceof TimeZoneAwareLocaleContext);
assertEquals(TimeZone.getTimeZone("GMT+1"), ((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
use of org.springframework.context.i18n.TimeZoneAwareLocaleContext in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testResolveLocaleContextWithoutCookieAndDefaultLocale.
@Test
public void testResolveLocaleContextWithoutCookieAndDefaultLocale() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.TAIWAN);
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setDefaultLocale(Locale.GERMAN);
resolver.setDefaultTimeZone(TimeZone.getTimeZone("GMT+1"));
LocaleContext loc = resolver.resolveLocaleContext(request);
assertEquals(Locale.GERMAN, loc.getLocale());
assertTrue(loc instanceof TimeZoneAwareLocaleContext);
assertEquals(TimeZone.getTimeZone("GMT+1"), ((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
use of org.springframework.context.i18n.TimeZoneAwareLocaleContext in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testSetAndResolveLocaleContextWithTimeZoneOnly.
@Test
public void testSetAndResolveLocaleContextWithTimeZoneOnly() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setLocaleContext(request, response, new SimpleTimeZoneAwareLocaleContext(null, TimeZone.getTimeZone("GMT+1")));
Cookie cookie = response.getCookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME);
request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.GERMANY);
request.setCookies(cookie);
resolver = new CookieLocaleResolver();
LocaleContext loc = resolver.resolveLocaleContext(request);
assertEquals(Locale.GERMANY, loc.getLocale());
assertTrue(loc instanceof TimeZoneAwareLocaleContext);
assertEquals(TimeZone.getTimeZone("GMT+1"), ((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
use of org.springframework.context.i18n.TimeZoneAwareLocaleContext in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testResolveLocaleContextWithInvalidTimeZoneOnErrorDispatch.
@Test
public void testResolveLocaleContextWithInvalidTimeZoneOnErrorDispatch() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE, new ServletException());
Cookie cookie = new Cookie("LanguageKoekje", "nl X-MT");
request.setCookies(cookie);
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setDefaultTimeZone(TimeZone.getTimeZone("GMT+2"));
resolver.setCookieName("LanguageKoekje");
LocaleContext loc = resolver.resolveLocaleContext(request);
assertEquals("nl", loc.getLocale().getLanguage());
assertTrue(loc instanceof TimeZoneAwareLocaleContext);
assertEquals(TimeZone.getTimeZone("GMT+2"), ((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
Aggregations