Search in sources :

Example 1 with SimpleTimeZoneAwareLocaleContext

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

the class CookieLocaleResolverTests method testSetAndResolveLocaleContextWithTimeZoneOnly.

@Test
public void testSetAndResolveLocaleContextWithTimeZoneOnly() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockServletRequestContext requestContext = new MockServletRequestContext(request, response);
    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setLocaleContext(requestContext, 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);
    requestContext = new MockServletRequestContext(request, response);
    resolver = new CookieLocaleResolver();
    LocaleContext loc = resolver.resolveLocaleContext(requestContext);
    assertThat(loc.getLocale()).isEqualTo(Locale.GERMANY);
    boolean condition = loc instanceof TimeZoneAwareLocaleContext;
    assertThat(condition).isTrue();
    assertThat(((TimeZoneAwareLocaleContext) loc).getTimeZone()).isEqualTo(TimeZone.getTimeZone("GMT+1"));
}
Also used : Cookie(jakarta.servlet.http.Cookie) TimeZoneAwareLocaleContext(cn.taketoday.core.i18n.TimeZoneAwareLocaleContext) SimpleTimeZoneAwareLocaleContext(cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext) SimpleLocaleContext(cn.taketoday.core.i18n.SimpleLocaleContext) LocaleContext(cn.taketoday.core.i18n.LocaleContext) SimpleTimeZoneAwareLocaleContext(cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext) 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 SimpleTimeZoneAwareLocaleContext

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

the class CookieLocaleResolverTests method testSetAndResolveLocaleContextWithTimeZone.

@Test
public void testSetAndResolveLocaleContextWithTimeZone() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockServletRequestContext requestContext = new MockServletRequestContext(request, response);
    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setLocaleContext(requestContext, new SimpleTimeZoneAwareLocaleContext(new Locale("nl", ""), TimeZone.getTimeZone("GMT+1")));
    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()).isEqualTo(TimeZone.getTimeZone("GMT+1"));
}
Also used : Locale(java.util.Locale) Cookie(jakarta.servlet.http.Cookie) TimeZoneAwareLocaleContext(cn.taketoday.core.i18n.TimeZoneAwareLocaleContext) SimpleTimeZoneAwareLocaleContext(cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext) SimpleLocaleContext(cn.taketoday.core.i18n.SimpleLocaleContext) LocaleContext(cn.taketoday.core.i18n.LocaleContext) SimpleTimeZoneAwareLocaleContext(cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext) 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 3 with SimpleTimeZoneAwareLocaleContext

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

the class CookieLocaleResolverTests method testSetAndResolveLocaleContextWithTimeZone.

@Test
public void testSetAndResolveLocaleContextWithTimeZone() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockServletRequestContext requestContext = new MockServletRequestContext(request, response);
    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setLocaleContext(requestContext, new SimpleTimeZoneAwareLocaleContext(new Locale("nl", ""), TimeZone.getTimeZone("GMT+1")));
    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()).isEqualTo(TimeZone.getTimeZone("GMT+1"));
}
Also used : Locale(java.util.Locale) Cookie(jakarta.servlet.http.Cookie) TimeZoneAwareLocaleContext(cn.taketoday.core.i18n.TimeZoneAwareLocaleContext) SimpleTimeZoneAwareLocaleContext(cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext) SimpleLocaleContext(cn.taketoday.core.i18n.SimpleLocaleContext) LocaleContext(cn.taketoday.core.i18n.LocaleContext) SimpleTimeZoneAwareLocaleContext(cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext) 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)

Example 4 with SimpleTimeZoneAwareLocaleContext

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

the class CookieLocaleResolverTests method testSetAndResolveLocaleContextWithTimeZoneOnly.

@Test
public void testSetAndResolveLocaleContextWithTimeZoneOnly() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockServletRequestContext requestContext = new MockServletRequestContext(request, response);
    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setLocaleContext(requestContext, 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);
    requestContext = new MockServletRequestContext(request, response);
    resolver = new CookieLocaleResolver();
    LocaleContext loc = resolver.resolveLocaleContext(requestContext);
    assertThat(loc.getLocale()).isEqualTo(Locale.GERMANY);
    boolean condition = loc instanceof TimeZoneAwareLocaleContext;
    assertThat(condition).isTrue();
    assertThat(((TimeZoneAwareLocaleContext) loc).getTimeZone()).isEqualTo(TimeZone.getTimeZone("GMT+1"));
}
Also used : Cookie(jakarta.servlet.http.Cookie) TimeZoneAwareLocaleContext(cn.taketoday.core.i18n.TimeZoneAwareLocaleContext) SimpleTimeZoneAwareLocaleContext(cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext) SimpleLocaleContext(cn.taketoday.core.i18n.SimpleLocaleContext) LocaleContext(cn.taketoday.core.i18n.LocaleContext) SimpleTimeZoneAwareLocaleContext(cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext) 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)4 SimpleLocaleContext (cn.taketoday.core.i18n.SimpleLocaleContext)4 SimpleTimeZoneAwareLocaleContext (cn.taketoday.core.i18n.SimpleTimeZoneAwareLocaleContext)4 TimeZoneAwareLocaleContext (cn.taketoday.core.i18n.TimeZoneAwareLocaleContext)4 MockServletRequestContext (cn.taketoday.web.servlet.MockServletRequestContext)4 Cookie (jakarta.servlet.http.Cookie)4 Test (org.junit.jupiter.api.Test)4 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.web.mock.MockHttpServletResponse)2 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)2 Locale (java.util.Locale)2