Search in sources :

Example 1 with ZeroDemandResponse

use of org.springframework.web.reactive.result.view.ZeroDemandResponse 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 ZeroDemandResponse

use of org.springframework.web.reactive.result.view.ZeroDemandResponse 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)

Aggregations

Test (org.junit.jupiter.api.Test)2 ZeroDemandResponse (org.springframework.web.reactive.result.view.ZeroDemandResponse)2 ServerWebExchange (org.springframework.web.server.ServerWebExchange)2 DefaultServerWebExchange (org.springframework.web.server.adapter.DefaultServerWebExchange)2 AcceptHeaderLocaleContextResolver (org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver)2 DefaultWebSessionManager (org.springframework.web.server.session.DefaultWebSessionManager)2 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)2 HashMap (java.util.HashMap)1 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)1 ModelMap (org.springframework.ui.ModelMap)1