Search in sources :

Example 1 with AcceptHeaderLocaleContextResolver

use of org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver in project spring-framework by spring-projects.

the class FreeMarkerViewTests method subscribeWithoutDemand.

// gh-22754
@Test
public void subscribeWithoutDemand() {
    ZeroDemandResponse response = new ZeroDemandResponse();
    ServerWebExchange exchange = new DefaultServerWebExchange(MockServerHttpRequest.get("/path").build(), response, new DefaultWebSessionManager(), ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
    FreeMarkerView view = new FreeMarkerView();
    view.setApplicationContext(this.context);
    view.setConfiguration(this.freeMarkerConfig);
    view.setUrl("test.ftl");
    ModelMap model = new ExtendedModelMap();
    model.addAttribute("hello", "hi FreeMarker");
    view.render(model, null, exchange).subscribe();
    response.cancelWrite();
    response.checkForLeaks();
}
Also used : AcceptHeaderLocaleContextResolver(org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) DefaultServerWebExchange(org.springframework.web.server.adapter.DefaultServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) DefaultServerWebExchange(org.springframework.web.server.adapter.DefaultServerWebExchange) ZeroDemandResponse(org.springframework.web.reactive.result.view.ZeroDemandResponse) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) ModelMap(org.springframework.ui.ModelMap) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) DefaultWebSessionManager(org.springframework.web.server.session.DefaultWebSessionManager) Test(org.junit.jupiter.api.Test)

Example 2 with AcceptHeaderLocaleContextResolver

use of org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver in project spring-framework by spring-projects.

the class DefaultWebSessionManagerTests method setUp.

@BeforeEach
void setUp() throws Exception {
    given(this.createSession.save()).willReturn(Mono.empty());
    given(this.createSession.getId()).willReturn("create-session-id");
    given(this.updateSession.getId()).willReturn("update-session-id");
    given(this.sessionStore.createWebSession()).willReturn(Mono.just(this.createSession));
    given(this.sessionStore.retrieveSession(this.updateSession.getId())).willReturn(Mono.just(this.updateSession));
    this.sessionManager = new DefaultWebSessionManager();
    this.sessionManager.setSessionIdResolver(this.sessionIdResolver);
    this.sessionManager.setSessionStore(this.sessionStore);
    MockServerHttpRequest request = MockServerHttpRequest.get("/path").build();
    MockServerHttpResponse response = new MockServerHttpResponse();
    this.exchange = new DefaultServerWebExchange(request, response, this.sessionManager, ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
}
Also used : AcceptHeaderLocaleContextResolver(org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver) DefaultServerWebExchange(org.springframework.web.server.adapter.DefaultServerWebExchange) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with AcceptHeaderLocaleContextResolver

use of org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver in project spring-boot by spring-projects.

the class WebFluxAutoConfigurationTests method defaultLocaleContextResolver.

@Test
void defaultLocaleContextResolver() {
    this.contextRunner.run((context) -> {
        assertThat(context).hasSingleBean(LocaleContextResolver.class);
        LocaleContextResolver resolver = context.getBean(LocaleContextResolver.class);
        assertThat(((AcceptHeaderLocaleContextResolver) resolver).getDefaultLocale()).isNull();
    });
}
Also used : AcceptHeaderLocaleContextResolver(org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver) FixedLocaleContextResolver(org.springframework.web.server.i18n.FixedLocaleContextResolver) LocaleContextResolver(org.springframework.web.server.i18n.LocaleContextResolver) AcceptHeaderLocaleContextResolver(org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with AcceptHeaderLocaleContextResolver

use of org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver in project spring-framework by spring-projects.

the class NashornScriptTemplateTests method subscribeWithoutDemand.

// gh-22754
@Test
public void subscribeWithoutDemand() throws Exception {
    ZeroDemandResponse response = new ZeroDemandResponse();
    ServerWebExchange exchange = new DefaultServerWebExchange(MockServerHttpRequest.get("/path").build(), response, new DefaultWebSessionManager(), ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
    Map<String, Object> model = new HashMap<>();
    model.put("title", "Layout example");
    model.put("body", "This is the body");
    String viewUrl = "org/springframework/web/reactive/result/view/script/nashorn/template.html";
    ScriptTemplateView view = createViewWithUrl(viewUrl, ScriptTemplatingConfiguration.class);
    view.render(model, null, exchange).subscribe();
    response.cancelWrite();
    response.checkForLeaks();
}
Also used : AcceptHeaderLocaleContextResolver(org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) DefaultServerWebExchange(org.springframework.web.server.adapter.DefaultServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) DefaultServerWebExchange(org.springframework.web.server.adapter.DefaultServerWebExchange) ZeroDemandResponse(org.springframework.web.reactive.result.view.ZeroDemandResponse) HashMap(java.util.HashMap) DefaultWebSessionManager(org.springframework.web.server.session.DefaultWebSessionManager) Test(org.junit.jupiter.api.Test)

Example 5 with AcceptHeaderLocaleContextResolver

use of org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver in project spring-framework by spring-projects.

the class DefaultHandlerStrategiesBuilder method defaultConfiguration.

public void defaultConfiguration() {
    this.codecConfigurer.registerDefaults(true);
    this.exceptionHandlers.add(new WebFluxResponseStatusExceptionHandler());
    this.localeContextResolver = new AcceptHeaderLocaleContextResolver();
}
Also used : WebFluxResponseStatusExceptionHandler(org.springframework.web.reactive.handler.WebFluxResponseStatusExceptionHandler) AcceptHeaderLocaleContextResolver(org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver)

Aggregations

AcceptHeaderLocaleContextResolver (org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver)9 Test (org.junit.jupiter.api.Test)7 DefaultServerWebExchange (org.springframework.web.server.adapter.DefaultServerWebExchange)7 ServerWebExchange (org.springframework.web.server.ServerWebExchange)6 HashMap (java.util.HashMap)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Map (java.util.Map)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 BDDMockito.given (org.mockito.BDDMockito.given)4 Mockito.mock (org.mockito.Mockito.mock)4 Mockito.spy (org.mockito.Mockito.spy)4 Mockito.times (org.mockito.Mockito.times)4 Mockito.verify (org.mockito.Mockito.verify)4 ServerCodecConfigurer (org.springframework.http.codec.ServerCodecConfigurer)4 ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)4 MockServerHttpRequest (org.springframework.mock.http.server.reactive.MockServerHttpRequest)4 MockServerHttpResponse (org.springframework.mock.http.server.reactive.MockServerHttpResponse)4 OAuth2AuthorizationRequest (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest)4 OAuth2ParameterNames (org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames)4 WebSession (org.springframework.web.server.WebSession)4