use of org.thymeleaf.context.Context in project thymeleaf-tests by thymeleaf.
the class TemplateResolverAttributesTest method testTemplateResolutionAttributes02.
@Test
public void testTemplateResolutionAttributes02() throws Exception {
final AttributeTesterTemplateResolver templateResolver = new AttributeTesterTemplateResolver(EXPECTED_ATTRIBUTES2);
final TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
final TemplateSpec templateSpec = new TemplateSpec("temp", EXPECTED_ATTRIBUTES2);
final String output = templateEngine.process(templateSpec, new Context());
Assert.assertTrue(templateResolver.tempCalled);
Assert.assertTrue(templateResolver.fragCalled);
Assert.assertEquals(EXPECTED_OUTPUT, output);
}
use of org.thymeleaf.context.Context in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testDefaultTemplateResolver02.
@Test
public void testDefaultTemplateResolver02() {
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>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.context.Context 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.context.Context 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.context.Context in project thymeleaf-tests by thymeleaf.
the class TemplateEngineTest method testStringTemplate.
@Test
public void testStringTemplate() {
final TemplateEngine templateEngine = new TemplateEngine();
final Context context = new Context();
context.setLocale(Locale.ENGLISH);
Assert.assertEquals("Hello ??something_en??", templateEngine.process("Hello [[#{something}]]", context));
Assert.assertEquals("Hello 58", templateEngine.process("Hello [[23+35]]", context));
}
Aggregations