use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testDefaultTemplateResolver01.
@Test
public void testDefaultTemplateResolver01() {
final TemplateEngine templateEngine = new TemplateEngine();
final Context context = new Context();
context.setLocale(Locale.ENGLISH);
context.setVariable("one", "this value");
final ClassLoaderTemplateResolver classLoaderTemplateResolver = new ClassLoaderTemplateResolver();
classLoaderTemplateResolver.setCheckExistence(true);
templateEngine.addTemplateResolver(classLoaderTemplateResolver);
final DefaultTemplateResolver defaultTemplateResolver = new DefaultTemplateResolver();
defaultTemplateResolver.setTemplate("<p>something</p>");
templateEngine.addTemplateResolver(defaultTemplateResolver);
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.DefaultTemplateResolver", templateResolvers.get(1).getName());
Assert.assertEquals("<p>something</p>", templateEngine.process("nonexisting", context));
}
use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testDefaultTemplateResolver04.
@Test
public void testDefaultTemplateResolver04() {
final TemplateEngine templateEngine = new SpringTemplateEngine();
final Context context = new Context();
context.setLocale(Locale.ENGLISH);
context.setVariable("one", "this value");
final ClassLoaderTemplateResolver classLoaderTemplateResolver = new ClassLoaderTemplateResolver();
classLoaderTemplateResolver.setCheckExistence(true);
templateEngine.addTemplateResolver(classLoaderTemplateResolver);
final DefaultTemplateResolver defaultTemplateResolver = new DefaultTemplateResolver();
defaultTemplateResolver.setTemplate("<p th:text=\"${one}\">something</p>");
templateEngine.addTemplateResolver(defaultTemplateResolver);
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.DefaultTemplateResolver", templateResolvers.get(1).getName());
Assert.assertEquals("<p>this value</p>", templateEngine.process("nonexisting", context));
}
use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testTemplateResolverConfiguration07.
@Test
public void testTemplateResolverConfiguration07() {
final TemplateEngine templateEngine = new TemplateEngine();
templateEngine.addTemplateResolver(new ClassLoaderTemplateResolver());
templateEngine.addTemplateResolver(new FileTemplateResolver());
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());
}
use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testTemplateResolverConfiguration05.
@Test
public void testTemplateResolverConfiguration05() {
final TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(new ClassLoaderTemplateResolver());
templateEngine.addTemplateResolver(new FileTemplateResolver());
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());
}
use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project thymeleaf-tests by thymeleaf.
the class ContextSequenceTest method testContextSequenceSpring.
public void testContextSequenceSpring() throws Exception {
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(new ClassLoaderTemplateResolver());
final Context ctx1 = new Context();
ctx1.setVariable("myObject", new MyObjectClass("one"));
final Context ctx2 = new Context();
ctx2.setVariable("myObject", new MyObjectClass("two"));
final String result1 = ResourceUtils.normalize(templateEngine.process("context/contextSequence.html", ctx1));
final String result2 = ResourceUtils.normalize(templateEngine.process("context/contextSequence.html", ctx2));
final String expected1 = ResourceUtils.read(ClassLoaderUtils.getClassLoader(ContextSequenceTest.class).getResourceAsStream("context/contextSequence-result1.html"), "UTF-8", true);
final String expected2 = ResourceUtils.read(ClassLoaderUtils.getClassLoader(ContextSequenceTest.class).getResourceAsStream("context/contextSequence-result2.html"), "UTF-8", true);
Assert.assertEquals(expected1, result1);
Assert.assertEquals(expected2, result2);
}
Aggregations