001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.reg;
022:
023: import java.util.*;
024: import java.io.*;
025: import java.sql.*;
026: import junit.framework.*;
027: import org.apache.log4j.*;
028: import com.methodhead.persistable.*;
029: import com.methodhead.test.*;
030: import com.methodhead.auth.*;
031: import com.methodhead.sitecontext.*;
032: import com.methodhead.aikp.*;
033: import com.methodhead.*;
034: import servletunit.struts.*;
035: import org.apache.struts.action.*;
036: import org.apache.cactus.*;
037:
038: public class ProfileActionTest extends CactusStrutsTestCase {
039:
040: DynaActionForm form = null;
041: List list = null;
042: String[] strings = null;
043: User user = null;
044: Contact contact = null;
045:
046: static {
047: TestUtils.initLogger();
048: TestUtils.initDb();
049: }
050:
051: public ProfileActionTest(String name) {
052: super (name);
053: }
054:
055: public void setUp() {
056: try {
057: super .setUp();
058: ConnectionSingleton.runBatchUpdate(new FileReader(
059: "webapp/WEB-INF/db/transfer-reset.sql"));
060:
061: AuthUtil.setUser(request, new TestUser());
062: } catch (Exception e) {
063: fail(e.getMessage());
064: }
065: }
066:
067: public void tearDown() throws Exception {
068: super .tearDown();
069: }
070:
071: public void testDoProfileForm() {
072: try {
073: TestData.createUsers();
074: AuthUtil.setUser(request, TestData.user1);
075:
076: setRequestPathInfo("/profileForm");
077: actionPerform();
078:
079: verifyForward("form");
080:
081: form = (DynaActionForm) getActionForm();
082: assertEquals("test1@methodhead.com", form.get("email"));
083: } catch (Exception e) {
084: e.printStackTrace();
085: fail();
086: }
087: }
088:
089: public void testDoProfileCancel() {
090: try {
091: TestData.createUsers();
092: AuthUtil.setUser(request, TestData.user1);
093:
094: setRequestPathInfo("/profile");
095: addRequestParameter("email", "user1updated@user1.com");
096: addRequestParameter("cancel", "Cancel");
097: actionPerform();
098:
099: verifyForward("cancelled");
100: } catch (Exception e) {
101: e.printStackTrace();
102: fail();
103: }
104: }
105:
106: public void testDoProfile() {
107: try {
108: TestData.createUsers();
109: AuthUtil.setUser(request, TestData.user1);
110:
111: setRequestPathInfo("/profile");
112: addRequestParameter("email", "user1updated@user1.com");
113: actionPerform();
114:
115: verifyInputForward();
116:
117: verifyActionMessages(new String[] { "reg.profile.profileupdated" });
118:
119: user = (User) AuthUtil.getUser(request);
120: assertEquals("user1updated@user1.com", user.getContact()
121: .getString("email"));
122:
123: user = new User();
124: user.load(new IntKey(TestData.user1.getInt("id")));
125: assertEquals("user1updated@user1.com", user.getContact()
126: .getString("email"));
127: } catch (Exception e) {
128: e.printStackTrace();
129: fail();
130: }
131: }
132:
133: public void testDoPasswordForm() {
134: try {
135: TestData.createUsers();
136: AuthUtil.setUser(request, TestData.user1);
137:
138: setRequestPathInfo("/passwordForm");
139: actionPerform();
140:
141: verifyForward("form");
142:
143: form = (DynaActionForm) getActionForm();
144: assertEquals("", form.get("oldpassword"));
145: assertEquals("", form.get("password"));
146: assertEquals("", form.get("verifypassword"));
147: } catch (Exception e) {
148: e.printStackTrace();
149: fail();
150: }
151: }
152:
153: public void testDoPasswordCancel() {
154: try {
155: TestData.createUsers();
156: AuthUtil.setUser(request, TestData.user1);
157:
158: setRequestPathInfo("/password");
159: addRequestParameter("oldpassword", "");
160: addRequestParameter("password", "");
161: addRequestParameter("verifypassword", "");
162: addRequestParameter("cancel", "Cancel");
163: actionPerform();
164:
165: verifyForward("cancelled");
166: } catch (Exception e) {
167: e.printStackTrace();
168: fail();
169: }
170: }
171:
172: public void testDoPassword() {
173: try {
174: TestData.createUsers();
175: AuthUtil.setUser(request, TestData.user1);
176:
177: setRequestPathInfo("/password");
178: addRequestParameter("oldpassword", "password");
179: addRequestParameter("password", "newpassword");
180: addRequestParameter("verifypassword", "newpassword");
181: actionPerform();
182:
183: verifyForward("success");
184:
185: verifyActionMessages(new String[] { "reg.profile.passwordupdated" });
186:
187: user = (User) AuthUtil.getUser(request);
188: assertEquals("newpassword", user.getString("password"));
189:
190: user = new User();
191: user.load(new IntKey(TestData.user1.getInt("id")));
192: assertEquals("newpassword", user.getString("password"));
193: } catch (Exception e) {
194: e.printStackTrace();
195: fail();
196: }
197: }
198: }
|