use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testResolveLocaleWithoutCookie.
@Test
public void testResolveLocaleWithoutCookie() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.TAIWAN);
CookieLocaleResolver resolver = new CookieLocaleResolver();
Locale loc = resolver.resolveLocale(request);
assertEquals(request.getLocale(), loc);
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testResolveLocaleWithoutCookieAndDefaultLocale.
@Test
public void testResolveLocaleWithoutCookieAndDefaultLocale() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.TAIWAN);
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setDefaultLocale(Locale.GERMAN);
Locale loc = resolver.resolveLocale(request);
assertEquals(Locale.GERMAN, loc);
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testSetLocaleToNull.
@Test
public void testSetLocaleToNull() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.TAIWAN);
Cookie cookie = new Cookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME, Locale.UK.toString());
request.setCookies(cookie);
MockHttpServletResponse response = new MockHttpServletResponse();
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setLocale(request, response, null);
Locale locale = (Locale) request.getAttribute(CookieLocaleResolver.LOCALE_REQUEST_ATTRIBUTE_NAME);
assertEquals(Locale.TAIWAN, locale);
Cookie[] cookies = response.getCookies();
assertEquals(1, cookies.length);
Cookie localeCookie = cookies[0];
assertEquals(CookieLocaleResolver.DEFAULT_COOKIE_NAME, localeCookie.getName());
assertEquals("", localeCookie.getValue());
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testResolveLocaleContextWithoutCookie.
@Test
public void testResolveLocaleContextWithoutCookie() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.TAIWAN);
CookieLocaleResolver resolver = new CookieLocaleResolver();
LocaleContext loc = resolver.resolveLocaleContext(request);
assertEquals(request.getLocale(), loc.getLocale());
assertTrue(loc instanceof TimeZoneAwareLocaleContext);
assertNull(((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
use of org.springframework.mock.web.test.MockHttpServletRequest in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testSetLocaleContextToNullWithDefault.
@Test
public void testSetLocaleContextToNullWithDefault() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.TAIWAN);
Cookie cookie = new Cookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME, Locale.UK.toString());
request.setCookies(cookie);
MockHttpServletResponse response = new MockHttpServletResponse();
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setDefaultLocale(Locale.CANADA_FRENCH);
resolver.setDefaultTimeZone(TimeZone.getTimeZone("GMT+1"));
resolver.setLocaleContext(request, response, null);
Locale locale = (Locale) request.getAttribute(CookieLocaleResolver.LOCALE_REQUEST_ATTRIBUTE_NAME);
assertEquals(Locale.CANADA_FRENCH, locale);
TimeZone timeZone = (TimeZone) request.getAttribute(CookieLocaleResolver.TIME_ZONE_REQUEST_ATTRIBUTE_NAME);
assertEquals(TimeZone.getTimeZone("GMT+1"), timeZone);
Cookie[] cookies = response.getCookies();
assertEquals(1, cookies.length);
Cookie localeCookie = cookies[0];
assertEquals(CookieLocaleResolver.DEFAULT_COOKIE_NAME, localeCookie.getName());
assertEquals("", localeCookie.getValue());
}
Aggregations