1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.melati.test.test;
45
46 import org.melati.JettyWebTestCase;
47
48 import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
49
50
51
52
53
54
55
56 public class PoemServletTestTest extends JettyWebTestCase {
57
58 protected String servletName;
59
60
61
62
63 public PoemServletTestTest(String name) {
64 super(name);
65 servletName = "org.melati.test.PoemServletTest";
66 }
67
68
69
70
71
72 protected void setUp() throws Exception {
73 super.setUp();
74 }
75
76
77
78
79
80 protected void tearDown() throws Exception {
81 super.tearDown();
82 }
83
84
85
86
87 public void testException() {
88 setScriptingEnabled(false);
89 beginAt("/" + servletName + "/melatitest");
90 try {
91 clickLinkWithText("Exception");
92 } catch (FailingHttpStatusCodeException e) {
93 assertEquals(500, e.getStatusCode());
94 }
95
96 assertTextPresent("MelatiBugMelatiException");
97 }
98
99
100
101 public void testAccessException() {
102 setScriptingEnabled(false);
103 beginAt("/" + servletName + "/melatitest" );
104 clickLinkWithText("Access Poem Exception");
105 assertTextPresent("You need the capability _administer_ ");
106 setTextField("field_login", "_administrator_");
107 setTextField("field_password", "FIXME");
108 checkCheckbox("rememberme");
109 submit("action");
110 assertTextPresent("You are logged in as _administrator_ and have _administer_ capability");
111 }
112
113
114
115
116 public void testAccessAllowed() {
117 setScriptingEnabled(false);
118 beginAt("/org.melati.login.Login/admintest");
119 setTextField("field_login", "_administrator_");
120 setTextField("field_password", "FIXME");
121 checkCheckbox("rememberme");
122 submit("action");
123 gotoPage("/" + servletName + "/admintest");
124 clickLinkWithText("Access Poem Exception");
125 assertTextPresent("You are logged in as _administrator_ and have _administer_ capability");
126 }
127
128
129
130
131 public void testView() {
132 setScriptingEnabled(false);
133 beginAt("/" + servletName +"/melatitest/");
134 clickLinkWithText("tableinfo/0/View");
135 assertTextPresent("logicalDatabase = melatitest, table = tableinfo, troid = 0, method = View");
136 }
137
138
139
140 public void testUpload() {
141 setScriptingEnabled(false);
142 beginAt("/org.melati.login.Login/admintest");
143 setTextField("field_login", "_administrator_");
144 setTextField("field_password", "FIXME");
145 checkCheckbox("rememberme");
146 submit("action");
147 gotoPage("/" + servletName + "/admintest/");
148
149 setTextField("file","/dist/melati/melati/src/main/java/org/melati/admin/static/file.gif");
150 submit();
151 assertWindowPresent("Upload");
152 setTextField("file","/dist/melati/LICENSE-GPL.txt");
153 submit();
154 gotoWindow("Upload");
155 assertTextPresent("GNU GENERAL PUBLIC LICENSE");
156
157 }
158
159
160
161 public void testUploadNothing() {
162 setScriptingEnabled(false);
163 beginAt("/org.melati.login.Login/admintest");
164 setTextField("field_login", "_administrator_");
165 setTextField("field_password", "FIXME");
166 checkCheckbox("rememberme");
167 submit("action");
168 gotoPage("/" + servletName + "/admintest/");
169
170
171 submit();
172 gotoWindow("Upload");
173 assertTextPresent("No file was uploaded");
174
175 }
176
177 }