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;
}
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));
}
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();
}
Aggregations