use of org.thymeleaf.TemplateProcessingParameters in project thymeleaf-tests by thymeleaf.
the class SpringResourceResourceResolverSpring4Test method testGetResourceAsStream.
@Test
public void testGetResourceAsStream() throws Exception {
final String templateLocation = "spring421/view/test.html";
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring421/view/applicationContext.xml");
final SpringResourceResourceResolver resolver = (SpringResourceResourceResolver) context.getBean("springResourceResourceResolver");
final TemplateProcessingParameters parameters = new TemplateProcessingParameters(new Configuration(), "test", new Context());
final InputStream is = resolver.getResourceAsStream(parameters, "classpath:" + templateLocation);
final String testResource = ResourceUtils.normalize(ResourceUtils.read(is, "US-ASCII"));
final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(SpringResourceResourceResolverSpring4Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
Assert.assertEquals(expected, testResource);
}
use of org.thymeleaf.TemplateProcessingParameters in project thymeleaf-tests by thymeleaf.
the class TemplateParserTest method createOutput.
private String createOutput(final Document document) throws IOException {
final TemplateProcessingParameters templateProcessingParameters = new TemplateProcessingParameters(this.configuration, "test", new Context());
final TemplateResolution templateResolution = new TemplateResolution("test", "test", new ClassLoaderResourceResolver(), "UTF-8", "XHTML", new NonCacheableCacheEntryValidity());
final Arguments arguments = new Arguments(new TemplateEngine(), templateProcessingParameters, templateResolution, new TemplateRepository(this.configuration), document);
final StringWriter stringWriter = new StringWriter();
final ITemplateWriter templateWriter = this.configuration.getTemplateModeHandler("XHTML").getTemplateWriter();
templateWriter.write(arguments, stringWriter, document);
return stringWriter.toString();
}
use of org.thymeleaf.TemplateProcessingParameters in project thymeleaf-tests by thymeleaf.
the class SpringResourceTemplateResolverSpring3Test method testResolveTemplate.
@Test
public void testResolveTemplate() throws Exception {
final String templateLocation = "spring321/view/test.html";
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring321/view/applicationContext.xml");
final SpringResourceTemplateResolver resolver = (SpringResourceTemplateResolver) context.getBean("springResourceTemplateResolver");
resolver.initialize();
final String templateMode = resolver.getTemplateMode();
Assert.assertEquals("HTML5", templateMode);
final TemplateProcessingParameters parameters = new TemplateProcessingParameters(new Configuration(), "classpath:" + templateLocation, new Context());
final TemplateResolution resolution = resolver.resolveTemplate(parameters);
final IResourceResolver resourceResolver = resolution.getResourceResolver();
final InputStream is = resourceResolver.getResourceAsStream(parameters, resolution.getResourceName());
final String testResource = ResourceUtils.normalize(ResourceUtils.read(is, "US-ASCII"));
final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(SpringResourceTemplateResolverSpring3Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
Assert.assertEquals(expected, testResource);
}
use of org.thymeleaf.TemplateProcessingParameters in project thymeleaf-tests by thymeleaf.
the class SpringResourceResourceResolverSpring3Test method testGetResourceAsStream.
@Test
public void testGetResourceAsStream() throws Exception {
final String templateLocation = "spring321/view/test.html";
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring321/view/applicationContext.xml");
final SpringResourceResourceResolver resolver = (SpringResourceResourceResolver) context.getBean("springResourceResourceResolver");
final TemplateProcessingParameters parameters = new TemplateProcessingParameters(new Configuration(), "test", new Context());
final InputStream is = resolver.getResourceAsStream(parameters, "classpath:" + templateLocation);
final String testResource = ResourceUtils.normalize(ResourceUtils.read(is, "US-ASCII"));
final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(SpringResourceResourceResolverSpring3Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
Assert.assertEquals(expected, testResource);
}
use of org.thymeleaf.TemplateProcessingParameters in project thymeleaf-tests by thymeleaf.
the class SpringResourceTemplateResolverSpring4Test method testResolveTemplate.
@Test
public void testResolveTemplate() throws Exception {
final String templateLocation = "spring421/view/test.html";
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring421/view/applicationContext.xml");
final SpringResourceTemplateResolver resolver = (SpringResourceTemplateResolver) context.getBean("springResourceTemplateResolver");
resolver.initialize();
final String templateMode = resolver.getTemplateMode();
Assert.assertEquals("HTML5", templateMode);
final TemplateProcessingParameters parameters = new TemplateProcessingParameters(new Configuration(), "classpath:" + templateLocation, new Context());
final TemplateResolution resolution = resolver.resolveTemplate(parameters);
final IResourceResolver resourceResolver = resolution.getResourceResolver();
final InputStream is = resourceResolver.getResourceAsStream(parameters, resolution.getResourceName());
final String testResource = ResourceUtils.normalize(ResourceUtils.read(is, "US-ASCII"));
final String expected = ResourceUtils.read(ClassLoaderUtils.getClassLoader(SpringResourceTemplateResolverSpring4Test.class).getResourceAsStream(templateLocation), "US-ASCII", true);
Assert.assertEquals(expected, testResource);
}
Aggregations