This project has retired. For details please refer to its
Attic page.
TestJLoginUser 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.modules.actions;
1819import junit.framework.*;
20import org.apache.cactus.*;
2122import org.apache.turbine.modules.ActionLoader;
23import org.apache.turbine.util.RunData;
24import org.apache.turbine.util.RunDataFactory;
2526/***27 * Tests JLoginUser.28 *29 * @author <a href="mailto:johnny.cass@epiuse.com">Johnny Cass</a>30 * @see JLoginUser31 */32publicclassTestJLoginUserextends ServletTestCase
33 {
3435/***36 * Defines the testcase name for JUnit.37 *38 * @param name the testcase's name.39 */40publicTestJLoginUser ( String name )
41 {
42super( name );
43 }
4445/***46 * Start the tests.47 *48 * @param args the arguments. Not used49 */50publicstaticvoid main ( String[] args )
51 {
52 junit.textui.TestRunner.main ( new String[] { TestJLoginUser.class.getName () } );
53 }
5455/***56 * Creates the test suite.57 *58 * @return a test suite (<code>TestSuite</code>) that includes all methods59 * starting with "test"60 */61publicstatic Test suite ()
62 {
63// All methods starting with "test" will be executed in the test suite.64returnnew TestSuite ( TestJLoginUser.class );
65 }
6667/***68 * Sets up the test case.69 *70 */71protectedvoid setUp () throws Exception
72 {
73// Create the RunData object to be used during testing. 74 runData = RunDataFactory.getRunData ( request, response, config );
75 }
7677/***78 * Tests if an invalid user is logged in correctly.79 *80 */81publicvoid testLoginInvalidUser () throws Exception
82 {
83// Shouldn't have a user object available at this stage.84 assertNull ( "User should be 'null' since we have not logged in " +
85"yet - runData.getUser () ", runData.getUser () );
8687// Add parameters to the RunData that will be used to login a non existent user.88 runData.getParameters ().setString ( "username", "" );
89 runData.getParameters ().setString ( "password", "" );
9091// Execute the login action.92 ActionLoader.getInstance ().exec ( runData, "JLoginUser" );
9394// See if we can find a user object.95 assertNotNull ( "User object not found in RunData - runData.getUser () ",
96 runData.getUser () );
9798// Since the user does not exist, the login should have failed.99 assertEquals ( "Logged in - runData.getUser ().hasLoggedIn ()",
100 false, runData.getUser ().hasLoggedIn () );
101 }
102103/***104 * Tests if a valid user is logged in correctly.105 *106 */107publicvoid testLoginValidUser () throws Exception
108 {
109// Shouldn't have a user object available at this stage.110 assertNull ( "User should be 'null' since we have not logged in " +
111"yet - runData.getUser () ", runData.getUser () );
112113// Add parameters to the RunData that will be used to login a valid user.114 runData.getParameters ().setString ( "username", "turbine" );
115 runData.getParameters ().setString ( "password", "turbine" );
116117// Execute the login action.118 ActionLoader.getInstance ().exec ( runData, "JLoginUser" );
119120// See if we can find a user object.121 assertNotNull ( "User object not found in RunData - runData.getUser () ",
122 runData.getUser () );
123124// Since we know the user exists, the login should have been successful/125 assertEquals ( "Not logged in - runData.getUser ().hasLoggedIn ()",
126true, runData.getUser ().hasLoggedIn () );
127 }
128129private RunData runData = null;
130 }