Search in sources :

Example 1 with SpringWebFluxTemplateEngine

use of org.thymeleaf.spring5.SpringWebFluxTemplateEngine in project thymeleaf-tests by thymeleaf.

the class AbstractSpring5ReactiveTest method initTemplateEngine.

@BeforeClass
public static void initTemplateEngine() {
    final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setPrefix(ReactiveTestUtils.TEMPLATE_PATH_BASE);
    templateResolver.setSuffix(".html");
    templateEngine = new SpringWebFluxTemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
    bufferFactory = new DefaultDataBufferFactory();
    htmlMediaType = MediaType.TEXT_HTML;
    sseMediaType = MediaType.TEXT_EVENT_STREAM;
    charset = Charset.forName("UTF-8");
}
Also used : ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) ISpringWebFluxTemplateEngine(org.thymeleaf.spring5.ISpringWebFluxTemplateEngine) SpringWebFluxTemplateEngine(org.thymeleaf.spring5.SpringWebFluxTemplateEngine) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) BeforeClass(org.junit.BeforeClass)

Example 2 with SpringWebFluxTemplateEngine

use of org.thymeleaf.spring5.SpringWebFluxTemplateEngine 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

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