Search in sources :

Example 1 with ThymeleafReactiveViewResolver

use of org.thymeleaf.spring5.view.reactive.ThymeleafReactiveViewResolver in project thymeleaf-tests by thymeleaf.

the class ThymeleafReactiveViewTest method testSeveralConversionServices.

@Test
public void testSeveralConversionServices() throws Exception {
    final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring5/view/applicationContextConversionService.xml");
    final SpringWebFluxTemplateEngine templateEngine = new SpringWebFluxTemplateEngine();
    final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setPrefix("spring5/view/");
    templateResolver.setSuffix(".html");
    templateEngine.setTemplateResolver(templateResolver);
    final ThymeleafReactiveViewResolver resolver = new ThymeleafReactiveViewResolver();
    resolver.setApplicationContext(context);
    resolver.setTemplateEngine(templateEngine);
    resolver.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_HTML));
    // testview2 does not exist as a declared bean at the application context
    final Mono<View> view = resolver.resolveViewName("testSeveralConversionServices", Locale.US);
    final Map<String, Object> model = new ModelMap();
    model.put("one", "one");
    final TestingServerWebExchange exchange = new TestingServerWebExchange("/testing", new HashMap<>(), new HashMap<>(), new HashMap<>());
    view.flatMap(v -> v.render(model, MediaType.TEXT_HTML, exchange)).block();
}
Also used : ThymeleafReactiveViewResolver(org.thymeleaf.spring5.view.reactive.ThymeleafReactiveViewResolver) ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) MediaType(org.springframework.http.MediaType) HashMap(java.util.HashMap) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) ModelMap(org.springframework.ui.ModelMap) Locale(java.util.Locale) Map(java.util.Map) SpringWebFluxTemplateEngine(org.thymeleaf.spring5.SpringWebFluxTemplateEngine) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) View(org.springframework.web.reactive.result.view.View) Collections(java.util.Collections) TestingServerWebExchange(org.thymeleaf.spring5.reactive.exchange.TestingServerWebExchange) SpringWebFluxTemplateEngine(org.thymeleaf.spring5.SpringWebFluxTemplateEngine) ModelMap(org.springframework.ui.ModelMap) View(org.springframework.web.reactive.result.view.View) ThymeleafReactiveViewResolver(org.thymeleaf.spring5.view.reactive.ThymeleafReactiveViewResolver) ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) TestingServerWebExchange(org.thymeleaf.spring5.reactive.exchange.TestingServerWebExchange) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Aggregations

Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Test (org.junit.Test)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 MediaType (org.springframework.http.MediaType)1 ModelMap (org.springframework.ui.ModelMap)1 View (org.springframework.web.reactive.result.view.View)1 SpringWebFluxTemplateEngine (org.thymeleaf.spring5.SpringWebFluxTemplateEngine)1 TestingServerWebExchange (org.thymeleaf.spring5.reactive.exchange.TestingServerWebExchange)1 ThymeleafReactiveViewResolver (org.thymeleaf.spring5.view.reactive.ThymeleafReactiveViewResolver)1 ClassLoaderTemplateResolver (org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)1 Mono (reactor.core.publisher.Mono)1