use of org.thymeleaf.TemplateEngine in project thymeleaf-tests by thymeleaf.
the class ScriptInlineTest method testInlineResult.
private static void testInlineResult(final String script, final String expectedResult, final Map<String, Object> variables) {
final String completeScript = "<script th:inline=\"javascript\">\n/*<![CDATA[ */\n" + script + "\n/* ]]> */\n</script>";
final ITemplateResolver templateResolver = new StringTemplateResolver();
final TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
final Context ctx = new Context();
ctx.setVariables(variables);
final StringWriter stringWriter = new StringWriter();
templateEngine.process(completeScript, ctx, stringWriter);
final String result = stringWriter.toString();
final String extractedResult = result.substring(0, result.indexOf("\n/* ]]> */\n</script>")).substring(24);
Assert.assertEquals(expectedResult, extractedResult);
}
use of org.thymeleaf.TemplateEngine 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.TemplateEngine in project thymeleaf-tests by thymeleaf.
the class LinkBuilderTest method testLinkBuilderWithECFactory01.
@Test
public void testLinkBuilderWithECFactory01() 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());
templateEngine.setEngineContextFactory(new TestEngineContextFactory());
final String result = templateEngine.process("<a th:href='@{/something}'>", ctx);
final String expected = "<a href='[ENGINE: /fromthebuilder/something]'>";
Assert.assertEquals(expected, result);
}
use of org.thymeleaf.TemplateEngine in project thymeleaf-tests by thymeleaf.
the class OfflineTest method testOffline01.
@Test
public void testOffline01() throws Exception {
final Context ctx = new Context();
ctx.setVariable("one", "This is one");
final TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(new ClassLoaderTemplateResolver());
final String result = templateEngine.process("offline/offline01.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.TemplateEngine in project thymeleaf-tests by thymeleaf.
the class Parsing03Test method testParsing.
@Test
public void testParsing() throws Exception {
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setTemplateMode("HTML5");
templateResolver.setCharacterEncoding("UTF-16");
final TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
final String result = templateEngine.process("parsing/parsingtest03.bulk", new Context());
final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(Parsing03Test.class).getResourceAsStream("parsing/parsingtest03-result.bulk"), "ISO-8859-1", true);
Assert.assertEquals(expected, ResourceUtils.normalize(result));
}
Aggregations