Search in sources :

Example 1 with ViewResolver

use of org.springframework.web.reactive.result.view.ViewResolver in project spring-framework by spring-projects.

the class WebFluxConfigurationSupport method viewResolutionResultHandler.

@Bean
public ViewResolutionResultHandler viewResolutionResultHandler() {
    ViewResolverRegistry registry = new ViewResolverRegistry(getApplicationContext());
    configureViewResolvers(registry);
    List<ViewResolver> resolvers = registry.getViewResolvers();
    ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolvers, webFluxContentTypeResolver(), webFluxAdapterRegistry());
    handler.setDefaultViews(registry.getDefaultViews());
    handler.setOrder(registry.getOrder());
    return handler;
}
Also used : ViewResolutionResultHandler(org.springframework.web.reactive.result.view.ViewResolutionResultHandler) ViewResolver(org.springframework.web.reactive.result.view.ViewResolver) Bean(org.springframework.context.annotation.Bean)

Example 2 with ViewResolver

use of org.springframework.web.reactive.result.view.ViewResolver in project spring-framework by spring-projects.

the class WebFluxConfigurationSupportTests method viewResolutionResultHandler.

@Test
public void viewResolutionResultHandler() throws Exception {
    ApplicationContext context = loadConfig(CustomViewResolverConfig.class);
    String name = "viewResolutionResultHandler";
    ViewResolutionResultHandler handler = context.getBean(name, ViewResolutionResultHandler.class);
    assertNotNull(handler);
    assertEquals(Ordered.LOWEST_PRECEDENCE, handler.getOrder());
    List<ViewResolver> resolvers = handler.getViewResolvers();
    assertEquals(1, resolvers.size());
    assertEquals(FreeMarkerViewResolver.class, resolvers.get(0).getClass());
    List<View> views = handler.getDefaultViews();
    assertEquals(1, views.size());
    MimeType type = MimeTypeUtils.parseMimeType("application/json;charset=UTF-8");
    assertEquals(type, views.get(0).getSupportedMediaTypes().get(0));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ViewResolutionResultHandler(org.springframework.web.reactive.result.view.ViewResolutionResultHandler) FreeMarkerViewResolver(org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver) ViewResolver(org.springframework.web.reactive.result.view.ViewResolver) HttpMessageWriterView(org.springframework.web.reactive.result.view.HttpMessageWriterView) View(org.springframework.web.reactive.result.view.View) MimeType(org.springframework.util.MimeType) Test(org.junit.Test)

Example 3 with ViewResolver

use of org.springframework.web.reactive.result.view.ViewResolver in project spring-framework by spring-projects.

the class DefaultRenderingResponseTests method render.

@Test
public void render() throws Exception {
    Map<String, Object> model = Collections.singletonMap("foo", "bar");
    Mono<RenderingResponse> result = RenderingResponse.create("view").modelAttributes(model).build();
    MockServerWebExchange exchange = MockServerHttpRequest.get("http://localhost").toExchange();
    ViewResolver viewResolver = mock(ViewResolver.class);
    View view = mock(View.class);
    when(viewResolver.resolveViewName("view", Locale.ENGLISH)).thenReturn(Mono.just(view));
    when(view.render(model, null, exchange)).thenReturn(Mono.empty());
    List<ViewResolver> viewResolvers = new ArrayList<>();
    viewResolvers.add(viewResolver);
    HandlerStrategies mockConfig = mock(HandlerStrategies.class);
    when(mockConfig.viewResolvers()).thenReturn(viewResolvers::stream);
    StepVerifier.create(result).expectNextMatches(response -> "view".equals(response.name()) && model.equals(response.model())).expectComplete().verify();
}
Also used : ArrayList(java.util.ArrayList) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) ViewResolver(org.springframework.web.reactive.result.view.ViewResolver) View(org.springframework.web.reactive.result.view.View) Test(org.junit.Test)

Aggregations

ViewResolver (org.springframework.web.reactive.result.view.ViewResolver)3 Test (org.junit.Test)2 View (org.springframework.web.reactive.result.view.View)2 ViewResolutionResultHandler (org.springframework.web.reactive.result.view.ViewResolutionResultHandler)2 ArrayList (java.util.ArrayList)1 ApplicationContext (org.springframework.context.ApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)1 MimeType (org.springframework.util.MimeType)1 HttpMessageWriterView (org.springframework.web.reactive.result.view.HttpMessageWriterView)1 FreeMarkerViewResolver (org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver)1