View Javadoc
1   /**
2    * 
3    */
4   package org.melati.template.test;
5   
6   import java.util.Enumeration;
7   
8   import org.melati.MelatiConfig;
9   import org.melati.poem.test.PoemTestCase;
10  import org.melati.template.Template;
11  import org.melati.template.TemplateContext;
12  import org.melati.template.TemplateEngine;
13  
14  /**
15   * @author timp
16   * @since 2007/08/21
17   *
18   */
19  public abstract class TemplateEngineSpec extends PoemTestCase {
20  
21    protected TemplateEngine templateEngine = null;
22    
23    /**
24     * @param name
25     */
26    public TemplateEngineSpec(String name) {
27      super(name);
28    }
29  
30    /**
31     * {@inheritDoc}
32     * @see org.melati.poem.test.PoemTestCase#setUp()
33     */
34    protected void setUp() throws Exception {
35      super.setUp();
36      setTemplateEngine();
37    }
38  
39    /**
40     * {@inheritDoc}
41     * @see org.melati.poem.test.PoemTestCase#tearDown()
42     */
43    protected void tearDown() throws Exception {
44      super.tearDown();
45    }
46  
47    
48    abstract protected void setTemplateEngine();
49    /**
50     * Test method for {@link org.melati.template.TemplateEngine#init(org.melati.MelatiConfig)}.
51     */
52    public void testInit() throws Exception {
53      MelatiConfig mc = new MelatiConfig();
54      templateEngine.init(mc);
55      
56    }
57  
58    /**
59     * Test method for {@link org.melati.template.TemplateEngine#getTemplateContext()}.
60     */
61    public void testGetTemplateContext() throws Exception {
62      MelatiConfig mc = new MelatiConfig();
63      templateEngine.init(mc);
64      templateEngine.getTemplateContext(); 
65    }
66  
67    /**
68     * Test method for {@link org.melati.template.TemplateEngine#getName()}.
69     */
70    public abstract void testGetName();
71  
72    /**
73     * Test method for {@link org.melati.template.TemplateEngine#templateExtension()}.
74     */
75    public abstract void testTemplateExtension();
76  
77    /**
78     * Test method for {@link org.melati.template.TemplateEngine#getRoots()}.
79     */
80    public void testGetRoots() {
81      
82    }
83  
84    /**
85     * Test method for {@link org.melati.template.TemplateEngine#addRoot(java.lang.String)}.
86     */
87    public void testAddRoot() {
88      Enumeration<String> en = templateEngine.getRoots();
89      int counter = 0;
90      while (en.hasMoreElements()) { 
91        en.nextElement();
92        counter++;
93      }
94      assertEquals(1, counter);
95      templateEngine.addRoot("root");
96      en = templateEngine.getRoots();
97      counter = 0;
98      while (en.hasMoreElements()) { 
99        en.nextElement();
100       counter++;
101     } 
102     assertEquals(2, counter);
103   }
104 
105   /**
106    * Test method for {@link org.melati.template.TemplateEngine#template(java.lang.String)}.
107    */
108   public void testTemplate() {
109     
110   }
111 
112   /**
113    * Test method for {@link org.melati.template.TemplateEngine#getTemplateName(java.lang.String, java.lang.String)}.
114    */
115   public void testGetTemplateName() {
116     
117   }
118 
119   /**
120    * Test method for {@link org.melati.template.TemplateEngine#expandTemplate(org.melati.util.MelatiWriter, java.lang.String, org.melati.template.TemplateContext)}.
121    * @throws Exception 
122    */
123   public void testExpandTemplateMelatiWriterStringTemplateContext() throws Exception {
124     
125   }
126 
127   /**
128    * Test method for {@link org.melati.template.TemplateEngine#expandTemplate(org.melati.util.MelatiWriter, org.melati.template.Template, org.melati.template.TemplateContext)}.
129    * @throws Exception 
130    */
131   public void testExpandTemplateMelatiWriterTemplateTemplateContext() throws Exception {
132     
133   }
134 
135   /**
136    * Test method for {@link org.melati.template.TemplateEngine#expandedTemplate(org.melati.template.Template, org.melati.template.TemplateContext)}.
137    * @throws Exception 
138    */
139   public void testExpandedTemplate() throws Exception {
140     MelatiConfig mc = new MelatiConfig();
141     templateEngine.init(mc);
142     TemplateContext templateContext = templateEngine.getTemplateContext();
143     Template template = templateEngine.template("org/melati/template/test/Templated" + 
144         templateEngine.templateExtension());
145     assertEquals("Hi, this is from a template.", templateEngine.expandedTemplate(template, templateContext));
146   }
147 
148   /**
149    * Test method for {@link org.melati.template.TemplateEngine#getStringWriter()}.
150    */
151   public void testGetStringWriter() {
152     
153   }
154 
155   /**
156    * Test method for {@link org.melati.template.TemplateEngine#getEngine()}.
157    */
158   public void testGetEngine() {
159     
160   }
161 
162 }