Search in sources :

Example 1 with GroovyMarkupConfig

use of org.springframework.web.servlet.view.groovy.GroovyMarkupConfig in project spring-boot by spring-projects.

the class GroovyTemplateAutoConfigurationTests method renderTemplate.

@Test
public void renderTemplate() throws Exception {
    registerAndRefreshContext();
    GroovyMarkupConfig config = this.context.getBean(GroovyMarkupConfig.class);
    MarkupTemplateEngine engine = config.getTemplateEngine();
    Writer writer = new StringWriter();
    engine.createTemplate(new ClassPathResource("templates/message.tpl").getFile()).make(new HashMap<String, Object>(Collections.singletonMap("greeting", "Hello World"))).writeTo(writer);
    assertThat(writer.toString()).contains("Hello World");
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) GroovyMarkupConfig(org.springframework.web.servlet.view.groovy.GroovyMarkupConfig) MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) StringWriter(java.io.StringWriter) Writer(java.io.Writer) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

MarkupTemplateEngine (groovy.text.markup.MarkupTemplateEngine)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 GroovyMarkupConfig (org.springframework.web.servlet.view.groovy.GroovyMarkupConfig)1