use of org.thymeleaf.spring5.SpringTemplateEngine in project thymeleaf-tests by thymeleaf.
the class LinkBuilderTest method testLinkBuilderSpring01.
@Test
public void testLinkBuilderSpring01() throws Exception {
final Context ctx = new Context();
ctx.setVariable("one", "This is one");
final TemplateEngine templateEngine = new SpringTemplateEngine();
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);
}
use of org.thymeleaf.spring5.SpringTemplateEngine in project thymeleaf-tests by thymeleaf.
the class OfflineTest method testOfflineSpring01.
@Test
public void testOfflineSpring01() throws Exception {
final Context ctx = new Context();
ctx.setVariable("one", "This is one");
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(new ClassLoaderTemplateResolver());
final String result = templateEngine.process("offline/offlinespring01.html", ctx);
final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(OfflineTest.class).getResourceAsStream("offline/offlinespring01-result.html"), "UTF-8", true);
Assert.assertEquals(expected, ResourceUtils.normalize(result));
}
use of org.thymeleaf.spring5.SpringTemplateEngine in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testDefaultTemplateResolver06.
@Test
public void testDefaultTemplateResolver06() {
final TemplateEngine templateEngine = new SpringTemplateEngine();
final Context context = new Context();
context.setLocale(Locale.ENGLISH);
context.setVariable("one", "this value");
final StringTemplateResolver stringTemplateResolver = new StringTemplateResolver();
stringTemplateResolver.setResolvablePatterns(Collections.singleton("<div*"));
templateEngine.addTemplateResolver(stringTemplateResolver);
final DefaultTemplateResolver defaultTemplateResolver = new DefaultTemplateResolver();
defaultTemplateResolver.setTemplate("<p>inserted!</p>");
templateEngine.addTemplateResolver(defaultTemplateResolver);
templateEngine.initialize();
Assert.assertEquals("<div>some text <p><p>inserted!</p></p> other text</div>", templateEngine.process("<div>some text <p th:insert=\"nonexisting\">...</p> other text</div>", context));
}
use of org.thymeleaf.spring5.SpringTemplateEngine in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testTemplateResolverConfiguration02.
@Test
public void testTemplateResolverConfiguration02() {
final TemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.initialize();
final List<ITemplateResolver> templateResolvers = new ArrayList<ITemplateResolver>(templateEngine.getTemplateResolvers());
Assert.assertEquals(1, templateResolvers.size());
Assert.assertEquals("org.thymeleaf.templateresolver.StringTemplateResolver", templateResolvers.get(0).getName());
}
use of org.thymeleaf.spring5.SpringTemplateEngine in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testTemplateResolverConfiguration10.
@Test
public void testTemplateResolverConfiguration10() {
final TemplateEngine templateEngine = new SpringTemplateEngine();
final Set<ITemplateResolver> resolvers = new LinkedHashSet<ITemplateResolver>();
resolvers.add(new ClassLoaderTemplateResolver());
resolvers.add(new FileTemplateResolver());
templateEngine.setTemplateResolvers(resolvers);
templateEngine.initialize();
final List<ITemplateResolver> templateResolvers = new ArrayList<ITemplateResolver>(templateEngine.getTemplateResolvers());
Assert.assertEquals(2, templateResolvers.size());
Assert.assertEquals("org.thymeleaf.templateresolver.ClassLoaderTemplateResolver", templateResolvers.get(0).getName());
Assert.assertEquals("org.thymeleaf.templateresolver.FileTemplateResolver", templateResolvers.get(1).getName());
}
Aggregations