Search in sources :

Example 1 with ISpringWebFluxTemplateEngine

use of org.thymeleaf.spring6.ISpringWebFluxTemplateEngine in project spring-boot by spring-projects.

the class ThymeleafReactiveAutoConfigurationTests method useDataDialect.

@Test
void useDataDialect() {
    this.contextRunner.run((context) -> {
        ISpringWebFluxTemplateEngine engine = context.getBean(ISpringWebFluxTemplateEngine.class);
        Context attrs = new Context(Locale.UK, Collections.singletonMap("foo", "bar"));
        String result = engine.process("data-dialect", attrs).trim();
        assertThat(result).isEqualTo("<html><body data-foo=\"bar\"></body></html>");
    });
}
Also used : WebContext(org.thymeleaf.context.WebContext) Context(org.thymeleaf.context.Context) ISpringWebFluxTemplateEngine(org.thymeleaf.spring6.ISpringWebFluxTemplateEngine) Test(org.junit.jupiter.api.Test)

Example 2 with ISpringWebFluxTemplateEngine

use of org.thymeleaf.spring6.ISpringWebFluxTemplateEngine in project spring-boot by spring-projects.

the class ThymeleafReactiveAutoConfigurationTests method renderTemplate.

@Test
void renderTemplate() {
    this.contextRunner.run((context) -> {
        ISpringWebFluxTemplateEngine engine = context.getBean(ISpringWebFluxTemplateEngine.class);
        Context attrs = new Context(Locale.UK, Collections.singletonMap("foo", "bar"));
        String result = engine.process("home", attrs).trim();
        assertThat(result).isEqualTo("<html><body>bar</body></html>");
    });
}
Also used : WebContext(org.thymeleaf.context.WebContext) Context(org.thymeleaf.context.Context) ISpringWebFluxTemplateEngine(org.thymeleaf.spring6.ISpringWebFluxTemplateEngine) Test(org.junit.jupiter.api.Test)

Example 3 with ISpringWebFluxTemplateEngine

use of org.thymeleaf.spring6.ISpringWebFluxTemplateEngine in project spring-boot by spring-projects.

the class ThymeleafReactiveAutoConfigurationTests method useSecurityDialect.

@Test
void useSecurityDialect() {
    this.contextRunner.run((context) -> {
        ISpringWebFluxTemplateEngine engine = context.getBean(ISpringWebFluxTemplateEngine.class);
        MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/test").build());
        exchange.getAttributes().put(SpringSecurityContextUtils.SECURITY_CONTEXT_MODEL_ATTRIBUTE_NAME, new SecurityContextImpl(new TestingAuthenticationToken("alice", "admin")));
        WebContext attrs = new WebContext(SpringWebFluxWebApplication.buildApplication(null).buildExchange(exchange, Locale.US, MediaType.TEXT_HTML, StandardCharsets.UTF_8));
        String result = engine.process("security-dialect", attrs);
        assertThat(result).isEqualTo("<html><body><div>alice</div></body></html>" + System.lineSeparator());
    });
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) WebContext(org.thymeleaf.context.WebContext) ISpringWebFluxTemplateEngine(org.thymeleaf.spring6.ISpringWebFluxTemplateEngine) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.jupiter.api.Test)

Example 4 with ISpringWebFluxTemplateEngine

use of org.thymeleaf.spring6.ISpringWebFluxTemplateEngine in project spring-boot by spring-projects.

the class ThymeleafReactiveAutoConfigurationTests method useJava8TimeDialect.

@Test
void useJava8TimeDialect() {
    this.contextRunner.run((context) -> {
        ISpringWebFluxTemplateEngine engine = context.getBean(ISpringWebFluxTemplateEngine.class);
        Context attrs = new Context(Locale.UK);
        String result = engine.process("java8time-dialect", attrs).trim();
        assertThat(result).isEqualTo("<html><body>2015-11-24</body></html>");
    });
}
Also used : WebContext(org.thymeleaf.context.WebContext) Context(org.thymeleaf.context.Context) ISpringWebFluxTemplateEngine(org.thymeleaf.spring6.ISpringWebFluxTemplateEngine) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 WebContext (org.thymeleaf.context.WebContext)4 ISpringWebFluxTemplateEngine (org.thymeleaf.spring6.ISpringWebFluxTemplateEngine)4 Context (org.thymeleaf.context.Context)3 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)1