PageRenderTime 14ms CodeModel.GetById 2ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/sigmah/src/test/java/org/sigmah/server/bootstrap/ViewTestCase.java

http://sigma-h.googlecode.com/
Java | 46 lines | 30 code | 9 blank | 7 comment | 0 complexity | be0de4f1de6562e8f0e8a585ca6e5739 MD5 | raw file
 1/*
 2 * All Sigmah code is released under the GNU General Public License v3
 3 * See COPYRIGHT.txt and LICENSE.txt.
 4 */
 5
 6package org.sigmah.server.bootstrap;
 7
 8import freemarker.template.Configuration;
 9import freemarker.template.Template;
10import freemarker.template.TemplateException;
11import org.junit.BeforeClass;
12import org.sigmah.server.bootstrap.model.PageModel;
13import org.sigmah.server.util.TemplateModule;
14
15import java.io.IOException;
16import java.io.StringWriter;
17
18/**
19 * @author Alex Bertram
20 */
21public abstract class ViewTestCase {
22
23    protected static Configuration templateCfg;
24
25    @BeforeClass
26    public static void setUpTemplateConfig() {
27        TemplateModule module = new TemplateModule();
28        templateCfg = module.provideConfiguration();
29    }
30
31    protected String process(PageModel model) throws IOException, TemplateException {
32        Template template = templateCfg.getTemplate(model.getTemplateName());
33        StringWriter writer = new StringWriter();
34        template.process(model, writer);
35
36        return writer.toString();
37    }
38
39    protected void assertProcessable(PageModel model) {
40        try {
41            process(model);
42        } catch (Exception e) {
43            throw new AssertionError(e);
44        }
45    }
46}