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.sql.*;
025: import java.io.*;
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.aikp.*;
032: import com.methodhead.sitecontext.*;
033: import com.methodhead.*;
034: import servletunit.struts.*;
035: import org.apache.struts.action.*;
036: import org.apache.cactus.*;
037:
038: public class SendPasswordActionTest extends CactusStrutsTestCase {
039:
040: User user = null;
041: Role role = null;
042:
043: static {
044: TestUtils.initLogger();
045: }
046:
047: public SendPasswordActionTest(String name) {
048: super (name);
049: }
050:
051: public void setUp() {
052: try {
053: super .setUp();
054:
055: ConnectionSingleton.runBatchUpdate(new FileReader(
056: "webapp/WEB-INF/db/transfer-reset.sql"));
057: } catch (Exception e) {
058: fail(e.getMessage());
059: }
060: }
061:
062: public void tearDown() throws Exception {
063: super .tearDown();
064: }
065:
066: public void testDoSendPasswordForm() {
067: TestData.createUsers();
068:
069: SiteContext.setContext(request, TestData.siteContext1);
070:
071: setRequestPathInfo("/sendPasswordForm");
072: actionPerform();
073:
074: verifyForward("form");
075: }
076:
077: public void testDoSendPassword() {
078: TestData.createUsers();
079:
080: SiteContext.setContext(request, TestData.siteContext1);
081:
082: setRequestPathInfo("/sendPassword");
083: addRequestParameter("email", "test1@methodhead.com");
084: actionPerform();
085:
086: verifyForward("success");
087:
088: //
089: // test policy should send the message to test1@methodhead.com
090: //
091:
092: //
093: // user should still have the same password
094: //
095: user = new User();
096: user.load(new IntKey(1));
097: assertEquals("password", user.getString("password"));
098:
099: //
100: // should have message
101: //
102: verifyActionMessages(new String[] { "reg.sendpassword.passwordSent" });
103: }
104:
105: public void testDoSendPasswordEncrypted() {
106: System.out
107: .println("SendPasswordActionTest.testDoSendPasswordEncrypted(): Can't test encrypted passwords with DefaultTransferPolicy.");
108: /*
109: TestData.createUsers();
110: TestPolicy.setPasswordEncrypted( true );
111:
112: SiteContext.setContext( request, TestData.siteContext1 );
113:
114: setRequestPathInfo( "/sendPassword" );
115: addRequestParameter( "email", "test1@methodhead.com" );
116: actionPerform();
117:
118: verifyForward( "success" );
119:
120: //
121: // test policy should send the message to test1@methodhead.com
122: //
123:
124: //
125: // user should still have a new password
126: //
127: user = new User();
128: user.load( new IntKey( 1 ) );
129: assertTrue( !"password".equals( user.getString( "password" ) ) );
130:
131: //
132: // should have message
133: //
134: verifyActionMessages( new String[] { "reg.sendpassword.passwordSent" } );
135: */
136: }
137: }
|