Search in sources :

Example 6 with SessionLocaleResolver

use of org.springframework.web.servlet.i18n.SessionLocaleResolver in project cas by apereo.

the class CasLocaleChangeInterceptorTests method verifyRequestParamBeatsCasDefault.

@Test
public void verifyRequestParamBeatsCasDefault() throws Exception {
    val request = new MockHttpServletRequest();
    request.addParameter("locale", "it");
    val response = new MockHttpServletResponse();
    val resolver = new SessionLocaleResolver();
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, resolver);
    getInterceptor(false).preHandle(request, response, new Object());
    assertEquals(Locale.ITALIAN, resolver.resolveLocale(request));
}
Also used : lombok.val(lombok.val) SessionLocaleResolver(org.springframework.web.servlet.i18n.SessionLocaleResolver) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 7 with SessionLocaleResolver

use of org.springframework.web.servlet.i18n.SessionLocaleResolver in project cas by apereo.

the class CasLocaleChangeInterceptorTests method verifyRequestHeaderBeatsCasDefault.

@Test
public void verifyRequestHeaderBeatsCasDefault() throws Exception {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val resolver = new SessionLocaleResolver();
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, resolver);
    getInterceptor(false).preHandle(request, response, new Object());
    assertEquals(Locale.ENGLISH, resolver.resolveLocale(request));
}
Also used : lombok.val(lombok.val) SessionLocaleResolver(org.springframework.web.servlet.i18n.SessionLocaleResolver) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 8 with SessionLocaleResolver

use of org.springframework.web.servlet.i18n.SessionLocaleResolver in project cas by apereo.

the class CasLocaleChangeInterceptorTests method verifyForcedCasDefaultBeatsAll.

@Test
public void verifyForcedCasDefaultBeatsAll() throws Exception {
    val request = new MockHttpServletRequest();
    request.addParameter("locale", "it");
    val response = new MockHttpServletResponse();
    val resolver = new SessionLocaleResolver();
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, resolver);
    getInterceptor(true).preHandle(request, response, new Object());
    assertEquals(Locale.FRENCH, resolver.resolveLocale(request));
}
Also used : lombok.val(lombok.val) SessionLocaleResolver(org.springframework.web.servlet.i18n.SessionLocaleResolver) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 9 with SessionLocaleResolver

use of org.springframework.web.servlet.i18n.SessionLocaleResolver in project cas by apereo.

the class CasLocaleChangeInterceptorTests method verifyServiceHasLocaleAssigned.

@Test
public void verifyServiceHasLocaleAssigned() throws Exception {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val resolver = new SessionLocaleResolver();
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, resolver);
    val service = RegisteredServiceTestUtils.getService();
    when(argumentExtractor.extractService(any(HttpServletRequest.class))).thenReturn(service);
    val registeredService = RegisteredServiceTestUtils.getRegisteredService();
    registeredService.setLocale("${T(java.util.Locale).GERMAN.getLanguage()}");
    when(servicesManager.findServiceBy(any(Service.class))).thenReturn(registeredService);
    getInterceptor(false).preHandle(request, response, new Object());
    assertEquals(Locale.GERMAN, resolver.resolveLocale(request));
}
Also used : lombok.val(lombok.val) SessionLocaleResolver(org.springframework.web.servlet.i18n.SessionLocaleResolver) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Service(org.apereo.cas.authentication.principal.Service) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 10 with SessionLocaleResolver

use of org.springframework.web.servlet.i18n.SessionLocaleResolver in project nikita-noark5-core by HiOA-ABI.

the class AppWebMvcConfiguration method localeResolver.

/**
     * Set the LocaleResolver for the GUI portion of the application
     * By default english pages with be returned to the user
     * @return LocaleResolver
     */
@Bean
public LocaleResolver localeResolver() {
    SessionLocaleResolver slr = new SessionLocaleResolver();
    slr.setDefaultLocale(Locale.US);
    return slr;
}
Also used : SessionLocaleResolver(org.springframework.web.servlet.i18n.SessionLocaleResolver) Bean(org.springframework.context.annotation.Bean)

Aggregations

SessionLocaleResolver (org.springframework.web.servlet.i18n.SessionLocaleResolver)15 Bean (org.springframework.context.annotation.Bean)8 lombok.val (lombok.val)6 Test (org.junit.jupiter.api.Test)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 Locale (java.util.Locale)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Service (org.apereo.cas.authentication.principal.Service)1 WebContext (org.directwebremoting.WebContext)1 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)1 FactoryBean (org.springframework.beans.factory.FactoryBean)1 LocaleEditor (org.springframework.beans.propertyeditors.LocaleEditor)1 LocalSessionFactoryBean (org.springframework.orm.hibernate5.LocalSessionFactoryBean)1 SchedulerFactoryBean (org.springframework.scheduling.quartz.SchedulerFactoryBean)1 LocaleResolver (org.springframework.web.servlet.LocaleResolver)1