1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.test;
18
19
20 import junit.awtui.TestRunner;
21 import junit.framework.Test;
22 import junit.framework.TestSuite;
23
24
25 import org.apache.cactus.ServletTestCase;
26 import org.apache.cactus.WebRequest;
27 import org.apache.cactus.WebResponse;
28
29
30 import org.apache.jetspeed.capability.CapabilityMap;
31 import org.apache.jetspeed.om.profile.Profile;
32 import org.apache.jetspeed.om.profile.ProfileLocator;
33 import org.apache.jetspeed.om.profile.PSMLDocument;
34 import org.apache.jetspeed.services.Profiler;
35 import org.apache.jetspeed.services.rundata.JetspeedRunData;
36 import org.apache.jetspeed.test.TurbineTestUtilities;
37
38
39 import org.apache.turbine.services.pull.TurbinePull;
40 import org.apache.turbine.services.velocity.TurbineVelocity;
41 import org.apache.turbine.util.RunData;
42 import org.apache.turbine.util.RunDataFactory;
43
44 import org.apache.jetspeed.om.security.JetspeedUser;
45
46
47 import org.apache.velocity.context.Context;
48
49 /***
50 *
51 * @author <a href="paulsp@apache.org">Paul Spencer</a>
52 * @version $Id $
53 */
54
55 public class TestBasicSanity extends ServletTestCase
56 {
57 private static String TEST_ANON_USER_NAME = "";
58 private static String TEST_CONTEXT = null;
59 private static String TEST_DEFAULT_PAGE = "default";
60 private static String TEST_HOST = "localhost";
61 private static String TEST_SERVLET = "/portal";
62 private static String TEST_GROUP = "apache";
63 private static String TEST_PAGE = "news";
64 private static String TEST_USER = "turbine";
65 private static String TEST_USER_PASSWORD ="turbine";
66
67 private RunData rundata = null;
68
69 /***
70 * Defines the testcase name for JUnit.
71 *
72 * @param name the testcase's name.
73 */
74 public TestBasicSanity(String name)
75 {
76 super( name );
77 }
78
79 /***
80 * Start the tests.
81 *
82 * @param args the arguments. Not used
83 */
84 public static void main(String args[])
85 {
86 TestRunner.main( new String[] { TestBasicSanity.class.getName() } );
87 }
88
89 /***
90 * Creates the test suite.
91 *
92 * @return a test suite (<code>TestSuite</code>) that includes all methods
93 * starting with "test"
94 */
95 public static Test suite()
96 {
97
98 return new TestSuite( TestBasicSanity.class );
99 }
100
101 /***
102 * Sets up the test case.
103 *
104 */
105 protected void setUp () throws Exception
106 {
107 }
108
109 /***
110 * Test: DefaultURL
111 * With the default URL "/"
112 * 1) A page is generated
113 * 2) The user is anonymous
114 * 3) Group and Role are not set
115 */
116 public void beginDefaultURL(WebRequest theRequest)
117 {
118 System.out.println("URL = " + theRequest.getURL());
119 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET, "", null);
120 System.out.println("post set URL = " + theRequest.getURL());
121 }
122
123 /***
124 * Execute the test
125 *
126 * @throws Exception
127 */
128 public void testDefaultURL() throws Exception
129 {
130
131 rundata = RunDataFactory.getRunData ( request, response, config );
132 assertNotNull( "Got rundata", rundata);
133 TurbineTestUtilities.setupRunData(rundata);
134
135
136 JetspeedUser user = (JetspeedUser)rundata.getUser();
137 assertNotNull( "Got user", user);
138
139
140 CapabilityMap cm = ((JetspeedRunData)rundata).getCapability();
141 assertNotNull( "Got Capability", cm);
142
143
144 Profile profile = Profiler.getProfile(rundata);
145 assertNotNull( "Got profile from Profiler", profile);
146
147
148 if (profile instanceof ProfileLocator)
149 {
150 ProfileLocator profileLocator = (ProfileLocator) profile;
151 assertTrue("Verify the 'anonymous' is set", profileLocator.getAnonymous());
152 assertNull("Verify the group is null", profileLocator.getGroup());
153 assertNull("Verify the role is null", profileLocator.getRole());
154 } else
155 {
156 assertTrue( "profile does not implement ProfileLocator", false);
157 }
158
159
160
161 PSMLDocument psmlDoc = profile.getDocument();
162 assertNotNull( "Got psmlDocument", psmlDoc);
163
164 System.out.println("DocumentName = " + profile.getDocument().getName());
165
166
167 Context context = TurbineVelocity.getContext(rundata);
168 assertNotNull( "Got context", context);
169 TurbinePull.populateContext( context, rundata);
170
171
172 assertNotNull( "Got jlink from context", context.get("jlink"));
173
174
175 TurbineTestUtilities.generatePage(rundata);
176 TurbineTestUtilities.outputPage(rundata);
177
178
179 RunDataFactory.putRunData(rundata);
180 }
181
182 public void endDefaultURL(org.apache.cactus.WebResponse theResponse)
183 {
184 System.out.println("text length = " + theResponse.getText().length());
185
186 }
187
188 /***
189 * Test: GroupURL
190 * With the default URL "/group/apache"
191 * 1) A page is generated
192 * 2) The user is anonymous
193 * 3) Group is set to "apache"
194 * 4) Role is not set
195 */
196 public void beginGroupUrl(WebRequest theRequest)
197 {
198 System.out.println("URL = " + theRequest.getURL());
199 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET
200 , "/group/" + TEST_GROUP , null);
201 System.out.println("post set URL = " + theRequest.getURL());
202 }
203
204 /***
205 * Test the Group link
206 * @throws Exception
207 */
208 public void testGroupUrl() throws Exception
209 {
210
211 rundata = RunDataFactory.getRunData ( request, response, config );
212 assertNotNull( "Got rundata", rundata);
213
214 TurbineTestUtilities.setupRunData(rundata);
215
216
217 Profile profile = Profiler.getProfile(rundata);
218 assertNotNull( "Got profile from Profiler", profile);
219
220
221 if (profile instanceof ProfileLocator)
222 {
223
224 ProfileLocator profileLocator = (ProfileLocator) profile;
225
226 assertNotNull("Verify the group is not null", profileLocator.getGroup());
227 assertNull("Verify the role is null", profileLocator.getRole());
228 } else
229 {
230 assertTrue( "profile does not implement ProfileLocator", false);
231 }
232 TurbineTestUtilities.generatePage(rundata);
233 TurbineTestUtilities.outputPage(rundata);
234
235
236 RunDataFactory.putRunData(rundata);
237 }
238
239 public void endGroupURL(WebResponse theResponse)
240 {
241 System.out.println("text length = " + theResponse.getText().length());
242
243 }
244
245 /***
246 * Test: PageURL
247 * With the page URL "/page/apache"
248 * 1) A page is generated
249 * 2) The user is anonymous
250 * 3) Group is set to "apache"
251 * 4) Role is not set
252 */
253 public void beginPageUrl(WebRequest theRequest)
254 {
255 System.out.println("URL = " + theRequest.getURL());
256 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET
257 , "/page/" + TEST_PAGE , null);
258 System.out.println("post set URL = " + theRequest.getURL());
259 }
260
261 /***
262 * Test the PageURL
263 *
264 * @throws Exception
265 */
266 public void testPageUrl() throws Exception
267 {
268
269 rundata = RunDataFactory.getRunData ( request, response, config );
270 assertNotNull( "Got rundata", rundata);
271
272 TurbineTestUtilities.setupRunData(rundata);
273
274
275 Profile profile = Profiler.getProfile(rundata);
276 assertNotNull( "Got profile from Profiler", profile);
277
278
279 if (profile instanceof ProfileLocator)
280 {
281 ProfileLocator profileLocator = (ProfileLocator) profile;
282
283 assertTrue("Verify the 'anonymous' is set", profileLocator.getAnonymous());
284 assertNull("Verify the group is null", profileLocator.getGroup());
285 assertNull("Verify the role is null", profileLocator.getRole());
286 assertEquals("Verify the page name", profileLocator.getName(), TEST_PAGE + ".psml");
287 } else
288 {
289 assertTrue( "profile does not implement ProfileLocator", false);
290 }
291 TurbineTestUtilities.generatePage(rundata);
292 TurbineTestUtilities.outputPage(rundata);
293
294
295 RunDataFactory.putRunData(rundata);
296 }
297
298 public void endPageURL(WebResponse theResponse)
299 {
300 System.out.println("text length = " + theResponse.getText().length());
301
302 }
303 /***
304 * Test: PageURL
305 * With the page URL "/page/apache"
306 * 1) A page is generated
307 * 2) The user is anonymous
308 * 3) Group is set to "apache"
309 * 4) Role is not set
310 */
311 public void beginUserPageUrl(WebRequest theRequest)
312 {
313 System.out.println("URL = " + theRequest.getURL());
314 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET
315 , "/page/" + TEST_DEFAULT_PAGE ,"action=JLoginUser&username=turbine&password=turbine");
316 System.out.println("post set URL = " + theRequest.getURL());
317 }
318
319 /***
320 * Test the PageURL
321 *
322 * @throws Exception
323 */
324 public void testUserPageUrl() throws Exception
325 {
326
327 rundata = RunDataFactory.getRunData ( request, response, config );
328 assertNotNull( "Got rundata", rundata);
329
330 TurbineTestUtilities.setupRunData(rundata);
331
332
333 Profile profile = Profiler.getProfile(rundata);
334 assertNotNull( "Got profile from Profiler", profile);
335
336
337 if (profile instanceof ProfileLocator)
338 {
339 ProfileLocator profileLocator = (ProfileLocator) profile;
340
341 assertTrue("Verify the 'anonymous' is not", !profileLocator.getAnonymous());
342 assertNull("Verify the group is null", profileLocator.getGroup());
343 assertNull("Verify the role is null", profileLocator.getRole());
344 assertNotNull("Verify the user is not null", profileLocator.getUser());
345 assertTrue("Verify the user is logged in", profileLocator.getUser().hasLoggedIn());
346 assertEquals("Verify the user's username", profileLocator.getUser().getUserName(),TEST_USER);
347 assertEquals("Verify the page name", profileLocator.getName(), TEST_DEFAULT_PAGE + ".psml");
348 } else
349 {
350 assertTrue( "profile does not implement ProfileLocator", false);
351 }
352 TurbineTestUtilities.generatePage(rundata);
353 TurbineTestUtilities.outputPage(rundata);
354
355
356 RunDataFactory.putRunData(rundata);
357 }
358
359 public void endUserPageURL(WebResponse theResponse)
360 {
361 System.out.println("text length = " + theResponse.getText().length());
362
363 }
364 }