KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > reg > ProfileActionTest


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.reg;
22
23 import java.util.*;
24 import java.io.*;
25 import java.sql.*;
26 import junit.framework.*;
27 import org.apache.log4j.*;
28 import com.methodhead.persistable.*;
29 import com.methodhead.test.*;
30 import com.methodhead.auth.*;
31 import com.methodhead.sitecontext.*;
32 import com.methodhead.aikp.*;
33 import com.methodhead.*;
34 import servletunit.struts.*;
35 import org.apache.struts.action.*;
36 import org.apache.cactus.*;
37
38 public class ProfileActionTest extends CactusStrutsTestCase {
39
40   DynaActionForm form = null;
41   List list = null;
42   String JavaDoc[] strings = null;
43   User user = null;
44   Contact contact = null;
45
46   static {
47     TestUtils.initLogger();
48     TestUtils.initDb();
49   }
50
51   public ProfileActionTest( String JavaDoc name ) {
52     super( name );
53   }
54
55   public void setUp() {
56     try {
57       super.setUp();
58       ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) );
59
60       AuthUtil.setUser( request, new TestUser() );
61     }
62     catch ( Exception JavaDoc e ) {
63       fail( e.getMessage() );
64     }
65   }
66
67   public void tearDown()
68   throws
69     Exception JavaDoc {
70     super.tearDown();
71   }
72
73   public void testDoProfileForm() {
74     try {
75       TestData.createUsers();
76       AuthUtil.setUser( request, TestData.user1 );
77
78       setRequestPathInfo( "/profileForm" );
79       actionPerform();
80
81       verifyForward( "form" );
82
83       form = ( DynaActionForm )getActionForm();
84       assertEquals( "test1@methodhead.com", form.get( "email" ) );
85     }
86     catch ( Exception JavaDoc e ) {
87       e.printStackTrace();
88       fail();
89     }
90   }
91
92   public void testDoProfileCancel() {
93     try {
94       TestData.createUsers();
95       AuthUtil.setUser( request, TestData.user1 );
96
97       setRequestPathInfo( "/profile" );
98       addRequestParameter( "email", "user1updated@user1.com" );
99       addRequestParameter( "cancel", "Cancel" );
100       actionPerform();
101
102       verifyForward( "cancelled" );
103     }
104     catch ( Exception JavaDoc e ) {
105       e.printStackTrace();
106       fail();
107     }
108   }
109
110   public void testDoProfile() {
111     try {
112       TestData.createUsers();
113       AuthUtil.setUser( request, TestData.user1 );
114
115       setRequestPathInfo( "/profile" );
116       addRequestParameter( "email", "user1updated@user1.com" );
117       actionPerform();
118
119       verifyInputForward();
120
121       verifyActionMessages( new String JavaDoc[] { "reg.profile.profileupdated" } );
122
123       user = ( User )AuthUtil.getUser( request );
124       assertEquals( "user1updated@user1.com", user.getContact().getString( "email" ) );
125
126       user = new User();
127       user.load( new IntKey( TestData.user1.getInt( "id" ) ) );
128       assertEquals( "user1updated@user1.com", user.getContact().getString( "email" ) );
129     }
130     catch ( Exception JavaDoc e ) {
131       e.printStackTrace();
132       fail();
133     }
134   }
135
136   public void testDoPasswordForm() {
137     try {
138       TestData.createUsers();
139       AuthUtil.setUser( request, TestData.user1 );
140
141       setRequestPathInfo( "/passwordForm" );
142       actionPerform();
143
144       verifyForward( "form" );
145
146       form = ( DynaActionForm )getActionForm();
147       assertEquals( "", form.get( "oldpassword" ) );
148       assertEquals( "", form.get( "password" ) );
149       assertEquals( "", form.get( "verifypassword" ) );
150     }
151     catch ( Exception JavaDoc e ) {
152       e.printStackTrace();
153       fail();
154     }
155   }
156
157   public void testDoPasswordCancel() {
158     try {
159       TestData.createUsers();
160       AuthUtil.setUser( request, TestData.user1 );
161
162       setRequestPathInfo( "/password" );
163       addRequestParameter( "oldpassword", "" );
164       addRequestParameter( "password", "" );
165       addRequestParameter( "verifypassword", "" );
166       addRequestParameter( "cancel", "Cancel" );
167       actionPerform();
168
169       verifyForward( "cancelled" );
170     }
171     catch ( Exception JavaDoc e ) {
172       e.printStackTrace();
173       fail();
174     }
175   }
176
177   public void testDoPassword() {
178     try {
179       TestData.createUsers();
180       AuthUtil.setUser( request, TestData.user1 );
181
182       setRequestPathInfo( "/password" );
183       addRequestParameter( "oldpassword", "password" );
184       addRequestParameter( "password", "newpassword" );
185       addRequestParameter( "verifypassword", "newpassword" );
186       actionPerform();
187
188       verifyForward( "success" );
189
190       verifyActionMessages( new String JavaDoc[] { "reg.profile.passwordupdated" } );
191
192       user = ( User )AuthUtil.getUser( request );
193       assertEquals( "newpassword", user.getString( "password" ) );
194
195       user = new User();
196       user.load( new IntKey( TestData.user1.getInt( "id" ) ) );
197       assertEquals( "newpassword", user.getString( "password" ) );
198     }
199     catch ( Exception JavaDoc e ) {
200       e.printStackTrace();
201       fail();
202     }
203   }
204 }
205
Popular Tags