1
2
3
4 package org.melati.admin.test;
5
6
7 import org.melati.Melati;
8 import org.melati.MelatiConfig;
9 import org.melati.PoemContext;
10 import org.melati.admin.AdminUtils;
11 import org.melati.poem.test.PoemTestCase;
12 import org.melati.servlet.test.MockHttpServletRequest;
13 import org.melati.servlet.test.MockHttpServletResponse;
14 import org.melati.template.TemplateContext;
15 import org.melati.template.TemplateEngine;
16
17
18
19
20
21
22 public class AdminUtilsTest extends PoemTestCase {
23 protected static MelatiConfig mc = null;
24 protected static TemplateEngine templateEngine = null;
25 protected static Melati m = null;
26 protected AdminUtils au;
27
28
29
30
31 public AdminUtilsTest(String name) {
32 super(name);
33 }
34
35
36
37
38 protected void setUp()
39 throws Exception {
40 super.setUp();
41 mc = new MelatiConfig();
42 templateEngine = mc.getTemplateEngine();
43 if (templateEngine != null)
44 templateEngine.init(mc);
45 else fail();
46 MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
47 mockHttpServletRequest.setPathInfo("melatitest/user/Selection");
48 mockHttpServletRequest.setRequestURI("melatitest/user/Selection");
49 System.err.println(mockHttpServletRequest.getRequestURI());
50 MockHttpServletResponse mockServletResponse = new MockHttpServletResponse();
51 m = new Melati(mc, mockHttpServletRequest, mockServletResponse);
52 m.setTemplateEngine(templateEngine);
53 assertNotNull(m.getTemplateEngine());
54 TemplateContext templateContext =
55 templateEngine.getTemplateContext(m);
56 m.setTemplateContext(templateContext);
57 PoemContext pc = new PoemContext();
58 pc.setLogicalDatabase("melatijunit");
59 pc.setTable("user");
60 pc.setTroid(new Integer(1));
61 pc.setMethod("Selection");
62 m.setPoemContext(pc);
63 au = new AdminUtils(m);
64 }
65
66
67
68
69 protected void tearDown()
70 throws Exception {
71
72
73
74 }
75
76
77
78
79 public void testAdminUtils() throws Exception {
80 }
81
82
83
84
85
86 public void testSpecialFacilities() throws Exception {
87 m.loadTableAndObject();
88 assertEquals("",
89 au.specialFacilities(m, m.getMarkupLanguage(), m.getObject()));
90 }
91
92
93
94
95 public void testToggledOrderSelectionURL() throws Exception {
96 m.loadTableAndObject();
97
98 assertEquals("melatitest/user/Selection?field_order-1=23&field_order-1-toggle=true",
99 au.ToggledOrderSelectionURL(m, "field_order-1", "23"));
100 }
101
102
103
104
105 public void testGetStaticURL() {
106 assertEquals("/melatitest/melati-static/admin/static", au.getStaticURL());
107 }
108
109
110
111
112 public void testCreateTree() {
113 }
114
115
116
117
118 public void testSimpleName() {
119 assertEquals("admin", AdminUtils.simpleName("org.melati.admin"));
120 assertEquals("admin", AdminUtils.simpleName(".admin"));
121 assertEquals("", AdminUtils.simpleName("admin."));
122 assertEquals("admin", AdminUtils.simpleName("admin"));
123 }
124
125 public void testCsvEscaped() {
126 assertEquals("Double quotes (\"\") are used to escape double quotes in CSV format",
127 AdminUtils.csvEscaped("Double quotes (\") are used to escape double quotes in CSV format"));
128 }
129
130 }