View Javadoc
1   package org.melati.template.test;
2   
3   import org.melati.MelatiConfig;
4   import org.melati.template.TemplateContext;
5   import org.melati.template.TemplateEngineException;
6   import org.melati.template.velocity.VelocityTemplateEngine;
7   import org.melati.util.MelatiBugMelatiException;
8   import org.melati.util.MelatiException;
9   
10  
11  /**
12   * Run all the tests against velocity.
13   * 
14   * @author timp
15   * @since 21-May-2006
16   *
17   */
18  public class HTMLMarkupLanguageVelocityTest extends HTMLMarkupLanguageSpec {
19  
20    /**
21     * 
22     */
23    public HTMLMarkupLanguageVelocityTest() {
24      super();
25    }
26    
27    /** 
28     * {@inheritDoc}
29     * @see org.melati.template.test.MarkupLanguageSpec#setUp()
30     */
31    protected void setUp() throws Exception {
32      super.setUp();
33      TemplateContext templateContext =
34          templateEngine.getTemplateContext();
35        m.setTemplateContext(templateContext);
36    }
37  
38    protected void melatiConfig() throws MelatiException {
39      mc = new MelatiConfig();
40      mc.setTemplateEngine(new VelocityTemplateEngine());
41    }
42  
43    /**
44     * Test that a syntax error in a WM templet is handled by Velocity.
45     */
46    public void testSyntaxErrorInWMTemplet() throws Exception { 
47      Object templated = new TemplatedWithWMSyntaxError();
48      try { 
49        ml.rendered(templated);
50        fail("Should have bombed");
51      } catch (MelatiBugMelatiException e) { 
52        assertTrue(e.getCause().getMessage().startsWith("Encountered"));
53        e = null;
54      } catch (TemplateEngineException e) { // If a bad .vm file is found instead,
55                                            // due to auto creation of .vm from .wm files
56        assertTrue(e.getCause().getMessage().startsWith("Encountered"));
57        e = null;
58      }
59    }
60    
61  }