1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.services.security;
18
19
20 import junit.framework.Test;
21 import junit.framework.TestSuite;
22
23 import org.apache.turbine.services.TurbineServices;
24 import org.apache.turbine.util.TurbineConfig;
25 import org.apache.turbine.util.StringUtils;
26
27
28 import org.apache.jetspeed.test.JetspeedTestCase;
29 import org.apache.jetspeed.om.security.JetspeedUser;
30
31 /***
32 * Unit test for PortalAuthentication interface
33 *
34 * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
35 * @version $Id: TestPortalAuthentication.java,v 1.1 2004/04/07 22:02:43 jford Exp $
36 */
37
38 public class TestPortalAuthentication extends JetspeedTestCase {
39
40 /***
41 * Defines the testcase name for JUnit.
42 *
43 * @param name the testcase's name.
44 */
45 public TestPortalAuthentication( String name ) {
46 super( name );
47 }
48
49 /***
50 * Start the tests.
51 *
52 * @param args the arguments. Not used
53 */
54 public static void main(String args[])
55 {
56 junit.awtui.TestRunner.main( new String[] { TestPortalAuthentication.class.getName() } );
57 }
58
59 public void setup()
60 {
61 System.out.println("Setup: Testing Turbine Authentication");
62 }
63
64 /***
65 * Creates the test suite.
66 *
67 * @return a test suite (<code>TestSuite</code>) that includes all methods
68 * starting with "test"
69 */
70 public static Test suite()
71 {
72
73 return new TestSuite( TestPortalAuthentication.class );
74 }
75
76
77 /***
78 * Tests PortalAuthentication.login()
79 *
80 * @throws Exception
81 */
82
83 public void testLogin() throws Exception
84 {
85 setup();
86
87 PortalAuthentication service = getService();
88 JetspeedUser user = null;
89
90 try
91 {
92 user = service.login("baduser", "badpassword");
93 }
94 catch (Exception e)
95 {
96 System.out.println("exception = " + e.toString());
97 assertTrue(e instanceof FailedLoginException);
98 }
99 try
100 {
101 user = service.login("turbine", "badpassword");
102 }
103 catch (Exception e)
104 {
105 System.out.println("e = " + e);
106 assertTrue(e instanceof FailedLoginException);
107 }
108 try
109 {
110 user = service.login("turbine", "turbine");
111 }
112 catch (Exception e)
113 {
114 fail(StringUtils.stackTrace(e));
115 }
116
117 assertTrue(user.hasLoggedIn() == true);
118
119 System.out.println("Completed Login Test OK ");
120
121 }
122
123 /***
124 * Tests PortalAuthentication.login()
125 *
126 * @throws Exception
127 */
128
129 public void testGetAnonymousUser()
130 {
131 setup();
132
133 PortalAuthentication service = getService();
134 JetspeedUser user = null;
135
136 try
137 {
138 user = service.getAnonymousUser();
139 }
140 catch (Exception e)
141 {
142 fail(StringUtils.stackTrace(e));
143 }
144
145 assertTrue(user.hasLoggedIn() == false);
146
147 System.out.println("Completed Anonymous Test OK");
148
149 }
150
151
152
153
154
155
156 private static TurbineConfig config = null;
157
158 /***
159 Sets up TurbineConfig using the system property:
160 <pre>turbine.properties</pre>
161 */
162 static
163 {
164 try
165 {
166 config = new TurbineConfig( "webapp", "/WEB-INF/conf/TurbineResources.properties");
167 config.init();
168 }
169 catch (Exception e)
170 {
171 fail(StringUtils.stackTrace(e));
172 }
173 }
174
175 private static PortalAuthentication getService()
176 {
177 return (PortalAuthentication)TurbineServices
178 .getInstance()
179 .getService(PortalAuthentication.SERVICE_NAME);
180 }
181
182 }
183
184
185