1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.modules.actions;
18
19 import junit.framework.*;
20 import org.apache.cactus.*;
21
22 import org.apache.turbine.modules.ActionLoader;
23 import org.apache.turbine.util.RunData;
24 import org.apache.turbine.util.RunDataFactory;
25
26 /***
27 * Tests JLoginUser.
28 *
29 * @author <a href="mailto:johnny.cass@epiuse.com">Johnny Cass</a>
30 * @see JLoginUser
31 */
32 public class TestJLoginUser extends ServletTestCase
33 {
34
35 /***
36 * Defines the testcase name for JUnit.
37 *
38 * @param name the testcase's name.
39 */
40 public TestJLoginUser ( String name )
41 {
42 super( name );
43 }
44
45 /***
46 * Start the tests.
47 *
48 * @param args the arguments. Not used
49 */
50 public static void main ( String[] args )
51 {
52 junit.textui.TestRunner.main ( new String[] { TestJLoginUser.class.getName () } );
53 }
54
55 /***
56 * Creates the test suite.
57 *
58 * @return a test suite (<code>TestSuite</code>) that includes all methods
59 * starting with "test"
60 */
61 public static Test suite ()
62 {
63
64 return new TestSuite ( TestJLoginUser.class );
65 }
66
67 /***
68 * Sets up the test case.
69 *
70 */
71 protected void setUp () throws Exception
72 {
73
74 runData = RunDataFactory.getRunData ( request, response, config );
75 }
76
77 /***
78 * Tests if an invalid user is logged in correctly.
79 *
80 */
81 public void testLoginInvalidUser () throws Exception
82 {
83
84 assertNull ( "User should be 'null' since we have not logged in " +
85 "yet - runData.getUser () ", runData.getUser () );
86
87
88 runData.getParameters ().setString ( "username", "" );
89 runData.getParameters ().setString ( "password", "" );
90
91
92 ActionLoader.getInstance ().exec ( runData, "JLoginUser" );
93
94
95 assertNotNull ( "User object not found in RunData - runData.getUser () ",
96 runData.getUser () );
97
98
99 assertEquals ( "Logged in - runData.getUser ().hasLoggedIn ()",
100 false, runData.getUser ().hasLoggedIn () );
101 }
102
103 /***
104 * Tests if a valid user is logged in correctly.
105 *
106 */
107 public void testLoginValidUser () throws Exception
108 {
109
110 assertNull ( "User should be 'null' since we have not logged in " +
111 "yet - runData.getUser () ", runData.getUser () );
112
113
114 runData.getParameters ().setString ( "username", "turbine" );
115 runData.getParameters ().setString ( "password", "turbine" );
116
117
118 ActionLoader.getInstance ().exec ( runData, "JLoginUser" );
119
120
121 assertNotNull ( "User object not found in RunData - runData.getUser () ",
122 runData.getUser () );
123
124
125 assertEquals ( "Not logged in - runData.getUser ().hasLoggedIn ()",
126 true, runData.getUser ().hasLoggedIn () );
127 }
128
129 private RunData runData = null;
130 }