Search in sources :

Example 1 with SimpleLocaleContext

use of cn.taketoday.core.i18n.SimpleLocaleContext in project today-infrastructure by TAKETODAY.

the class CookieLocaleResolverTests method testSetAndResolveLocaleContext.

@Test
public void testSetAndResolveLocaleContext() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockServletRequestContext requestContext = new MockServletRequestContext(request, response);
    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setLocaleContext(requestContext, new SimpleLocaleContext(new Locale("nl", "")));
    Cookie cookie = response.getCookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME);
    request = new MockHttpServletRequest();
    request.setCookies(cookie);
    resolver = new CookieLocaleResolver();
    LocaleContext loc = resolver.resolveLocaleContext(requestContext);
    assertThat(loc.getLocale().getLanguage()).isEqualTo("nl");
    boolean condition = loc instanceof TimeZoneAwareLocaleContext;
    assertThat(condition).isTrue();
    assertThat(((TimeZoneAwareLocaleContext) loc).getTimeZone()).isNull();
}
Also used : Locale(java.util.Locale) Cookie(jakarta.servlet.http.Cookie) SimpleLocaleContext(cn.taketoday.core.i18n.SimpleLocaleContext) TimeZoneAwareLocaleContext(cn.taketoday.core.i18n.TimeZoneAwareLocaleContext) SimpleTimeZoneAwareLocaleContext(cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext) SimpleLocaleContext(cn.taketoday.core.i18n.SimpleLocaleContext) LocaleContext(cn.taketoday.core.i18n.LocaleContext) TimeZoneAwareLocaleContext(cn.taketoday.core.i18n.TimeZoneAwareLocaleContext) SimpleTimeZoneAwareLocaleContext(cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) MockHttpServletResponse(cn.taketoday.web.mock.MockHttpServletResponse) MockServletRequestContext(cn.taketoday.web.servlet.MockServletRequestContext) Test(org.junit.jupiter.api.Test)

Example 2 with SimpleLocaleContext

use of cn.taketoday.core.i18n.SimpleLocaleContext in project today-framework by TAKETODAY.

the class CookieLocaleResolverTests method testSetAndResolveLocaleContext.

@Test
public void testSetAndResolveLocaleContext() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockServletRequestContext requestContext = new MockServletRequestContext(request, response);
    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setLocaleContext(requestContext, new SimpleLocaleContext(new Locale("nl", "")));
    Cookie cookie = response.getCookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME);
    request = new MockHttpServletRequest();
    request.setCookies(cookie);
    resolver = new CookieLocaleResolver();
    LocaleContext loc = resolver.resolveLocaleContext(requestContext);
    assertThat(loc.getLocale().getLanguage()).isEqualTo("nl");
    boolean condition = loc instanceof TimeZoneAwareLocaleContext;
    assertThat(condition).isTrue();
    assertThat(((TimeZoneAwareLocaleContext) loc).getTimeZone()).isNull();
}
Also used : Locale(java.util.Locale) Cookie(jakarta.servlet.http.Cookie) SimpleLocaleContext(cn.taketoday.core.i18n.SimpleLocaleContext) TimeZoneAwareLocaleContext(cn.taketoday.core.i18n.TimeZoneAwareLocaleContext) SimpleTimeZoneAwareLocaleContext(cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext) SimpleLocaleContext(cn.taketoday.core.i18n.SimpleLocaleContext) LocaleContext(cn.taketoday.core.i18n.LocaleContext) TimeZoneAwareLocaleContext(cn.taketoday.core.i18n.TimeZoneAwareLocaleContext) SimpleTimeZoneAwareLocaleContext(cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext) MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) MockHttpServletResponse(cn.taketoday.web.testfixture.servlet.MockHttpServletResponse) MockServletRequestContext(cn.taketoday.web.servlet.MockServletRequestContext) Test(org.junit.jupiter.api.Test)

Aggregations

LocaleContext (cn.taketoday.core.i18n.LocaleContext)2 SimpleLocaleContext (cn.taketoday.core.i18n.SimpleLocaleContext)2 SimpleTimeZoneAwareLocaleContext (cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext)2 TimeZoneAwareLocaleContext (cn.taketoday.core.i18n.TimeZoneAwareLocaleContext)2 MockServletRequestContext (cn.taketoday.web.servlet.MockServletRequestContext)2 Cookie (jakarta.servlet.http.Cookie)2 Locale (java.util.Locale)2 Test (org.junit.jupiter.api.Test)2 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)1 MockHttpServletResponse (cn.taketoday.web.mock.MockHttpServletResponse)1 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)1 MockHttpServletResponse (cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)1