1 package org.melati.template.test;
2
3 import org.melati.PoemContext;
4 import org.melati.poem.AccessPoemException;
5 import org.melati.poem.BaseFieldAttributes;
6 import org.melati.poem.Capability;
7 import org.melati.poem.Column;
8 import org.melati.poem.Field;
9 import org.melati.poem.PoemLocale;
10 import org.melati.template.ClassNameTempletLoader;
11 import org.melati.template.WMLAttributeMarkupLanguage;
12 import org.melati.template.WMLMarkupLanguage;
13 import org.melati.util.JSStaticTree;
14 import org.melati.util.MelatiBugMelatiException;
15 import org.melati.util.Tree;
16 import org.melati.util.test.Node;
17 import org.melati.util.test.TreeDatabase;
18
19 /**
20 * @author timp
21 * @since 2 Jul 2007
22 *
23 */
24 public abstract class WMLMarkupLanguageSpec extends MarkupLanguageSpec {
25
26 /**
27 * @param arg0
28 */
29 public WMLMarkupLanguageSpec(String arg0) {
30 super(arg0);
31 }
32
33 /**
34 *
35 */
36 public WMLMarkupLanguageSpec() {
37 super();
38 }
39
40 /**
41 * {@inheritDoc}
42 * @see org.melati.template.test.MarkupLanguageSpec#setUp()
43 */
44 protected void setUp() throws Exception {
45 super.setUp();
46 ml = new WMLMarkupLanguage(
47 m,
48 ClassNameTempletLoader.getInstance(),
49 PoemLocale.HERE);
50 aml = new WMLAttributeMarkupLanguage((WMLMarkupLanguage)ml);
51 m.setMarkupLanguage(ml);
52 assertEquals(ml, m.getMarkupLanguage());
53 }
54
55 /**
56 * Test method for rendered(Exception).
57 * @throws Exception
58 *
59 * @see org.melati.template.HTMLAttributeMarkupLanguage#
60 * rendered(AccessPoemException)
61 */
62 public void testRenderedAccessPoemException() throws Exception {
63
64 assertEquals("java.lang.Exception",aml.rendered(new Exception()));
65
66
67
68 AccessPoemException ape = new AccessPoemException(
69 getDb().getUserTable().guestUser(), new Capability("Cool"));
70 System.err.println(ml.rendered(ape));
71 assertTrue(ml.rendered(ape).indexOf(
72 "org.melati.poem.AccessPoemException: " +
73 "You need the capability Cool but " +
74 "your access token _guest_ doesn't confer it") != -1);
75
76
77
78
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 * Test that special templets are found.
96 *
97 */
98 public void testSpecialTemplateFound() throws Exception {
99 Column column = getDb().getGroupMembershipTable().getUserColumn();
100 BaseFieldAttributes fa = new BaseFieldAttributes(column, column.getType());
101 Field field = new Field(getDb().getUserTable().administratorUser().troid(), fa);
102 Object adminUtil = m.getContextUtil("org.melati.admin.AdminUtils");
103 assertTrue(adminUtil instanceof org.melati.admin.AdminUtils);
104
105 try {
106 ml.input(field);
107 fail("Should have blown up");
108 } catch (MelatiBugMelatiException e) {
109 e = null;
110 }
111 }
112 /**
113 * WML does not have SelectionWindow, perhaps it should
114 * {@inheritDoc}
115 * @see org.melati.template.test.MarkupLanguageSpec#testSelectionWindowField()
116 */
117 public void testSelectionWindowField() throws Exception {
118
119 }
120
121 /**
122 * Test method for rendered(Treeable).
123 * WML Does not have this templet.
124 *
125 * @see org.melati.template.MarkupLanguage#rendered(Object)
126 */
127 public void testRenderedTreeable() throws Exception {
128 Node parent = (Node)((TreeDatabase)getDb()).getNodeTable().newPersistent();
129 parent.setName("Mum");
130 parent.makePersistent();
131 Node kid1 = (Node)((TreeDatabase)getDb()).getNodeTable().newPersistent();
132 kid1.setName("K1");
133 kid1.setParent(parent);
134 kid1.makePersistent();
135 Node kid2 = (Node)((TreeDatabase)getDb()).getNodeTable().newPersistent();
136 kid2.setName("K2");
137 kid2.setParent(parent);
138 kid2.makePersistent();
139 Tree testTree = new Tree(parent);
140 JSStaticTree tree = new JSStaticTree(testTree, "/melati-static/admin");
141 m.setPoemContext(new PoemContext());
142
143 String renderedTree = ml.rendered(tree);
144 assertTrue(renderedTree.trim().startsWith("[org.melati.util.JSStaticTree@"));
145
146 }
147
148
149
150 }