View Javadoc

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