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.webmacro.WebmacroTemplateEngine;
6   import org.melati.util.MelatiException;
7   import org.melati.poem.AccessPoemException;
8   import org.melati.poem.Capability;
9   
10  
11  /**
12   * Test the HTMLMarkupLanguage and its AttributeMarkupLanguage.
13   * 
14   * @author timp
15   * @since 18-May-2006
16   */
17  public class WMLMarkupLanguageWebmacroTest extends WMLMarkupLanguageSpec {
18  
19    /**
20     * Constructor for PoemTest.
21     * @param arg0
22     */
23    public WMLMarkupLanguageWebmacroTest(String arg0) {
24      super(arg0);
25    }
26    /**
27     * Constructor.
28     */
29    public WMLMarkupLanguageWebmacroTest() {
30      super();
31    }
32    
33  
34    /** 
35     * {@inheritDoc}
36     * @see org.melati.template.test.MarkupLanguageSpec#setUp()
37     */
38    protected void setUp() throws Exception {
39      super.setUp();
40      TemplateContext templateContext =
41          templateEngine.getTemplateContext();
42        m.setTemplateContext(templateContext);
43    }
44    protected void melatiConfig() throws MelatiException {
45      mc = new MelatiConfig();
46      if(mc.getTemplateEngine().getName() != "webmacro") {
47        mc.setTemplateEngine(new WebmacroTemplateEngine());
48      }
49    }
50    
51    /**
52     * Test method for getName.
53     * 
54     * @see org.melati.template.MarkupLanguage#getName()
55     */
56    public void testGetName() {
57      assertEquals("wml", ml.getName());
58      assertEquals("wml_attr", aml.getName());
59    }
60  
61    /**
62     * Test method for rendered(Exception).
63     * @throws Exception 
64     * 
65     * @see org.melati.template.HTMLAttributeMarkupLanguage#
66     *      rendered(AccessPoemException)
67     */
68    public void testRenderedAccessPoemException() throws Exception {
69      
70      assertEquals("java.lang.Exception",aml.rendered(new Exception()));
71  
72      AccessPoemException ape = new AccessPoemException(
73            getDb().getUserTable().guestUser(), new Capability("Cool"));
74      // System.err.println(ml.rendered(ape));
75      assertTrue(ml.rendered(ape).indexOf(
76            "org.melati.poem.AccessPoemException: " + 
77            "You need the capability Cool but " + 
78            "your access token _guest_ doesn't confer it") != -1);
79      //assertTrue(ml.rendered(ape).indexOf("[Access denied to Melati guest user]") != -1);
80      ape = new AccessPoemException();
81      assertEquals("", aml.rendered(ape));
82      //System.err.println(m.getWriter().toString());
83      assertTrue(m.getWriter().toString().indexOf("[Access denied to [UNRENDERABLE EXCEPTION!]") != -1);
84      ape = new AccessPoemException(
85            getDb().getUserTable().guestUser(), new Capability("Cool"));
86      assertEquals("", aml.rendered(ape));
87        // NB Not at all sure how this value changed 
88        //System.err.println(m.getWriter().toString());
89        //assertTrue(m.getWriter().toString().indexOf("[Access denied to Melati guest user]") != -1);
90      assertTrue(m.getWriter().toString().indexOf("[Access denied to _guest_]") != -1);
91  
92    }
93  
94  
95  }