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
13
14
15
16
17 public class WMLMarkupLanguageWebmacroTest extends WMLMarkupLanguageSpec {
18
19
20
21
22
23 public WMLMarkupLanguageWebmacroTest(String arg0) {
24 super(arg0);
25 }
26
27
28
29 public WMLMarkupLanguageWebmacroTest() {
30 super();
31 }
32
33
34
35
36
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
53
54
55
56 public void testGetName() {
57 assertEquals("wml", ml.getName());
58 assertEquals("wml_attr", aml.getName());
59 }
60
61
62
63
64
65
66
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
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
80 ape = new AccessPoemException();
81 assertEquals("", aml.rendered(ape));
82
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
88
89
90 assertTrue(m.getWriter().toString().indexOf("[Access denied to _guest_]") != -1);
91
92 }
93
94
95 }