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