Search in sources :

Example 1 with Context

use of org.thymeleaf.context.Context in project spring-boot by spring-projects.

the class ThymeleafAutoConfigurationTests method useJava8TimeDialect.

@Test
public void useJava8TimeDialect() throws Exception {
    this.context.register(ThymeleafAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    TemplateEngine engine = this.context.getBean(TemplateEngine.class);
    Context attrs = new Context(Locale.UK);
    String result = engine.process("java8time-dialect", attrs);
    assertThat(result).isEqualTo("<html><body>2015-11-24</body></html>");
}
Also used : RequestContext(org.springframework.web.servlet.support.RequestContext) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Context(org.thymeleaf.context.Context) TemplateEngine(org.thymeleaf.TemplateEngine) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 2 with Context

use of org.thymeleaf.context.Context in project spring-boot by spring-projects.

the class ThymeleafAutoConfigurationTests method createFromConfigClass.

@Test
public void createFromConfigClass() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context, "spring.thymeleaf.mode:XHTML", "spring.thymeleaf.suffix:");
    this.context.register(ThymeleafAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    TemplateEngine engine = this.context.getBean(TemplateEngine.class);
    Context attrs = new Context(Locale.UK, Collections.singletonMap("foo", "bar"));
    String result = engine.process("template.txt", attrs);
    assertThat(result).isEqualTo("<html>bar</html>");
}
Also used : RequestContext(org.springframework.web.servlet.support.RequestContext) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Context(org.thymeleaf.context.Context) TemplateEngine(org.thymeleaf.TemplateEngine) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 3 with Context

use of org.thymeleaf.context.Context in project spring-boot by spring-projects.

the class ThymeleafAutoConfigurationTests method useDataDialect.

@Test
public void useDataDialect() throws Exception {
    this.context.register(ThymeleafAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    TemplateEngine engine = this.context.getBean(TemplateEngine.class);
    Context attrs = new Context(Locale.UK, Collections.singletonMap("foo", "bar"));
    String result = engine.process("data-dialect", attrs);
    assertThat(result).isEqualTo("<html><body data-foo=\"bar\"></body></html>");
}
Also used : RequestContext(org.springframework.web.servlet.support.RequestContext) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Context(org.thymeleaf.context.Context) TemplateEngine(org.thymeleaf.TemplateEngine) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 4 with Context

use of org.thymeleaf.context.Context in project spring-boot by spring-projects.

the class ThymeleafAutoConfigurationTests method renderTemplate.

@Test
public void renderTemplate() throws Exception {
    this.context.register(ThymeleafAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    TemplateEngine engine = this.context.getBean(TemplateEngine.class);
    Context attrs = new Context(Locale.UK, Collections.singletonMap("foo", "bar"));
    String result = engine.process("home", attrs);
    assertThat(result).isEqualTo("<html><body>bar</body></html>");
}
Also used : RequestContext(org.springframework.web.servlet.support.RequestContext) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Context(org.thymeleaf.context.Context) TemplateEngine(org.thymeleaf.TemplateEngine) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 5 with Context

use of org.thymeleaf.context.Context in project thymeleaf-tests by thymeleaf.

the class LinkBuilderTest method testLinkBuilder01.

@Test
public void testLinkBuilder01() throws Exception {
    final Context ctx = new Context();
    ctx.setVariable("one", "This is one");
    final TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(new StringTemplateResolver());
    templateEngine.setLinkBuilder(new TestLinkBuilder());
    final String result = templateEngine.process("<a th:href='@{/something}'>", ctx);
    final String expected = "<a href='[/fromthebuilder/something]'>";
    Assert.assertEquals(expected, result);
}
Also used : Context(org.thymeleaf.context.Context) SpringTemplateEngine(org.thymeleaf.spring5.SpringTemplateEngine) TemplateEngine(org.thymeleaf.TemplateEngine) StringTemplateResolver(org.thymeleaf.templateresolver.StringTemplateResolver) Test(org.junit.Test)

Aggregations

Context (org.thymeleaf.context.Context)242 Test (org.junit.Test)179 Album (org.thymeleaf.spring5.reactive.data.Album)141 ReactiveDataDriverContextVariable (org.thymeleaf.spring5.context.webflux.ReactiveDataDriverContextVariable)130 TemplateEngine (org.thymeleaf.TemplateEngine)30 Locale (java.util.Locale)24 Async (org.springframework.scheduling.annotation.Async)21 ClassLoaderTemplateResolver (org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)13 SpringTemplateEngine (org.thymeleaf.spring5.SpringTemplateEngine)11 MockServletContext (org.springframework.mock.web.MockServletContext)10 RequestContext (org.springframework.web.servlet.support.RequestContext)10 Test (org.junit.jupiter.api.Test)9 WebContext (org.thymeleaf.context.WebContext)9 MessagingException (javax.mail.MessagingException)7 StringTemplateResolver (org.thymeleaf.templateresolver.StringTemplateResolver)7 DefaultTemplateResolver (org.thymeleaf.templateresolver.DefaultTemplateResolver)6 ServletContext (jakarta.servlet.ServletContext)5 ArrayList (java.util.ArrayList)5 MimeMessage (javax.mail.internet.MimeMessage)5 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)5