This project has retired. For details please refer to its
Attic page.
TestBasicSanity xref
1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.test;
1819// Junit imports20import junit.awtui.TestRunner;
21import junit.framework.Test;
22import junit.framework.TestSuite;
2324// Cactus imports25import org.apache.cactus.ServletTestCase;
26import org.apache.cactus.WebRequest;
27import org.apache.cactus.WebResponse;
2829// Jetspeed imports30import org.apache.jetspeed.capability.CapabilityMap;
31import org.apache.jetspeed.om.profile.Profile;
32import org.apache.jetspeed.om.profile.ProfileLocator;
33import org.apache.jetspeed.om.profile.PSMLDocument;
34import org.apache.jetspeed.services.Profiler;
35import org.apache.jetspeed.services.rundata.JetspeedRunData;
36import org.apache.jetspeed.test.TurbineTestUtilities;
3738// Turbine imports39import org.apache.turbine.services.pull.TurbinePull;
40import org.apache.turbine.services.velocity.TurbineVelocity;
41import org.apache.turbine.util.RunData;
42import org.apache.turbine.util.RunDataFactory;
4344import org.apache.jetspeed.om.security.JetspeedUser;
4546// Velocity47import org.apache.velocity.context.Context;
4849/***50 *51 * @author <a href="paulsp@apache.org">Paul Spencer</a>52 * @version $Id $53 */5455publicclassTestBasicSanityextends ServletTestCase
56 {
57privatestatic String TEST_ANON_USER_NAME = "";
58privatestatic String TEST_CONTEXT = null;
59privatestatic String TEST_DEFAULT_PAGE = "default";
60privatestatic String TEST_HOST = "localhost";
61privatestatic String TEST_SERVLET = "/portal";
62privatestatic String TEST_GROUP = "apache";
63privatestatic String TEST_PAGE = "news";
64privatestatic String TEST_USER = "turbine";
65privatestatic String TEST_USER_PASSWORD ="turbine";
6667private RunData rundata = null;
6869/***70 * Defines the testcase name for JUnit.71 *72 * @param name the testcase's name.73 */74publicTestBasicSanity(String name)
75 {
76super( name );
77 }
7879/***80 * Start the tests.81 *82 * @param args the arguments. Not used83 */84publicstaticvoid main(String args[])
85 {
86 TestRunner.main( new String[] { TestBasicSanity.class.getName() } );
87 }
8889/***90 * Creates the test suite.91 *92 * @return a test suite (<code>TestSuite</code>) that includes all methods93 * starting with "test"94 */95publicstatic Test suite()
96 {
97// All methods starting with "test" will be executed in the test suite.98returnnew TestSuite( TestBasicSanity.class );
99 }
100101/***102 * Sets up the test case.103 *104 */105protectedvoid setUp () throws Exception
106 {
107 }
108109/***110 * Test: DefaultURL111 * With the default URL "/"112 * 1) A page is generated 113 * 2) The user is anonymous114 * 3) Group and Role are not set115 */116publicvoid 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 }
122123/***124 * Execute the test125 *126 * @throws Exception127 */128publicvoid testDefaultURL() throws Exception
129 {
130// Create the RunData object to be used during testing. 131 rundata = RunDataFactory.getRunData ( request, response, config );
132 assertNotNull( "Got rundata", rundata);
133 TurbineTestUtilities.setupRunData(rundata);
134135// Verify we have a user136 JetspeedUser user = (JetspeedUser)rundata.getUser();
137 assertNotNull( "Got user", user);
138139// Verify we have a CapabilityMap140 CapabilityMap cm = ((JetspeedRunData)rundata).getCapability();
141 assertNotNull( "Got Capability", cm);
142143// Verify we have a profile144 Profile profile = Profiler.getProfile(rundata);
145 assertNotNull( "Got profile from Profiler", profile);
146147// Verify the profile location information in the profile148if (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 } else155 {
156 assertTrue( "profile does not implement ProfileLocator", false);
157 }
158159160// Verify we have a Document161 PSMLDocument psmlDoc = profile.getDocument();
162 assertNotNull( "Got psmlDocument", psmlDoc);
163164 System.out.println("DocumentName = " + profile.getDocument().getName());
165166// Get and populate the context167 Context context = TurbineVelocity.getContext(rundata);
168 assertNotNull( "Got context", context);
169 TurbinePull.populateContext( context, rundata);
170171// Verify tool are in the context172 assertNotNull( "Got jlink from context", context.get("jlink"));
173174// Generatate and output thre page175 TurbineTestUtilities.generatePage(rundata);
176 TurbineTestUtilities.outputPage(rundata);
177178// Return the used RunData to the factory for recycling.179 RunDataFactory.putRunData(rundata);
180 }
181182publicvoid endDefaultURL(org.apache.cactus.WebResponse theResponse)
183 {
184 System.out.println("text length = " + theResponse.getText().length());
185// System.out.println("text length = " + theResponse.getText());186 }
187188/***189 * Test: GroupURL190 * With the default URL "/group/apache"191 * 1) A page is generated 192 * 2) The user is anonymous193 * 3) Group is set to "apache"194 * 4) Role is not set195 */196publicvoid 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 }
203204/***205 * Test the Group link206 * @throws Exception207 */208publicvoid testGroupUrl() throws Exception
209 {
210// Create the RunData object to be used during testing. 211 rundata = RunDataFactory.getRunData ( request, response, config );
212 assertNotNull( "Got rundata", rundata);
213214 TurbineTestUtilities.setupRunData(rundata);
215216// Verify we have a profile217 Profile profile = Profiler.getProfile(rundata);
218 assertNotNull( "Got profile from Profiler", profile);
219220// Verify the profile location information in the profile221if (profile instanceof ProfileLocator)
222 {
223// FIXME: Need to verify 'anonymous' and group name224 ProfileLocator profileLocator = (ProfileLocator) profile;
225// assertTrue("Verify the 'anonymous' is set", profileLocator.getAnonymous());226 assertNotNull("Verify the group is not null", profileLocator.getGroup());
227 assertNull("Verify the role is null", profileLocator.getRole());
228 } else229 {
230 assertTrue( "profile does not implement ProfileLocator", false);
231 }
232 TurbineTestUtilities.generatePage(rundata);
233 TurbineTestUtilities.outputPage(rundata);
234235// Return the used RunData to the factory for recycling.236 RunDataFactory.putRunData(rundata);
237 }
238239publicvoid endGroupURL(WebResponse theResponse)
240 {
241 System.out.println("text length = " + theResponse.getText().length());
242// System.out.println("text length = " + theResponse.getText());243 }
244245/***246 * Test: PageURL247 * With the page URL "/page/apache"248 * 1) A page is generated 249 * 2) The user is anonymous250 * 3) Group is set to "apache"251 * 4) Role is not set252 */253publicvoid 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 }
260261/***262 * Test the PageURL263 *264 * @throws Exception265 */266publicvoid testPageUrl() throws Exception
267 {
268// Create the RunData object to be used during testing. 269 rundata = RunDataFactory.getRunData ( request, response, config );
270 assertNotNull( "Got rundata", rundata);
271272 TurbineTestUtilities.setupRunData(rundata);
273274// Verify we have a profile275 Profile profile = Profiler.getProfile(rundata);
276 assertNotNull( "Got profile from Profiler", profile);
277278// Verify the profile location information in the profile279if (profile instanceof ProfileLocator)
280 {
281 ProfileLocator profileLocator = (ProfileLocator) profile;
282// FIXME: Need to verify 'anonymous' and page name283 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 } else288 {
289 assertTrue( "profile does not implement ProfileLocator", false);
290 }
291 TurbineTestUtilities.generatePage(rundata);
292 TurbineTestUtilities.outputPage(rundata);
293294// Return the used RunData to the factory for recycling.295 RunDataFactory.putRunData(rundata);
296 }
297298publicvoid endPageURL(WebResponse theResponse)
299 {
300 System.out.println("text length = " + theResponse.getText().length());
301// System.out.println("text length = " + theResponse.getText());302 }
303/***304 * Test: PageURL305 * With the page URL "/page/apache"306 * 1) A page is generated 307 * 2) The user is anonymous308 * 3) Group is set to "apache"309 * 4) Role is not set310 */311publicvoid 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 }
318319/***320 * Test the PageURL321 *322 * @throws Exception323 */324publicvoid testUserPageUrl() throws Exception
325 {
326// Create the RunData object to be used during testing. 327 rundata = RunDataFactory.getRunData ( request, response, config );
328 assertNotNull( "Got rundata", rundata);
329330 TurbineTestUtilities.setupRunData(rundata);
331332// Verify we have a profile333 Profile profile = Profiler.getProfile(rundata);
334 assertNotNull( "Got profile from Profiler", profile);
335336// Verify the profile location information in the profile337if (profile instanceof ProfileLocator)
338 {
339 ProfileLocator profileLocator = (ProfileLocator) profile;
340// FIXME: Need to verify 'anonymous' and page name341 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 } else349 {
350 assertTrue( "profile does not implement ProfileLocator", false);
351 }
352 TurbineTestUtilities.generatePage(rundata);
353 TurbineTestUtilities.outputPage(rundata);
354355// Return the used RunData to the factory for recycling.356 RunDataFactory.putRunData(rundata);
357 }
358359publicvoid endUserPageURL(WebResponse theResponse)
360 {
361 System.out.println("text length = " + theResponse.getText().length());
362// System.out.println("text length = " + theResponse.getText());363 }
364 }